feat: refactor feeds; reduce dependencies
This commit is contained in:
parent
4067148658
commit
d768007f1c
375 changed files with 2568 additions and 13971 deletions
|
@ -1,5 +1,4 @@
|
|||
import { DateTime } from 'luxon'
|
||||
import tagAliases from '../data/tag-aliases.js'
|
||||
import { makeYearStats, processPostFile } from './utils.js'
|
||||
|
||||
export const searchIndex = (collection) => {
|
||||
|
@ -45,32 +44,6 @@ export const tagList = (collection) => {
|
|||
return Array.from(tagsSet).sort()
|
||||
}
|
||||
|
||||
export const tagMap = (collection) => {
|
||||
const tags = {}
|
||||
const collectionData = collection.getAll()[0]
|
||||
const posts = collectionData.data.collections.posts
|
||||
const links = collectionData.data.links
|
||||
if (posts) {
|
||||
posts.forEach((post) => {
|
||||
const url = post.url.includes('http') ? post.url : `https://coryd.dev${post.url}`
|
||||
const tagString = [...new Set(post.data.tags.map((tag) => tagAliases[tag.toLowerCase()]))]
|
||||
.join(' ')
|
||||
.trim()
|
||||
if (tagString) tags[url] = tagString.replace(/\s+/g,' ')
|
||||
})
|
||||
}
|
||||
if (links) {
|
||||
links.forEach((link) => {
|
||||
const tagString = link['tags']
|
||||
.map((tag) => tagAliases[tag.toLowerCase()])
|
||||
.join(' ')
|
||||
.trim()
|
||||
if (tagString) tags[link.url] = tagString.replace(/\s+/g,' ')
|
||||
})
|
||||
}
|
||||
return tags
|
||||
}
|
||||
|
||||
export const tagsSortedByCount = (collection) => {
|
||||
const tagStats = {};
|
||||
collection.getFilteredByGlob('src/posts/**/*.*').forEach((item) => {
|
||||
|
@ -85,6 +58,8 @@ export const tagsSortedByCount = (collection) => {
|
|||
return Object.entries(tagStats).sort((a, b) => b[1] - a[1]).map(([key, value]) => `${key}`);
|
||||
}
|
||||
|
||||
export const links = (collection) => collection.getFilteredByGlob('src/links/**/*.*').reverse()
|
||||
|
||||
export const postStats = (collection) => {
|
||||
const oneDayMilliseconds = 1000 * 60 * 60 * 24
|
||||
const statsObject = {
|
||||
|
|
|
@ -1,42 +0,0 @@
|
|||
export default {
|
||||
'11ty': '#Eleventy',
|
||||
accessibility: '#Accessibility',
|
||||
ai: '#AI',
|
||||
'black metal': '#BlackMetal',
|
||||
blogging: '#Blogging',
|
||||
books: '#Books',
|
||||
climate: '#Climate',
|
||||
css: '#CSS',
|
||||
'death metal': '#DeathMetal',
|
||||
development: '#WebDev',
|
||||
economics: '#Economics',
|
||||
eleventy: '#Eleventy',
|
||||
email: '#Email',
|
||||
emo: '#Emo',
|
||||
fastmail: '#Email',
|
||||
gmail: '#Email',
|
||||
grindcore: '#Grindcore',
|
||||
health: '#Health',
|
||||
'indie web': '#IndieWeb #SmallWeb',
|
||||
ios: '#iOS #Apple',
|
||||
javascript: '#JavaScript',
|
||||
'last.fm': '#Music',
|
||||
journalism: '#Journalism',
|
||||
labor: '#Work',
|
||||
lastfm: '#Music',
|
||||
macos: '#macOS #Apple',
|
||||
mastodon: '#Mastodon',
|
||||
music: '#Music',
|
||||
privacy: '#Privacy',
|
||||
productivity: '#Productivity',
|
||||
react: '#JavaScript',
|
||||
rss: '#RSS',
|
||||
shoegaze: '#Shoegaze',
|
||||
'social media': '#SocialMedia',
|
||||
spotify: '#Music',
|
||||
'surveillance capitalism': '#SurveillanceCapitalism',
|
||||
'tattoos': '#Tattoos',
|
||||
tech: '#Tech',
|
||||
technology: '#Tech',
|
||||
'web components': '#WebComponents'
|
||||
}
|
|
@ -60,14 +60,6 @@ export default {
|
|||
})
|
||||
},
|
||||
|
||||
// tags
|
||||
tagLookup: (url, tagMap) => {
|
||||
if (!url) return
|
||||
if (url.includes('thestorygraph.com')) return '#Books #NowReading #TheStoryGraph'
|
||||
if (url.includes('trakt.tv')) return '#Movies #Watching #Trakt'
|
||||
return tagMap[url] || ''
|
||||
},
|
||||
|
||||
// dates
|
||||
readableDate: (date) => {
|
||||
return DateTime.fromISO(date).toFormat('LLLL d, yyyy')
|
||||
|
@ -144,6 +136,7 @@ export default {
|
|||
|
||||
// set the entry excerpt
|
||||
if (entry.description) excerpt = entry.description
|
||||
if (entry?.data?.description) excerpt = entry?.data?.description
|
||||
if (entry.content) excerpt = sanitizeHtml(`${entry.content}${feedNote}`, {
|
||||
disallowedTagsMode: 'completelyDiscard'
|
||||
})
|
||||
|
@ -153,7 +146,7 @@ export default {
|
|||
posts.push({
|
||||
title: entry.data?.title || entry.title,
|
||||
url: entry.url.includes('http') ? entry.url : new URL(entry.url, BASE_URL).toString(),
|
||||
content: entry.description,
|
||||
content: entry?.description || entry?.data?.description,
|
||||
date,
|
||||
excerpt,
|
||||
})
|
||||
|
|
Reference in a new issue