chore: cleanup

This commit is contained in:
Cory Dransfeldt 2024-09-23 14:10:12 -07:00
parent 3f48399c09
commit 4696b0c383
No known key found for this signature in database
6 changed files with 72 additions and 75 deletions

View file

@ -32,11 +32,23 @@ export const processContent = (collection) => {
const parseDate = (date) => { const parseDate = (date) => {
if (!date) return null if (!date) return null
let parsedDate = DateTime.fromISO(date)
if (!parsedDate.isValid) parsedDate = DateTime.fromFormat(date, 'yyyy-MM-dd') const formats = [
if (!parsedDate.isValid) parsedDate = DateTime.fromFormat(date, 'MM/dd/yyyy') { method: 'fromISO' },
if (!parsedDate.isValid) parsedDate = DateTime.fromFormat(date, 'dd-MM-yyyy') { method: 'fromFormat', format: 'yyyy-MM-dd' },
return parsedDate.isValid ? parsedDate : null { method: 'fromFormat', format: 'MM/dd/yyyy' },
{ method: 'fromFormat', format: 'dd-MM-yyyy' },
]
for (const { method, format } of formats) {
const parsedDate = format
? DateTime[method](date, format)
: DateTime[method](date)
if (parsedDate.isValid) return parsedDate
}
return null
} }
const addSiteMapContent = (items, getTitle, getDate) => { const addSiteMapContent = (items, getTitle, getDate) => {

View file

@ -12,79 +12,67 @@ export default {
const posts = [] const posts = []
const mdGenerator = () => { const mdGenerator = () => {
const md = markdownIt({ html: true, linkify: true }) const md = markdownIt({ html: true, linkify: true })
md.use(markdownItAnchor, { md.use(markdownItAnchor, {
level: [1, 2], level: [1, 2],
permalink: markdownItAnchor.permalink.headerLink({ permalink: markdownItAnchor.permalink.headerLink({ safariReaderFix: true })
safariReaderFix: true
})
}) })
md.use(markdownItFootnote) md.use(markdownItFootnote)
md.renderer.rules.footnote_ref = (tokens, idx) => { md.renderer.rules.footnote_ref = (tokens, idx) => `<sup>${tokens[idx].meta.id + 1}</sup>`
const id = tokens[idx].meta.id + 1 md.renderer.rules.footnote_block_open = () => '<hr class="footnotes-sep">\n<section class="footnotes">\n<ol class="footnotes-list">\n'
return `<sup>${id}</sup>` md.renderer.rules.footnote_open = (tokens, idx) => `<li id="fn${tokens[idx].meta.id + 1}" class="footnote-item"> `
}
md.renderer.rules.footnote_block_open = () => (
'<hr class="footnotes-sep">\n<section class="footnotes">\n<ol class="footnotes-list">\n'
)
md.renderer.rules.footnote_open = (tokens, idx) => {
const id = tokens[idx].meta.id + 1
return `<li id="fn${id}" class="footnote-item"> `
}
md.renderer.rules.footnote_anchor = () => '' md.renderer.rules.footnote_anchor = () => ''
return md return md
} }
const entryData = limit ? entries.slice(0, limit) : entries
const entryData = limit ? entries.slice(0, limit) : entries
entryData.forEach((entry) => { entryData.forEach((entry) => {
const md = mdGenerator() const md = mdGenerator()
const dateKey = Object.keys(entry).find(key => key.includes('date')) const dateKey = Object.keys(entry).find(key => key.includes('date'))
let { artist, authors, backdrop, content, description, image, link, rating, review, slug, title, url, tags, type } = entry const {
artist, authors, backdrop, content, description, image, link, rating, review,
slug, title, url, tags, type
} = entry
const processedEntry = {
title: title.trim(),
date: new Date(entry[dateKey]),
content: description || ''
}
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>'
const processedEntry = { title: title.trim(), date: new Date(entry[dateKey]), content: description }
if (url?.includes('http')) processedEntry['url'] = url processedEntry.url = (url?.includes('http')) ? url : new URL(slug || url, BASE_URL).toString()
if (!url?.includes('http')) processedEntry['url'] = new URL(url, BASE_URL).toString()
if (slug) processedEntry['url'] = new URL(slug, BASE_URL).toString()
if (link) { if (link) {
processedEntry['title'] = `${title} via ${authors['name']}` processedEntry.title = `${title} via ${authors?.name || 'Unknown'}`
processedEntry['url'] = link, processedEntry.url = link
processedEntry['author'] = { processedEntry.author = {
name: authors['name'], name: authors?.name || 'Unknown',
url: authors['url'], url: authors?.url || '',
mastodon: authors?.['mastodon'] || '', mastodon: authors?.mastodon || '',
rss: authors?.['rss_feed'] || '' rss: authors?.rss_feed || ''
}, }
processedEntry['excerpt'] = sanitizeHtml(`${md.render(description)}`) processedEntry.excerpt = sanitizeHtml(md.render(description || ''))
}
if (description) processedEntry['excerpt'] = description
if (['book', 'movie'].includes(type) && review) {
processedEntry['excerpt'] = sanitizeHtml(`${md.render(review)}`)
} else if (['book', 'movie'].includes(type)) { } else if (['book', 'movie'].includes(type)) {
processedEntry['excerpt'] = sanitizeHtml(`${md.render(description)}`) processedEntry.excerpt = sanitizeHtml(md.render(review || description || ''))
} else if (type === 'album-release') {
let sanitizedDescription = sanitizeHtml(md.render(description || ''))
let truncatedDescription = truncate(sanitizedDescription, { length: 500, reserveLastWord: true, ellipsis: '...' })
if (sanitizedDescription.length > 500) truncatedDescription += ` <a href="${artist?.url}">Read more about ${artist?.name}</a>`
processedEntry.excerpt = truncatedDescription
} else if (slug && content) {
processedEntry.excerpt = sanitizeHtml(md.render(content) + feedNote, { disallowedTagsMode: 'completelyDiscard' })
} else if (description) {
processedEntry.excerpt = description
} }
if (type === 'album-release') {
let sanitizedDescription = sanitizeHtml(`${md.render(description)}`)
let truncatedDescription = truncate(sanitizedDescription, {
length: 500,
reserveLastWord: true,
ellipsis: '...'
})
if (sanitizedDescription.length > 500) truncatedDescription += ` <a href="${entry['artist']['url']}">Read more about ${entry['artist']['name']}</a>`
processedEntry['excerpt'] = truncatedDescription
}
if (slug && content) processedEntry['excerpt'] = sanitizeHtml(`${md.render(content)}${feedNote}`, {
disallowedTagsMode: 'completelyDiscard'
})
processedEntry['image'] = backdrop || image processedEntry.image = backdrop || image
if (rating) processedEntry['rating'] = rating if (rating) processedEntry.rating = rating
if (tags) processedEntry['tags'] = tags if (tags) processedEntry.tags = tags
if (type === 'album-release' && artist) processedEntry['title'] = `${title} by ${artist}` if (type === 'album-release' && artist) processedEntry.title = `${title} by ${artist}`
if (entry) posts.push(processedEntry) posts.push(processedEntry)
}) })
return posts return posts

25
package-lock.json generated
View file

@ -1,12 +1,12 @@
{ {
"name": "coryd.dev", "name": "coryd.dev",
"version": "24.19.5", "version": "24.19.7",
"lockfileVersion": 3, "lockfileVersion": 3,
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"name": "coryd.dev", "name": "coryd.dev",
"version": "24.19.5", "version": "24.19.7",
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"@cdransf/api-text": "^1.5.0", "@cdransf/api-text": "^1.5.0",
@ -701,9 +701,9 @@
"peer": true "peer": true
}, },
"node_modules/@types/node": { "node_modules/@types/node": {
"version": "22.5.5", "version": "22.6.1",
"resolved": "https://registry.npmjs.org/@types/node/-/node-22.5.5.tgz", "resolved": "https://registry.npmjs.org/@types/node/-/node-22.6.1.tgz",
"integrity": "sha512-Xjs4y5UPO/CLdzpgR6GirZJx36yScjh73+2NlLlkFRSoQN8B0DpfXPdZGnvVmLRLOsqDpOfTNv7D9trgGhmOIA==", "integrity": "sha512-V48tCfcKb/e6cVUigLAaJDAILdMP0fUW6BidkPK4GpGjXcfbnoHasCZDwz3N3yVt5we2RHm4XTQCpv0KJz9zqw==",
"dev": true, "dev": true,
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
@ -1083,9 +1083,9 @@
} }
}, },
"node_modules/caniuse-lite": { "node_modules/caniuse-lite": {
"version": "1.0.30001662", "version": "1.0.30001663",
"resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001662.tgz", "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001663.tgz",
"integrity": "sha512-sgMUVwLmGseH8ZIrm1d51UbrhqMCH3jvS7gF/M6byuHOnKyLOBL7W8yz5V02OHwgLGA36o/AFhWzzh4uc5aqTA==", "integrity": "sha512-o9C3X27GLKbLeTYZ6HBOLU1tsAcBZsLis28wrVzddShCS16RujjHp9GDHKZqrB3meE0YjhawvMFsGb/igqiPzA==",
"dev": true, "dev": true,
"funding": [ "funding": [
{ {
@ -2651,9 +2651,9 @@
} }
}, },
"node_modules/jackspeak": { "node_modules/jackspeak": {
"version": "4.0.1", "version": "4.0.2",
"resolved": "https://registry.npmjs.org/jackspeak/-/jackspeak-4.0.1.tgz", "resolved": "https://registry.npmjs.org/jackspeak/-/jackspeak-4.0.2.tgz",
"integrity": "sha512-cub8rahkh0Q/bw1+GxP7aeSe29hHHn2V4m29nnDlvCdlgU+3UGxkZp7Z53jLUdpX3jdTO0nJZUDl3xvbWc2Xog==", "integrity": "sha512-bZsjR/iRjl1Nk1UkjGpAzLNfQtzuijhn2g+pbZb98HQ1Gk8vM9hfbxeMBP+M2/UUdwj0RqGG3mlvk2MsAqwvEw==",
"dev": true, "dev": true,
"license": "BlueOak-1.0.0", "license": "BlueOak-1.0.0",
"dependencies": { "dependencies": {
@ -2664,9 +2664,6 @@
}, },
"funding": { "funding": {
"url": "https://github.com/sponsors/isaacs" "url": "https://github.com/sponsors/isaacs"
},
"optionalDependencies": {
"@pkgjs/parseargs": "^0.11.0"
} }
}, },
"node_modules/js-yaml": { "node_modules/js-yaml": {

View file

@ -1,6 +1,6 @@
{ {
"name": "coryd.dev", "name": "coryd.dev",
"version": "24.19.5", "version": "24.19.7",
"description": "The source for my personal site. Built using 11ty (and other tools).", "description": "The source for my personal site. Built using 11ty (and other tools).",
"type": "module", "type": "module",
"scripts": { "scripts": {

View file

@ -27,7 +27,7 @@
} }
&:not(:last-of-type) { &:not(:last-of-type) {
margin-bottom: var(--spacing-md); margin-bottom: var(--spacing-lg);
} }
& .progress-bar-wrapper { & .progress-bar-wrapper {

View file

@ -48,7 +48,7 @@ schema: artist
<p class="sub-meta tattoo">{% tablericon "needle" "Tattoo" %} I have a tattoo inspired by this artist!</p> <p class="sub-meta tattoo">{% tablericon "needle" "Tattoo" %} I have a tattoo inspired by this artist!</p>
{%- endif -%} {%- endif -%}
{%- if artist.totalPlays > 0 -%} {%- if artist.totalPlays > 0 -%}
<p class="sub-meta"><strong class="highlight-text">{{ artist.totalPlays }} {{ playLabel }}</strong></p> <p class="sub-meta"><strong class="highlight-text">{{ artist.totalPlays | formatNumber }} {{ playLabel }}</strong></p>
{%- endif -%} {%- endif -%}
<p class="sub-meta"> <p class="sub-meta">
<a href="/music/genres/{{ artist.genre | replace: '/', '-' | slugify | downcase }}" title="Learn more about {{ artist.genre | escape }}"> <a href="/music/genres/{{ artist.genre | replace: '/', '-' | slugify | downcase }}" title="Learn more about {{ artist.genre | escape }}">