feat: add rss for logs

This commit is contained in:
dusk 2024-12-16 15:01:51 +03:00
parent cc9963e240
commit ee926f5d6d
Signed by: dusk
SSH Key Fingerprint: SHA256:Abmvag+juovVufZTxyWY8KcVgrznxvBjQpJesv071Aw
2 changed files with 41 additions and 3 deletions

View File

@ -18,9 +18,9 @@ const render = (posts: PostData[]) => `<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"> <rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
<channel> <channel>
<atom:link href="${entriesUrl}/_rss" rel="self" type="application/rss+xml" /> <atom:link href="${entriesUrl}/_rss" rel="self" type="application/rss+xml" />
<title>gaze.systems</title> <title>dusk's posts (@gaze.systems)</title>
<link>${PUBLIC_BASE_URL}</link> <link>${entriesUrl}</link>
<description>dusk's personal website</description> <description>posts from my website</description>
${posts.map((post) => `<item> ${posts.map((post) => `<item>
<guid>${entriesUrl}/${post.path}</guid> <guid>${entriesUrl}/${post.path}</guid>
<title>${post.metadata.title}</title> <title>${post.metadata.title}</title>

View File

@ -0,0 +1,38 @@
import { PUBLIC_BASE_URL } from '$env/static/public';
import { readNote, readNotesList, type Note } from '$lib/notes.ts';
const logUrl = `${PUBLIC_BASE_URL}/log`;
interface NoteData {
data: Note,
id: string,
}
export const GET = async ({ }) => {
const log = readNotesList().map((id) => {return { data: readNote(id), id }})
return new Response(
render(log),
{
headers: {
'content-type': 'application/xml',
'cache-control': 'no-store',
}
})
};
const render = (log: NoteData[]) => `<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
<channel>
<atom:link href="${logUrl}/_rss" rel="self" type="application/rss+xml" />
<title>dusk's notes (@gaze.systems)</title>
<link>${logUrl}</link>
<description>a collection of random notes i write whenever, aka my microblogging spot</description>
${log.map((note) => `<item>
<guid>${logUrl}/?id=${note.id}</guid>
<link>${logUrl}/?id=${note.id}</link>
<description>${note.data.content}</description>
<pubDate>${new Date(note.data.published).toUTCString()}</pubDate>
</item>`).join('')}
</channel>
</rss>
`;