uh rss feed done
This commit is contained in:
parent
1435cbb397
commit
803afe55d1
1 changed files with 11 additions and 7 deletions
|
@ -4,6 +4,12 @@ import { client } from "@/lib/sanity";
|
||||||
import { toHTML } from "@portabletext/to-html";
|
import { toHTML } from "@portabletext/to-html";
|
||||||
|
|
||||||
export async function GET() {
|
export async function GET() {
|
||||||
|
// Define the site URL based on the environment
|
||||||
|
const SITE_URL =
|
||||||
|
process.env.NODE_ENV === "production"
|
||||||
|
? "https://svrjs.vercel.app"
|
||||||
|
: "http://localhost:3000";
|
||||||
|
|
||||||
const postsQuery = `*[_type == 'blog'] | order(_createdAt desc) {
|
const postsQuery = `*[_type == 'blog'] | order(_createdAt desc) {
|
||||||
title,
|
title,
|
||||||
"slug": slug.current,
|
"slug": slug.current,
|
||||||
|
@ -12,11 +18,6 @@ export async function GET() {
|
||||||
_createdAt
|
_createdAt
|
||||||
}`;
|
}`;
|
||||||
|
|
||||||
const SITE_URL =
|
|
||||||
process.env.NODE_ENV === "production"
|
|
||||||
? "http://localhost:3000"
|
|
||||||
: "https://svrjs.vercel.app";
|
|
||||||
|
|
||||||
const posts = await client.fetch(postsQuery);
|
const posts = await client.fetch(postsQuery);
|
||||||
|
|
||||||
const feed = new RSS({
|
const feed = new RSS({
|
||||||
|
@ -35,12 +36,15 @@ export async function GET() {
|
||||||
description: toHTML(post.content),
|
description: toHTML(post.content),
|
||||||
url: `${SITE_URL}/blog/${post.slug}`,
|
url: `${SITE_URL}/blog/${post.slug}`,
|
||||||
date: new Date(post._createdAt).toUTCString(),
|
date: new Date(post._createdAt).toUTCString(),
|
||||||
|
// uncomment this if u want to
|
||||||
// enclosure: { url: urlFor(post.titleImage).url() },
|
// enclosure: { url: urlFor(post.titleImage).url() },
|
||||||
// author: "SVRJS",
|
// author: "SVRJS",
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
return NextResponse.json(feed.xml({ indent: true }), {
|
return new NextResponse(feed.xml({ indent: true }), {
|
||||||
headers: { "Content-Type": "application" },
|
headers: {
|
||||||
|
"Content-Type": "application/xml",
|
||||||
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue