Migrate sitemap to Next.js native app/sitemap.ts (#258)
* sitemap migration to next * robots.txt migration * rss refactoring * claude upd * add test
This commit is contained in:
1 parent
0fd75a3b9a
commit
05f7d4d13d
17 files changed
+214
-161
No files matched your search
@@ -0,0 +1,23 @@
|
||||
import { NextResponse } from "next/server"
|
||||
import { siteUrl } from "@/const"
|
||||
import { getRecentPages } from "@/remote/api"
|
||||
|
||||
export async function GET() {
|
||||
const pages = await getRecentPages()
|
||||
|
||||
const feed = {
|
||||
version: "https://jsonfeed.org/version/1.1",
|
||||
title: "Шлиссельбургская ДХШ",
|
||||
home_page_url: siteUrl,
|
||||
feed_url: `${siteUrl}/feed.json`,
|
||||
items: pages.map((page) => ({
|
||||
id: `${siteUrl}${page.url}`,
|
||||
url: `${siteUrl}${page.url}`,
|
||||
title: page.title,
|
||||
date_published: new Date(page.date).toISOString(),
|
||||
summary: page.excerpt,
|
||||
})),
|
||||
}
|
||||
|
||||
return NextResponse.json(feed)
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
import type { MetadataRoute } from "next"
|
||||
import { siteUrl } from "@/const"
|
||||
|
||||
export default function robots(): MetadataRoute.Robots {
|
||||
return {
|
||||
rules: {
|
||||
userAgent: "*",
|
||||
allow: "/",
|
||||
},
|
||||
host: siteUrl,
|
||||
sitemap: `${siteUrl}/sitemap.xml`,
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
import type { MetadataRoute } from "next"
|
||||
import { siteUrl } from "@/const"
|
||||
import { getUrls } from "@/remote/api"
|
||||
|
||||
export default async function sitemap(): Promise<MetadataRoute.Sitemap> {
|
||||
const urls = await getUrls()
|
||||
|
||||
const staticPages: MetadataRoute.Sitemap = [
|
||||
{
|
||||
url: siteUrl,
|
||||
changeFrequency: "daily",
|
||||
},
|
||||
{
|
||||
url: `${siteUrl}/collective`,
|
||||
changeFrequency: "daily",
|
||||
},
|
||||
]
|
||||
|
||||
const dynamicPages: MetadataRoute.Sitemap = urls.map((path) => ({
|
||||
url: `${siteUrl}${path}`,
|
||||
changeFrequency: "daily",
|
||||
}))
|
||||
|
||||
return [...staticPages, ...dynamicPages]
|
||||
}
|
||||
Reference in new issue
Block a user