Skip to content

Commit 973adc1

Browse files
added RSS feed
1 parent 2baf326 commit 973adc1

6 files changed

Lines changed: 237 additions & 1 deletion

File tree

astro.config.mjs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export default defineConfig({
1414
},
1515
smartypants: false,
1616
},
17+
trailingSlash: "never",
1718
build: {
1819
format: 'file',
1920
},
@@ -46,4 +47,8 @@ export default defineConfig({
4647
},
4748
}),
4849
],
50+
i18n: {
51+
defaultLocale: "en",
52+
locales: ["en"]
53+
}
4954
});

package-lock.json

Lines changed: 183 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,12 @@
1010
},
1111
"dependencies": {
1212
"@astrojs/prism": "^3.3.0",
13+
"@astrojs/rss": "^4.0.15",
1314
"@tailwindcss/vite": "^4.1.18",
1415
"astro": "^5.16.11",
1516
"astro-favicons": "^3.1.5",
17+
"markdown-it": "^14.1.0",
18+
"sanitize-html": "^2.17.0",
1619
"tailwindcss": "^4.1.18"
1720
},
1821
"devDependencies": {

src/components/Header.astro

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,17 @@
1818
</nav>
1919

2020
<div class="flex items-center gap-4">
21+
<a href="/rss.xml" target="_blank" rel="noopener noreferrer" class="text-slate-500 hover:text-slate-900 dark:text-blog-text dark:hover:text-blog-accent transition-colors">
22+
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-rss-icon lucide-rss">
23+
<title>RSS</title>
24+
<path d="M4 11a9 9 0 0 1 9 9"/>
25+
<path d="M4 4a16 16 0 0 1 16 16"/>
26+
<circle cx="5" cy="19" r="1"/>
27+
</svg>
28+
</a>
2129
<a href="https://github.com/kyle-undefined" target="_blank" rel="noopener noreferrer" class="text-slate-500 hover:text-slate-900 dark:text-blog-text dark:hover:text-blog-accent transition-colors">
2230
<span class="sr-only">GitHub</span>
23-
<svg role="img" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-external-link w-5 h-5 text-slate-400 hover:text-blog-proj-link dark:hover:text-blog-proj-link">
31+
<svg role="img" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-external-link w-5 h-5 text-slate-400 hover:text-blog-accent dark:hover:text-blog-accent">
2432
<title>GitHub</title>
2533
<path d="M12 .297c-6.63 0-12 5.373-12 12 0 5.303 3.438 9.8 8.205 11.385.6.113.82-.258.82-.577 0-.285-.01-1.04-.015-2.04-3.338.724-4.042-1.61-4.042-1.61C4.422 18.07 3.633 17.7 3.633 17.7c-1.087-.744.084-.729.084-.729 1.205.084 1.838 1.236 1.838 1.236 1.07 1.835 2.809 1.305 3.495.998.108-.776.417-1.305.76-1.605-2.665-.3-5.466-1.332-5.466-5.93 0-1.31.465-2.38 1.235-3.22-.135-.303-.54-1.523.105-3.176 0 0 1.005-.322 3.3 1.23.96-.267 1.98-.399 3-.405 1.02.006 2.04.138 3 .405 2.28-1.552 3.285-1.23 3.285-1.23.645 1.653.24 2.873.12 3.176.765.84 1.23 1.91 1.23 3.22 0 4.61-2.805 5.625-5.475 5.92.42.36.81 1.096.81 2.22 0 1.606-.015 2.896-.015 3.286 0 .315.21.69.825.57C20.565 22.092 24 17.592 24 12.297c0-6.627-5.373-12-12-12"/>
2634
</svg>

src/layouts/Layout.astro

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ const { title, description = "Kyle Undefined.dev, just a dude who enjoys writing
3131
<meta property="twitter:url" content={Astro.url} />
3232
<meta property="twitter:title" content={title} />
3333
<meta property="twitter:description" content={description} />
34+
35+
<!-- RSS -->
36+
<link rel="alternate" type="application/rss+xml" title="kyleundefined.dev" href={new URL("rss.xml", Astro.site).href} />
3437

3538
<title>{title}</title>
3639

src/pages/rss.xml.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import rss from '@astrojs/rss';
2+
import { getCollection } from 'astro:content';
3+
import sanitizeHtml from 'sanitize-html';
4+
import MarkdownIt from 'markdown-it';
5+
import { site, i18n } from 'astro:config/client';
6+
7+
const blog = (await getCollection('blog')).sort((a, b) => b.data.pubDate.valueOf() - a.data.pubDate.valueOf());
8+
const parser = new MarkdownIt();
9+
10+
export async function GET(context) {
11+
return rss({
12+
title: 'kyleundefined.dev',
13+
description: 'Just a dude who enjoys writing code and learning;',
14+
trailingSlash: false,
15+
site: context.site,
16+
customData: ([
17+
`<language>${i18n.defaultLocale}</language>`,
18+
`<atom:link href="${new URL('rss.xml', site).href}" rel="self" type="application/rss+xml" />`,
19+
]).join(''),
20+
xmlns: {
21+
atom: 'http://www.w3.org/2005/Atom',
22+
content: 'http://purl.org/rss/1.0/modules/content/'
23+
},
24+
items: blog.map((post) => ({
25+
title: post.data.title,
26+
description: post.data.description,
27+
link: `/blog/${post.slug}/`,
28+
pubDate: post.data.pubDate,
29+
content: sanitizeHtml(parser.render(post.body), {
30+
allowedTags: sanitizeHtml.defaults.allowedTags.concat(['img'])
31+
}),
32+
})),
33+
});
34+
}

0 commit comments

Comments
 (0)