feat: add jsonfeed api
All checks were successful
create archive with lfs / tag (push) Successful in 8s
All checks were successful
create archive with lfs / tag (push) Successful in 8s
This commit is contained in:
parent
c614a66c98
commit
9ec18b728a
34
src/routes/entries/_jsonfeed/+server.ts
Normal file
34
src/routes/entries/_jsonfeed/+server.ts
Normal 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(),
|
||||
}
|
||||
}),
|
||||
})
|
||||
}
|
@ -4,7 +4,9 @@ import { _allPosts, type PostData } from '../+layout.ts';
|
||||
const entriesUrl = `${PUBLIC_BASE_URL}/entries`;
|
||||
|
||||
export const GET = async ({ }) => {
|
||||
return new Response(render(_allPosts), {
|
||||
return new Response(
|
||||
render(_allPosts),
|
||||
{
|
||||
headers: {
|
||||
'content-type': 'application/xml',
|
||||
'cache-control': 'no-store',
|
||||
|
Loading…
Reference in New Issue
Block a user