🐛 Fix rss
This commit is contained in:
@ -1,28 +1,44 @@
|
||||
import RSS from "rss";
|
||||
import { Feed } from "feed";
|
||||
import { SITE_DESCRIPTION, SITE_NAME, SITE_URL } from "@/app/consts";
|
||||
import { getSortedPosts } from "@/content/posts";
|
||||
import { client } from "@/sanity/lib/client";
|
||||
|
||||
export async function GET() {
|
||||
const feed = new RSS({
|
||||
const feed = new Feed({
|
||||
title: SITE_NAME,
|
||||
description: SITE_DESCRIPTION,
|
||||
site_url: SITE_URL,
|
||||
feed_url: `${SITE_URL}/feed`,
|
||||
id: SITE_URL,
|
||||
link: SITE_URL,
|
||||
favicon: `${SITE_URL}/favicon.png`,
|
||||
feedLinks: { atom: `${SITE_URL}/feed` },
|
||||
language: "zh-CN",
|
||||
copyright: `Copyright © ${new Date().getFullYear()} SmartSheep Studio`,
|
||||
});
|
||||
|
||||
getSortedPosts().forEach((item) => {
|
||||
feed.item({
|
||||
url: `${SITE_URL}/p/${item.id}`,
|
||||
const posts = await client.fetch<any[]>(`*[_type == "post"] {
|
||||
title, description, slug, publishedAt,
|
||||
mainImage {
|
||||
asset -> {
|
||||
_id,
|
||||
url
|
||||
},
|
||||
alt
|
||||
},
|
||||
"categories": categories[]->title,
|
||||
}`);
|
||||
|
||||
posts.forEach((item) => {
|
||||
feed.addItem({
|
||||
id: `${SITE_URL}/p/${item.slug.current}`,
|
||||
link: `${SITE_URL}/p/${item.slug.current}`,
|
||||
title: item.title,
|
||||
description: item.description ?? "No description yet.",
|
||||
date: item.date,
|
||||
date: new Date(item.publishedAt)
|
||||
});
|
||||
});
|
||||
|
||||
return new Response(feed.xml(), {
|
||||
return new Response(feed.rss2(), {
|
||||
headers: {
|
||||
"content-type": "application/xml",
|
||||
},
|
||||
"content-type": "application/xml"
|
||||
}
|
||||
});
|
||||
}
|
||||
|
Reference in New Issue
Block a user