Skip to content

Commit ee42904

Browse files
committed
Refactor posts feed
1 parent bd4554d commit ee42904

10 files changed

Lines changed: 66 additions & 84 deletions

File tree

‎package.json‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"@eslint/compat": "^1.3.1",
1919
"@eslint/js": "^9.32.0",
2020
"@iconify/svelte": "^5.0.1",
21-
"@lucide/svelte": "^0.527.0",
21+
"@lucide/svelte": "^0.528.0",
2222
"@maiertech/sveltekit-helpers": "^0.28.0",
2323
"@playwright/test": "^1.54.1",
2424
"@sindresorhus/slugify": "^2.2.1",
@@ -37,7 +37,6 @@
3737
"prettier": "^3.6.2",
3838
"prettier-plugin-svelte": "^3.4.0",
3939
"prettier-plugin-tailwindcss": "^0.6.14",
40-
"rss": "^1.2.2",
4140
"shiki": "^3.8.1",
4241
"svelte": "^5.37.0",
4342
"svelte-check": "^4.3.0",

‎pnpm-lock.yaml‎

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

‎src/lib/schemas/index.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
export { default as eoApiErrorSchema } from './eo-api-error-schema';
22
export { default as eoListSchema } from './eo-list-schema';
33
export { default as eoSubscriberSchema } from './eo-subscriber-schema';
4-
export { default as subscribeFormSchema } from './subscribe-form-schema';
5-
export { default as unsubscribeFormSchema } from './unsubscribe-form-schema';
4+
export { default as subscribeFormSchema } from './subscribeFormSchema';
5+
export { default as unsubscribeFormSchema } from './unsubscribeFormSchema';

‎src/lib/schemas/subscribe-form-schema.js‎

Lines changed: 0 additions & 6 deletions
This file was deleted.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import * as z from 'zod';
2+
3+
export default z.object({
4+
first_name: z.string().optional(),
5+
email_address: z.email({ error: 'Invalid email address.' })
6+
});

‎src/lib/schemas/unsubscribe-form-schema.js‎

Lines changed: 0 additions & 5 deletions
This file was deleted.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import * as z from 'zod';
2+
3+
export default z.object({
4+
email_address: z.email({ error: 'Invalid email address.' })
5+
});

‎src/routes/+layout.svelte‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,12 @@
2222
<Favicon />
2323

2424
<svelte:head>
25-
<link rel="alternate" type="application/rss+xml" title="Thilo Maier" href="/rss.xml" />
25+
<link
26+
rel="alternate"
27+
type="application/rss+xml"
28+
title="Thilo Maier (posts)"
29+
href="/posts/rss.xml"
30+
/>
2631
</svelte:head>
2732

2833
<PageLayout>
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import type { RequestHandler } from '@sveltejs/kit';
2+
import { PUBLIC_URL_ORIGIN } from '$env/static/public';
3+
import type { ResolvedPost } from '@maiertech/sveltekit-helpers';
4+
5+
export const prerender = true;
6+
7+
export const GET: RequestHandler = async ({ fetch }) => {
8+
const response = await fetch('/api/posts/latest');
9+
const posts = (await response.json()) as ResolvedPost[];
10+
11+
const xml = `<?xml version="1.0" encoding="UTF-8"?>
12+
<rss version="2.0">
13+
<channel>
14+
<title>Thilo Maier (posts)</title>
15+
<description>RSS feed for Thilo Maier's posts.</description>
16+
<link>${PUBLIC_URL_ORIGIN}</link>
17+
<language>en-US</language>
18+
<generator>${PUBLIC_URL_ORIGIN}</generator>
19+
${posts
20+
.map(
21+
(post) => `
22+
<item>
23+
<title>${post.title}</title>
24+
<description>${post.description}</description>
25+
<link>${PUBLIC_URL_ORIGIN}${post.path}</link>
26+
<pubDate>${new Date(post.publishedDate).toUTCString()}</pubDate>
27+
<guid isPermalink="true">${PUBLIC_URL_ORIGIN}${post.path}</guid>
28+
</item>
29+
`
30+
)
31+
.join('')}
32+
</channel>
33+
</rss>`;
34+
35+
return new Response(xml, {
36+
headers: {
37+
'Content-Type': 'application/xml',
38+
'Cache-Control': 'max-age=0, s-maxage=3600'
39+
}
40+
});
41+
};

‎src/routes/rss.xml/+server.ts‎

Lines changed: 0 additions & 33 deletions
This file was deleted.

0 commit comments

Comments
 (0)