-
-
Notifications
You must be signed in to change notification settings - Fork 10
/
feed.json.ts
53 lines (48 loc) · 1.37 KB
/
feed.json.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import { getImage } from 'astro:assets'
import faviconSrc from '@/images/favicon.png'
import { getAllPosts } from '@/lib/astro'
import { getFeedContent } from '@/lib/feed'
import config from '@config/blog.config'
import type { AstroConfig } from 'astro'
const { siteTitle, siteDescription, author } = config
const favicon = await getImage({
src: faviconSrc,
width: 64,
height: 64,
format: 'png'
})
export async function GET(context: AstroConfig) {
const allPostsSorted = await getAllPosts()
const items = await Promise.all(
allPostsSorted.map(async (post) => ({
id: post.id,
url: `${context.site}${post.slug}`,
title: post.data.title,
date_published: post.data.date as Date,
...(post.data.updated && { date_modified: post.data.updated as Date }),
content_html: await getFeedContent(post)
}))
)
return new Response(
JSON.stringify({
version: 'https://jsonfeed.org/version/1.1',
title: siteTitle,
description: siteDescription,
home_page_url: context.site,
feed_url: `${context.site}feed.json`,
favicon: `${context.site}${favicon}`,
icon: `${context.site}${faviconSrc.src}`,
language: 'en-US',
authors: [
{
name: author.name,
url: author.url
}
],
items
}),
{
headers: { 'content-type': 'application/json' }
}
)
}