feat: change the default format of the feed to XML

This commit is contained in:
DIYgod 2023-07-18 16:47:58 +01:00
parent dcd64efea6
commit 0c5860453b
No known key found for this signature in database
9 changed files with 33 additions and 30 deletions

View File

@ -25,7 +25,7 @@ export async function GET(request: Request) {
),
}
const format = searchParams.get("format") === "xml" ? "xml" : "json"
const format = searchParams.get("format") === "json" ? "json" : "xml"
const res = new NextServerResponse()
return res.status(200).rss(data, format)

View File

@ -21,9 +21,9 @@ export async function GET(request: Request) {
}
const format =
new URLSearchParams(request.url.split("?")[1]).get("format") === "xml"
? "xml"
: "json"
new URLSearchParams(request.url.split("?")[1]).get("format") === "json"
? "json"
: "xml"
const res = new NextServerResponse()
return res.status(200).rss(data, format)

View File

@ -32,28 +32,34 @@ export const metadata: Metadata = {
alternates: {
types: {
"application/rss+xml": [
{ url: "/feed/latest?format=xml", title: "xLog Latest" },
{ url: "/feed/hottest?interval=0&format=xml", title: "xLog Hottest" },
{ url: "/feed/latest", title: "xLog Latest" },
{ url: "/feed/hottest?interval=0", title: "xLog Hottest" },
{
url: "/feed/hottest?interval=1&format=xml",
url: "/feed/hottest?interval=1",
title: "xLog Hottest of the Day",
},
{
url: "/feed/hottest?interval=7&format=xml",
url: "/feed/hottest?interval=7",
title: "xLog Hottest of the Week",
},
{
url: "/feed/hottest?interval=30&format=xml",
url: "/feed/hottest?interval=30",
title: "xLog Hottest of the Month",
},
],
"application/feed+json": [
{ url: "/feed/latest", title: "xLog Latest" },
{ url: "/feed/hottest?interval=0", title: "xLog Hottest" },
{ url: "/feed/hottest?interval=1", title: "xLog Hottest of the Day" },
{ url: "/feed/hottest?interval=7", title: "xLog Hottest of the Week" },
{ url: "/feed/latest?format=json", title: "xLog Latest" },
{ url: "/feed/hottest?interval=0&format=json", title: "xLog Hottest" },
{
url: "/feed/hottest?interval=30",
url: "/feed/hottest?interval=1&format=json",
title: "xLog Hottest of the Day",
},
{
url: "/feed/hottest?interval=7&format=json",
title: "xLog Hottest of the Week",
},
{
url: "/feed/hottest?interval=30&format=json",
title: "xLog Hottest of the Month",
},
],

View File

@ -59,9 +59,9 @@ export async function GET(
}
const format =
new URLSearchParams(request.url.split("?")[1]).get("format") === "xml"
? "xml"
: "json"
new URLSearchParams(request.url.split("?")[1]).get("format") === "json"
? "json"
: "xml"
const res = new NextServerResponse()
return res.status(200).rss(data, format)

View File

@ -72,9 +72,9 @@ export async function GET(
}
const format =
new URLSearchParams(request.url.split("?")[1]).get("format") === "xml"
? "xml"
: "json"
new URLSearchParams(request.url.split("?")[1]).get("format") === "json"
? "json"
: "xml"
const res = new NextServerResponse()
return res.status(200).rss(data, format)

View File

@ -53,13 +53,13 @@ export async function generateMetadata({
alternates: {
types: {
"application/rss+xml": [
{ url: "/feed?format=xml", title },
{ url: "/feed/comments?format=xml", title: `Comments on ${title}` },
],
"application/feed+json": [
{ url: "/feed", title },
{ url: "/feed/comments", title: `Comments on ${title}` },
],
"application/feed+json": [
{ url: "/feed?format=json", title },
{ url: "/feed/comments?format=json", title: `Comments on ${title}` },
],
},
},
icons: images,

View File

@ -22,7 +22,7 @@ export function Integration() {
url:
getSiteLink({
subdomain: "xlog",
}) + "/feed?format=xml",
}) + "/feed",
},
{
name: "JSON Feed",

View File

@ -97,7 +97,7 @@ export const SiteHeaderMenu = ({
icon: <RssIcon className="w-full h-full text-[#ee832f]" />,
url: `${getSiteLink({
subdomain: handle || "",
})}/feed?format=xml`,
})}/feed`,
out: true,
},
...(hideSearch

View File

@ -41,10 +41,7 @@ export default async function middleware(req: NextRequest) {
pathname === "/atom.xml" ||
pathname === "/feed/xml"
) {
return NextResponse.redirect(
`https://${req.headers.get("host")}/feed?format=xml`,
301,
)
return NextResponse.redirect(`https://${req.headers.get("host")}/feed`, 301)
}
console.log(`${req.method} ${req.nextUrl.pathname}${req.nextUrl.search}`)