-
-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
10ff4cf
commit d9bab3c
Showing
5 changed files
with
97 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,4 +39,7 @@ sitemap.xml | |
|
||
# cypress | ||
cypress/videos | ||
cypress/screenshots | ||
cypress/screenshots | ||
|
||
# rss | ||
rss.xml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import format from 'date-fns/format'; | ||
import fs from 'fs'; | ||
|
||
import { getAllFilesFrontmatter } from '@/lib/mdx'; | ||
|
||
export async function getRssXml() { | ||
const frontmatters = await getAllFilesFrontmatter('blog'); | ||
|
||
const blogUrl = 'https://theodorusclarence.com/blog'; | ||
|
||
const itemXml = frontmatters | ||
.filter((fm) => !fm.slug.startsWith('id-')) | ||
.map(({ slug, title, description, publishedAt, lastUpdated }) => | ||
` | ||
<item> | ||
<title>${cdata(title)}</title> | ||
<description>${cdata(description)}</description> | ||
<link>${blogUrl}/${slug}</link> | ||
<guid>${blogUrl}/${slug}</guid> | ||
<pubDate>${format( | ||
new Date(lastUpdated ?? publishedAt), | ||
'yyyy-MM-ii' | ||
)}</pubDate> | ||
</item> | ||
`.trim() | ||
); | ||
|
||
return ` | ||
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:blogChannel="${blogUrl}"> | ||
<channel> | ||
<title>Theodorus Clarence Blog</title> | ||
<link>${blogUrl}</link> | ||
<description>The Theodorus Clarence Blog, thoughts, mental models, and tutorials about front-end development.</description> | ||
<language>en</language> | ||
<ttl>40</ttl> | ||
${itemXml.join('\n')} | ||
</channel> | ||
</rss> | ||
`.trim(); | ||
} | ||
|
||
function cdata(s: string) { | ||
return `<![CDATA[${s}]]>`; | ||
} | ||
|
||
export async function generateRss() { | ||
const xml = await getRssXml(); | ||
fs.writeFileSync('public/rss.xml', xml); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
d9bab3c
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs: