86 lines
2.2 KiB
TypeScript
86 lines
2.2 KiB
TypeScript
import { api } from "@/api";
|
|
import { IArticle } from "@/types/IArticle";
|
|
import { MetadataRoute } from "next";
|
|
|
|
export default async function sitemap(): Promise<MetadataRoute.Sitemap> {
|
|
const baseUrl = "https://graff.estate";
|
|
|
|
// Статические страницы
|
|
const staticPages: MetadataRoute.Sitemap = [
|
|
{
|
|
url: baseUrl,
|
|
lastModified: new Date(),
|
|
changeFrequency: "monthly",
|
|
priority: 1,
|
|
},
|
|
{
|
|
url: `${baseUrl}/projects`,
|
|
lastModified: new Date(),
|
|
changeFrequency: "monthly",
|
|
priority: 0.8,
|
|
},
|
|
{
|
|
url: `${baseUrl}/prime`,
|
|
lastModified: new Date(),
|
|
changeFrequency: "monthly",
|
|
priority: 0.8,
|
|
},
|
|
{
|
|
url: `${baseUrl}/blog`,
|
|
lastModified: new Date(),
|
|
changeFrequency: "weekly",
|
|
priority: 0.8,
|
|
},
|
|
{
|
|
url: `${baseUrl}/about`,
|
|
lastModified: new Date(),
|
|
changeFrequency: "monthly",
|
|
priority: 0.7,
|
|
},
|
|
{
|
|
url: `${baseUrl}/web`,
|
|
lastModified: new Date(),
|
|
changeFrequency: "monthly",
|
|
priority: 0.7,
|
|
},
|
|
{
|
|
url: `${baseUrl}/stream`,
|
|
lastModified: new Date(),
|
|
changeFrequency: "monthly",
|
|
priority: 0.7,
|
|
},
|
|
{
|
|
url: `${baseUrl}/picture`,
|
|
lastModified: new Date(),
|
|
changeFrequency: "monthly",
|
|
priority: 0.7,
|
|
},
|
|
{
|
|
url: `${baseUrl}/walk`,
|
|
lastModified: new Date(),
|
|
changeFrequency: "monthly",
|
|
priority: 0.7,
|
|
},
|
|
];
|
|
|
|
try {
|
|
// Получаем все статьи блога
|
|
const articles = await api.get("articles").json<IArticle[]>();
|
|
|
|
const blogPages: MetadataRoute.Sitemap = articles
|
|
.filter(({ slug, drafted }) => slug && !drafted)
|
|
.map(({ slug, createdAt }) => ({
|
|
url: `${baseUrl}/blog/${slug}`,
|
|
lastModified: createdAt ? new Date(createdAt) : new Date(),
|
|
changeFrequency: "monthly",
|
|
priority: 0.8,
|
|
}));
|
|
|
|
return [...staticPages.slice(0, 4), ...blogPages, ...staticPages.slice(4)];
|
|
} catch (error) {
|
|
console.error("Error generating sitemap:", error);
|
|
// Возвращаем хотя бы статические страницы, если API недоступен
|
|
return staticPages;
|
|
}
|
|
}
|