fix the rss feed

This commit is contained in:
Daniel Bulant 2022-08-25 10:27:29 +02:00
parent 75ee719495
commit 3be02ece9a
4 changed files with 24 additions and 19 deletions

View file

@ -12,16 +12,16 @@
"@sveltejs/kit": "1.0.0-next.431", "@sveltejs/kit": "1.0.0-next.431",
"mdsvex": "0.10.5", "mdsvex": "0.10.5",
"svelte": "3.46.4", "svelte": "3.46.4",
"vite-plugin-windicss": "^1.8.6" "vite-plugin-windicss": "^1.8.7"
}, },
"type": "module", "type": "module",
"dependencies": { "dependencies": {
"@sveltejs/pancake": "^0.0.18", "@sveltejs/pancake": "^0.0.18",
"katex": "0.15.2", "katex": "0.15.2",
"luxon": "2.3.1", "luxon": "2.3.1",
"mdast-util-gfm-table": "^1.0.1", "mdast-util-gfm-table": "^1.0.4",
"micromark": "^3.0.5", "micromark": "^3.0.10",
"micromark-extension-gfm-table": "^1.0.3", "micromark-extension-gfm-table": "^1.0.5",
"rehype-autolink-headings": "6.1.1", "rehype-autolink-headings": "6.1.1",
"rehype-katex-svelte": "1.0.3", "rehype-katex-svelte": "1.0.3",
"rehype-slug": "5.0.1", "rehype-slug": "5.0.1",
@ -31,7 +31,7 @@
"remark-parse": "10.0.1", "remark-parse": "10.0.1",
"remark-twemoji": "0.1.1", "remark-twemoji": "0.1.1",
"twemoji": "13.1.0", "twemoji": "13.1.0",
"unified": "^10.1.0", "unified": "^10.1.2",
"vite": "^3.0.9", "vite": "^3.0.9",
"xterm": "4.18.0" "xterm": "4.18.0"
} }

View file

@ -6,10 +6,10 @@ specifiers:
'@sveltejs/pancake': ^0.0.18 '@sveltejs/pancake': ^0.0.18
katex: 0.15.2 katex: 0.15.2
luxon: 2.3.1 luxon: 2.3.1
mdast-util-gfm-table: ^1.0.1 mdast-util-gfm-table: ^1.0.4
mdsvex: 0.10.5 mdsvex: 0.10.5
micromark: ^3.0.5 micromark: ^3.0.10
micromark-extension-gfm-table: ^1.0.3 micromark-extension-gfm-table: ^1.0.5
rehype-autolink-headings: 6.1.1 rehype-autolink-headings: 6.1.1
rehype-katex-svelte: 1.0.3 rehype-katex-svelte: 1.0.3
rehype-slug: 5.0.1 rehype-slug: 5.0.1
@ -20,9 +20,9 @@ specifiers:
remark-twemoji: 0.1.1 remark-twemoji: 0.1.1
svelte: 3.46.4 svelte: 3.46.4
twemoji: 13.1.0 twemoji: 13.1.0
unified: ^10.1.0 unified: ^10.1.2
vite: ^3.0.9 vite: ^3.0.9
vite-plugin-windicss: ^1.8.6 vite-plugin-windicss: ^1.8.7
xterm: 4.18.0 xterm: 4.18.0
dependencies: dependencies:

View file

@ -1,14 +1,14 @@
/** /**
* @type {import("@sveltejs/kit").RequestHandler} * @type {import("@sveltejs/kit").RequestHandler}
*/ */
export async function get(req) { export async function GET(req) {
const allPostFiles = import.meta.glob('../posts/**/*.md'); const allPostFiles = import.meta.glob('../**/*.md');
const allPosts = await Promise.all( const allPosts = await Promise.all(
Object.entries(allPostFiles).map(async ([path, resolver]) => { Object.entries(allPostFiles).map(async ([path, resolver]) => {
const { metadata } = await resolver(); const { metadata } = await resolver();
let postPath = path.slice(2, -3); let postPath = path.slice(2, -3);
if(postPath.endsWith('/index')) postPath = postPath.slice(0, -6); if(postPath.endsWith('/+page')) postPath = postPath.slice(0, -6);
return { return {
...metadata, ...metadata,
path: postPath, path: postPath,
@ -20,8 +20,7 @@ export async function get(req) {
return new Date(b.date) - new Date(a.date) return new Date(b.date) - new Date(a.date)
}); });
return { return new Response(`<?xml version="1.0" encoding="UTF-8" ?>
body: `<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0"> <rss version="2.0">
<channel> <channel>
<title>Blog - Daniel Bulant</title> <title>Blog - Daniel Bulant</title>
@ -35,12 +34,15 @@ export async function get(req) {
<item> <item>
<title>${t.title}</title> <title>${t.title}</title>
<description>${t.description}</description> <description>${t.description}</description>
<link>https://danbulant.eu${t.path}</link> <link>https://danbulant.eu/posts${t.path}</link>
<pubDate>${new Date(t.date).toUTCString()}</pubDate> <pubDate>${new Date(t.date).toUTCString()}</pubDate>
<guid>${t.path}</guid> <guid>${t.path}</guid>
</item>`).join("\n")} </item>`).join("\n")}
</channel> </channel>
</rss>` </rss>`, {
}; headers: {
'Content-Type': 'application/rss+xml'
},
});
} }

View file

@ -13,7 +13,10 @@ const config = {
kit: { kit: {
adapter: adapter({ adapter: adapter({
precompress: true precompress: true
}) }),
prerender: {
default: true
}
}, },
extensions: ['.svelte', '.md'], extensions: ['.svelte', '.md'],