feat: add jsonfeed api
All checks were successful
create archive with lfs / tag (push) Successful in 8s

This commit is contained in:
dusk 2024-09-30 06:50:54 +03:00
parent c614a66c98
commit 9ec18b728a
Signed by: dusk
SSH Key Fingerprint: SHA256:Abmvag+juovVufZTxyWY8KcVgrznxvBjQpJesv071Aw
2 changed files with 37 additions and 1 deletions

View File

@ -0,0 +1,34 @@
import { PUBLIC_BASE_URL } from '$env/static/public';
import { _allPosts, type PostData } from '../+layout.ts';
const entriesUrl = `${PUBLIC_BASE_URL}/entries`;
export const GET = async ({ }) => {
return new Response(
render(_allPosts),
{
headers: {
'content-type': 'application/json',
'cache-control': 'no-store',
}
})
};
const render = (posts: PostData[]) => {
return JSON.stringify({
version: 'https://jsonfeed.org/version/1.1',
title: 'gaze.systems posts feed',
home_page_url: PUBLIC_BASE_URL,
feed_url: `${entriesUrl}/_jsonfeed`,
items: posts.map((post) => {
return {
id: post.path,
url: `${entriesUrl}/${post.path}`,
title: post.metadata.title,
summary: post.metadata.excerpt,
content_text: 'read the post on the website',
date_published: new Date(post.metadata.date).toISOString(),
}
}),
})
}

View File

@ -4,7 +4,9 @@ import { _allPosts, type PostData } from '../+layout.ts';
const entriesUrl = `${PUBLIC_BASE_URL}/entries`; const entriesUrl = `${PUBLIC_BASE_URL}/entries`;
export const GET = async ({ }) => { export const GET = async ({ }) => {
return new Response(render(_allPosts), { return new Response(
render(_allPosts),
{
headers: { headers: {
'content-type': 'application/xml', 'content-type': 'application/xml',
'cache-control': 'no-store', 'cache-control': 'no-store',