fix: feed + formatting

This commit is contained in:
Cory Dransfeldt 2024-06-01 08:47:33 -07:00
parent 34d2020173
commit 09614b0589
No known key found for this signature in database
22 changed files with 30 additions and 52 deletions

View file

@ -1,7 +1,9 @@
import { DateTime } from 'luxon' import { DateTime } from 'luxon'
import { URL } from 'url' import { URL } from 'url'
import slugify from 'slugify' import slugify from 'slugify'
import markdownIt from 'markdown-it'
import sanitizeHtml from 'sanitize-html'; import sanitizeHtml from 'sanitize-html';
import { shuffleArray, sanitizeMediaString } from '../utilities/index.js' import { shuffleArray, sanitizeMediaString } from '../utilities/index.js'
const BASE_URL = 'https://coryd.dev' const BASE_URL = 'https://coryd.dev'
@ -94,7 +96,7 @@ export default {
try { try {
return (new URL(url, BASE_URL)).toString() return (new URL(url, BASE_URL)).toString()
} catch(e) { } catch(e) {
console.log('Error generating absoluteUrl.') console.error('Error generating absoluteUrl.')
} }
return url; return url;
}, },
@ -105,6 +107,7 @@ export default {
entries.forEach((entry) => { entries.forEach((entry) => {
const dateKey = Object.keys(entry).find((key) => key.includes('date')) const dateKey = Object.keys(entry).find((key) => key.includes('date'))
const date = new Date(entry[dateKey]) const date = new Date(entry[dateKey])
const md = markdownIt({ html: true, linkify: true })
let excerpt = '' let excerpt = ''
let url = '' let url = ''
const feedNote = '<hr/><p>This is a full text feed, but not all content can be rendered perfectly within the feed. If something looks off, feel free to <a href="https://coryd.dev">visit my site</a> for the original post.</p>' const feedNote = '<hr/><p>This is a full text feed, but not all content can be rendered perfectly within the feed. If something looks off, feel free to <a href="https://coryd.dev">visit my site</a> for the original post.</p>'
@ -116,20 +119,20 @@ export default {
// set the entry excerpt // set the entry excerpt
if (entry.description) excerpt = entry.description // general case if (entry.description) excerpt = entry.description // general case
if (entry?.data?.description) excerpt = `${entry?.data?.description}<br/><br/>` // links where description is stored in frontmatter
if (entry.type === 'book' || entry.type === 'movie') excerpt = `${entry.description}<br/><br/>` // books if (entry.type === 'book' || entry.type === 'movie') excerpt = `${entry.description}<br/><br/>` // books
// send full post content to rss // send full post content to rss
if (entry.content) excerpt = sanitizeHtml(`${entry.content}${feedNote}`, { if (entry?.url?.includes('/posts/') && entry.content) excerpt = sanitizeHtml(`${md.render(entry.content)}${feedNote}`, {
disallowedTagsMode: 'completelyDiscard' disallowedTagsMode: 'completelyDiscard'
}) })
// if there's a valid entry return a normalized object // if there's a valid entry return a normalized object
if (entry) if (entry)
posts.push({ posts.push({
title: entry.data?.title || entry.title, title: entry.title,
url, url,
content: entry?.description || entry?.data?.description, content: entry.description,
date, date,
excerpt, excerpt,
rating: entry?.rating || '' rating: entry?.rating || ''

View file

@ -1,4 +1,4 @@
{%- assign shareLink = postUrl | findPost: linkPosts -%} {%- assign shareLink = postUrl | findPost:linkPosts -%}
{%- if shareLink %} {%- if shareLink %}
<script type="module" src="/assets/scripts/components/mastodon-post.js"></script> <script type="module" src="/assets/scripts/components/mastodon-post.js"></script>
<template id="mastodon-post-template"> <template id="mastodon-post-template">

View file

@ -1,25 +0,0 @@
---
layout: main
schema: blog
---
{% render "partials/header.liquid", meta: meta, page: page, nav: nav %}
{%- capture postUrl %}{{ meta.url }}{{ page.url }}{% endcapture -%}
<div class="default-wrapper">
<article class="h-entry">
<div class="flex-centered gap-xs icon-small icon-light">
{% tablericon "calendar-month" "Date" %}
<time class="dt-published" datetime="{{ date }}">
{{ date | date: "%B %e, %Y" }}
</time>
</div>
<h2 class="p-name">{{ title }}</h2>
<span class="p-author h-card hidden">{{ meta.author }}</span>
<div class="p-summary hidden">{{ post.description }}</div>
<div class="e-content">
{% render "partials/banners/old-post.liquid", date:post.date %}
{{ content }}
</div>
</article>
</div>
{% render "partials/widgets/mastodon-post.liquid", postUrl:postUrl, linkPosts:linkPosts %}
{% render "partials/widgets/addon-links.liquid", posts:posts, analytics:analytics, links:collections.links %}

View file

@ -1,7 +1,7 @@
--- ---
layout: null layout: null
eleventyExcludeFromCollections: true eleventyExcludeFromCollections: true
permalink: /feeds/all.json permalink: "/feeds/all.json"
--- ---
{% render "partials/feeds/json.liquid" {% render "partials/feeds/json.liquid"
permalink:'/feeds/all.json' permalink:'/feeds/all.json'

View file

@ -1,7 +1,7 @@
--- ---
layout: null layout: null
eleventyExcludeFromCollections: true eleventyExcludeFromCollections: true
permalink: /feeds/all permalink: "/feeds/all"
--- ---
{% render "partials/feeds/rss.liquid" {% render "partials/feeds/rss.liquid"
permalink:"/feeds/all" permalink:"/feeds/all"

View file

@ -1,7 +1,7 @@
--- ---
layout: null layout: null
eleventyExcludeFromCollections: true eleventyExcludeFromCollections: true
permalink: /feeds/books permalink: "/feeds/books"
--- ---
{%- assign bookData = books | bookStatus: 'finished' | bookSortDescending -%} {%- assign bookData = books | bookStatus: 'finished' | bookSortDescending -%}
{% render "partials/feeds/rss.liquid" {% render "partials/feeds/rss.liquid"

View file

@ -1,7 +1,7 @@
--- ---
layout: null layout: null
eleventyExcludeFromCollections: true eleventyExcludeFromCollections: true
permalink: /feeds/posts permalink: "/feeds/posts"
--- ---
{% render "partials/feeds/rss.liquid" {% render "partials/feeds/rss.liquid"
permalink:"/feeds/posts" permalink:"/feeds/posts"

View file

@ -1,7 +1,7 @@
--- ---
layout: null layout: null
eleventyExcludeFromCollections: true eleventyExcludeFromCollections: true
permalink: /feeds/links permalink: "/feeds/links"
--- ---
{% render "partials/feeds/rss.liquid" {% render "partials/feeds/rss.liquid"
permalink:"/feeds/links" permalink:"/feeds/links"

View file

@ -1,7 +1,7 @@
--- ---
layout: null layout: null
eleventyExcludeFromCollections: true eleventyExcludeFromCollections: true
permalink: /feeds/movies permalink: "/feeds/movies"
--- ---
{% render "partials/feeds/rss.liquid" {% render "partials/feeds/rss.liquid"
permalink:"/feeds/movies" permalink:"/feeds/movies"

View file

@ -1,5 +1,5 @@
--- ---
permalink: '/ai.txt' permalink: "/ai.txt"
eleventyExcludeFromCollections: true eleventyExcludeFromCollections: true
dynamicPermalink: false dynamicPermalink: false
--- ---

View file

@ -1,5 +1,5 @@
--- ---
permalink: '/contribute.json' permalink: "/contribute.json"
eleventyExcludeFromCollections: true eleventyExcludeFromCollections: true
dynamicPermalink: false dynamicPermalink: false
--- ---

View file

@ -1,5 +1,5 @@
--- ---
permalink: '.meta/gpc.json' permalink: ".meta/gpc.json"
eleventyExcludeFromCollections: true eleventyExcludeFromCollections: true
dynamicPermalink: false dynamicPermalink: false
--- ---

View file

@ -1,5 +1,5 @@
--- ---
permalink: '/humans.txt' permalink: "/humans.txt"
eleventyExcludeFromCollections: true eleventyExcludeFromCollections: true
dynamicPermalink: false dynamicPermalink: false
--- ---

View file

@ -1,5 +1,5 @@
--- ---
permalink: /blogroll.opml permalink: "/blogroll.opml"
layout: null layout: null
eleventyExcludeFromCollections: true eleventyExcludeFromCollections: true
--- ---

View file

@ -1,5 +1,5 @@
--- ---
permalink: '/robots.txt' permalink: "/robots.txt"
eleventyExcludeFromCollections: true eleventyExcludeFromCollections: true
dynamicPermalink: false dynamicPermalink: false
--- ---

View file

@ -1,5 +1,5 @@
--- ---
permalink: '.well-known/security.txt' permalink: ".well-known/security.txt"
eleventyExcludeFromCollections: true eleventyExcludeFromCollections: true
dynamicPermalink: false dynamicPermalink: false
--- ---

View file

@ -1,5 +1,5 @@
--- ---
permalink: /sitemap.xml permalink: "/sitemap.xml"
eleventyExcludeFromCollections: true eleventyExcludeFromCollections: true
--- ---
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>

View file

@ -1,5 +1,5 @@
--- ---
permalink: '.well-known/traffic-advice' permalink: ".well-known/traffic-advice"
eleventyExcludeFromCollections: true eleventyExcludeFromCollections: true
dynamicPermalink: false dynamicPermalink: false
--- ---

View file

@ -1,5 +1,5 @@
--- ---
permalink: '.well-known/webfinger' permalink: ".well-known/webfinger"
eleventyExcludeFromCollections: true eleventyExcludeFromCollections: true
dynamicPermalink: false dynamicPermalink: false
--- ---

View file

@ -4,7 +4,7 @@ pagination:
data: books data: books
size: 1 size: 1
alias: book alias: book
permalink: /books/{{ book.isbn }}/index.html permalink: "/books/{{ book.isbn }}/index.html"
isbn: {{ book.isbn }} isbn: {{ book.isbn }}
schema: book schema: book
--- ---

View file

@ -4,7 +4,7 @@ pagination:
data: artists data: artists
size: 1 size: 1
alias: artist alias: artist
permalink: /music/artists/{{ artist.name_string | slugify | downcase }}-{{ artist.country | slugify | downcase}}/index.html permalink: "/music/artists/{{ artist.name_string | slugify | downcase }}-{{ artist.country | slugify | downcase}}/index.html"
updated: "now" updated: "now"
schema: artist schema: artist
--- ---

View file

@ -4,7 +4,7 @@ pagination:
data: genres data: genres
size: 1 size: 1
alias: genre alias: genre
permalink: /music/genres/{{ genre.name | slugify | downcase }}/index.html permalink: "/music/genres/{{ genre.name | slugify | downcase }}/index.html"
updated: "now" updated: "now"
schema: genre schema: genre
--- ---