chore: cleanup
This commit is contained in:
parent
3f48399c09
commit
4696b0c383
6 changed files with 72 additions and 75 deletions
|
@ -32,11 +32,23 @@ export const processContent = (collection) => {
|
|||
|
||||
const parseDate = (date) => {
|
||||
if (!date) return null
|
||||
let parsedDate = DateTime.fromISO(date)
|
||||
if (!parsedDate.isValid) parsedDate = DateTime.fromFormat(date, 'yyyy-MM-dd')
|
||||
if (!parsedDate.isValid) parsedDate = DateTime.fromFormat(date, 'MM/dd/yyyy')
|
||||
if (!parsedDate.isValid) parsedDate = DateTime.fromFormat(date, 'dd-MM-yyyy')
|
||||
return parsedDate.isValid ? parsedDate : null
|
||||
|
||||
const formats = [
|
||||
{ method: 'fromISO' },
|
||||
{ method: 'fromFormat', format: 'yyyy-MM-dd' },
|
||||
{ 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) => {
|
||||
|
|
|
@ -12,79 +12,67 @@ export default {
|
|||
const posts = []
|
||||
const mdGenerator = () => {
|
||||
const md = markdownIt({ html: true, linkify: true })
|
||||
|
||||
md.use(markdownItAnchor, {
|
||||
level: [1, 2],
|
||||
permalink: markdownItAnchor.permalink.headerLink({
|
||||
safariReaderFix: true
|
||||
})
|
||||
permalink: markdownItAnchor.permalink.headerLink({ safariReaderFix: true })
|
||||
})
|
||||
md.use(markdownItFootnote)
|
||||
md.renderer.rules.footnote_ref = (tokens, idx) => {
|
||||
const id = tokens[idx].meta.id + 1
|
||||
return `<sup>${id}</sup>`
|
||||
}
|
||||
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_ref = (tokens, idx) => `<sup>${tokens[idx].meta.id + 1}</sup>`
|
||||
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) => `<li id="fn${tokens[idx].meta.id + 1}" class="footnote-item"> `
|
||||
md.renderer.rules.footnote_anchor = () => ''
|
||||
|
||||
return md
|
||||
}
|
||||
const entryData = limit ? entries.slice(0, limit) : entries
|
||||
|
||||
const entryData = limit ? entries.slice(0, limit) : entries
|
||||
entryData.forEach((entry) => {
|
||||
const md = mdGenerator()
|
||||
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 processedEntry = { title: title.trim(), date: new Date(entry[dateKey]), content: description }
|
||||
|
||||
if (url?.includes('http')) processedEntry['url'] = url
|
||||
if (!url?.includes('http')) processedEntry['url'] = new URL(url, BASE_URL).toString()
|
||||
if (slug) processedEntry['url'] = new URL(slug, BASE_URL).toString()
|
||||
processedEntry.url = (url?.includes('http')) ? url : new URL(slug || url, BASE_URL).toString()
|
||||
|
||||
if (link) {
|
||||
processedEntry['title'] = `${title} via ${authors['name']}`
|
||||
processedEntry['url'] = link,
|
||||
processedEntry['author'] = {
|
||||
name: authors['name'],
|
||||
url: authors['url'],
|
||||
mastodon: authors?.['mastodon'] || '',
|
||||
rss: authors?.['rss_feed'] || ''
|
||||
},
|
||||
processedEntry['excerpt'] = sanitizeHtml(`${md.render(description)}`)
|
||||
}
|
||||
if (description) processedEntry['excerpt'] = description
|
||||
if (['book', 'movie'].includes(type) && review) {
|
||||
processedEntry['excerpt'] = sanitizeHtml(`${md.render(review)}`)
|
||||
processedEntry.title = `${title} via ${authors?.name || 'Unknown'}`
|
||||
processedEntry.url = link
|
||||
processedEntry.author = {
|
||||
name: authors?.name || 'Unknown',
|
||||
url: authors?.url || '',
|
||||
mastodon: authors?.mastodon || '',
|
||||
rss: authors?.rss_feed || ''
|
||||
}
|
||||
processedEntry.excerpt = sanitizeHtml(md.render(description || ''))
|
||||
} 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 (tags) processedEntry['tags'] = tags
|
||||
if (type === 'album-release' && artist) processedEntry['title'] = `${title} by ${artist}`
|
||||
if (rating) processedEntry.rating = rating
|
||||
if (tags) processedEntry.tags = tags
|
||||
if (type === 'album-release' && artist) processedEntry.title = `${title} by ${artist}`
|
||||
|
||||
if (entry) posts.push(processedEntry)
|
||||
posts.push(processedEntry)
|
||||
})
|
||||
|
||||
return posts
|
||||
|
|
25
package-lock.json
generated
25
package-lock.json
generated
|
@ -1,12 +1,12 @@
|
|||
{
|
||||
"name": "coryd.dev",
|
||||
"version": "24.19.5",
|
||||
"version": "24.19.7",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "coryd.dev",
|
||||
"version": "24.19.5",
|
||||
"version": "24.19.7",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@cdransf/api-text": "^1.5.0",
|
||||
|
@ -701,9 +701,9 @@
|
|||
"peer": true
|
||||
},
|
||||
"node_modules/@types/node": {
|
||||
"version": "22.5.5",
|
||||
"resolved": "https://registry.npmjs.org/@types/node/-/node-22.5.5.tgz",
|
||||
"integrity": "sha512-Xjs4y5UPO/CLdzpgR6GirZJx36yScjh73+2NlLlkFRSoQN8B0DpfXPdZGnvVmLRLOsqDpOfTNv7D9trgGhmOIA==",
|
||||
"version": "22.6.1",
|
||||
"resolved": "https://registry.npmjs.org/@types/node/-/node-22.6.1.tgz",
|
||||
"integrity": "sha512-V48tCfcKb/e6cVUigLAaJDAILdMP0fUW6BidkPK4GpGjXcfbnoHasCZDwz3N3yVt5we2RHm4XTQCpv0KJz9zqw==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
|
@ -1083,9 +1083,9 @@
|
|||
}
|
||||
},
|
||||
"node_modules/caniuse-lite": {
|
||||
"version": "1.0.30001662",
|
||||
"resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001662.tgz",
|
||||
"integrity": "sha512-sgMUVwLmGseH8ZIrm1d51UbrhqMCH3jvS7gF/M6byuHOnKyLOBL7W8yz5V02OHwgLGA36o/AFhWzzh4uc5aqTA==",
|
||||
"version": "1.0.30001663",
|
||||
"resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001663.tgz",
|
||||
"integrity": "sha512-o9C3X27GLKbLeTYZ6HBOLU1tsAcBZsLis28wrVzddShCS16RujjHp9GDHKZqrB3meE0YjhawvMFsGb/igqiPzA==",
|
||||
"dev": true,
|
||||
"funding": [
|
||||
{
|
||||
|
@ -2651,9 +2651,9 @@
|
|||
}
|
||||
},
|
||||
"node_modules/jackspeak": {
|
||||
"version": "4.0.1",
|
||||
"resolved": "https://registry.npmjs.org/jackspeak/-/jackspeak-4.0.1.tgz",
|
||||
"integrity": "sha512-cub8rahkh0Q/bw1+GxP7aeSe29hHHn2V4m29nnDlvCdlgU+3UGxkZp7Z53jLUdpX3jdTO0nJZUDl3xvbWc2Xog==",
|
||||
"version": "4.0.2",
|
||||
"resolved": "https://registry.npmjs.org/jackspeak/-/jackspeak-4.0.2.tgz",
|
||||
"integrity": "sha512-bZsjR/iRjl1Nk1UkjGpAzLNfQtzuijhn2g+pbZb98HQ1Gk8vM9hfbxeMBP+M2/UUdwj0RqGG3mlvk2MsAqwvEw==",
|
||||
"dev": true,
|
||||
"license": "BlueOak-1.0.0",
|
||||
"dependencies": {
|
||||
|
@ -2664,9 +2664,6 @@
|
|||
},
|
||||
"funding": {
|
||||
"url": "https://github.com/sponsors/isaacs"
|
||||
},
|
||||
"optionalDependencies": {
|
||||
"@pkgjs/parseargs": "^0.11.0"
|
||||
}
|
||||
},
|
||||
"node_modules/js-yaml": {
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "coryd.dev",
|
||||
"version": "24.19.5",
|
||||
"version": "24.19.7",
|
||||
"description": "The source for my personal site. Built using 11ty (and other tools).",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
|
|
|
@ -27,7 +27,7 @@
|
|||
}
|
||||
|
||||
&:not(:last-of-type) {
|
||||
margin-bottom: var(--spacing-md);
|
||||
margin-bottom: var(--spacing-lg);
|
||||
}
|
||||
|
||||
& .progress-bar-wrapper {
|
||||
|
|
|
@ -48,7 +48,7 @@ schema: artist
|
|||
<p class="sub-meta tattoo">{% tablericon "needle" "Tattoo" %} I have a tattoo inspired by this artist!</p>
|
||||
{%- endif -%}
|
||||
{%- 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 -%}
|
||||
<p class="sub-meta">
|
||||
<a href="/music/genres/{{ artist.genre | replace: '/', '-' | slugify | downcase }}" title="Learn more about {{ artist.genre | escape }}">
|
||||
|
|
Reference in a new issue