|
| 1 | +import { defineConfig, createContentLoader } from 'vitepress'; |
| 2 | +import path from 'node:path' |
| 3 | +import { writeFileSync } from 'node:fs' |
| 4 | +import { Feed } from 'feed' |
| 5 | + |
| 6 | +import { formatPageContentForRSS } from './theme/utils'; |
| 7 | + |
| 8 | +const siteTitle = 'Neural Interfaces'; |
| 9 | +const siteDescription = 'The Catalog of Brain-Responsive Applications'; |
| 10 | +const blogDir = 'posts'; |
| 11 | + |
| 12 | +const hostName = 'https://neuralinterfaces.com'; |
| 13 | +const author = [ |
| 14 | + { |
| 15 | + name: 'Garrett Flynn', |
| 16 | + |
| 17 | + link: `garrettflynn.com` |
| 18 | + } |
| 19 | +] |
| 20 | + |
| 21 | +const siteCopyright = 'Copyright © 2024-present Garrett Flynn'; |
| 22 | + |
| 23 | +const formattedPagesForRSS: Record<string, string> = {}; |
| 24 | + |
| 25 | +// https://vitepress.dev/reference/site-config |
| 26 | +export default defineConfig({ |
| 27 | + lang: 'en-US', |
| 28 | + title: siteTitle, |
| 29 | + description: siteDescription, |
| 30 | + |
| 31 | + head: [['link', { rel: 'icon', href: '/favicon.ico' }]], |
| 32 | + |
| 33 | + themeConfig: { |
| 34 | + |
| 35 | + logo: '/logo_dark.png', |
| 36 | + |
| 37 | + nav: [ |
| 38 | + { text: 'Home', link: '/' }, |
| 39 | + { text: 'Catalog', link: '/catalog' }, |
| 40 | + { text: 'Blog', link: '/posts' } |
| 41 | + ], |
| 42 | + |
| 43 | + socialLinks: [ |
| 44 | + { icon: 'github', link: 'https://github.com/neuralinterfaces' }, |
| 45 | + ], |
| 46 | + |
| 47 | + footer: { |
| 48 | + message: 'Built with 🧠 by Garrett Flynn', |
| 49 | + copyright: siteCopyright |
| 50 | + } |
| 51 | + }, |
| 52 | + |
| 53 | + transformHtml(_code, _id, { content, pageData }) { |
| 54 | + const { filePath } = pageData; |
| 55 | + const dirname = path.dirname(filePath); |
| 56 | + const basename = path.basename(filePath, '.md'); |
| 57 | + |
| 58 | + if (dirname === blogDir) { |
| 59 | + const html = formatPageContentForRSS(content, hostName); |
| 60 | + if (html) { |
| 61 | + formattedPagesForRSS[`/${dirname}/${basename}`] = html; |
| 62 | + } |
| 63 | + } |
| 64 | + }, |
| 65 | + |
| 66 | + |
| 67 | + buildEnd: async (config) => { |
| 68 | + |
| 69 | + const feed = new Feed({ |
| 70 | + title: siteTitle, |
| 71 | + description: siteDescription, |
| 72 | + id: hostName, |
| 73 | + link: hostName, |
| 74 | + copyright: siteCopyright, |
| 75 | + language: 'en', |
| 76 | + }); |
| 77 | + |
| 78 | + // Load data from all the blog markdown files, sorted by date |
| 79 | + const posts = await createContentLoader(`/${blogDir}/*.md`, { |
| 80 | + render: true, |
| 81 | + includeSrc: true, |
| 82 | + transform(rawData) { |
| 83 | + return rawData.sort((a, b) => { |
| 84 | + return +new Date(b.frontmatter.date).getTime() - +new Date(a.frontmatter.date).getTime() |
| 85 | + }); |
| 86 | + } |
| 87 | + }).load(); |
| 88 | + |
| 89 | + for (const { url, excerpt, frontmatter, html } of posts) { |
| 90 | + |
| 91 | + if (frontmatter.status === 'draft') continue; |
| 92 | + |
| 93 | + const improvedHtml = formattedPagesForRSS[url]; |
| 94 | + |
| 95 | + feed.addItem({ |
| 96 | + title: frontmatter.title, |
| 97 | + id: `${hostName}${url}`, |
| 98 | + link: `${hostName}${url}`, |
| 99 | + description: excerpt, |
| 100 | + content: improvedHtml || html, |
| 101 | + author, |
| 102 | + date: frontmatter.date |
| 103 | + }); |
| 104 | + } |
| 105 | + |
| 106 | + writeFileSync(path.join(config.outDir, 'feed.rss'), feed.rss2()); |
| 107 | + } |
| 108 | + |
| 109 | +}) |
0 commit comments