Fix the sitemap indexes
This commit is contained in:
@@ -21,9 +21,28 @@ export const GET = (async () => {
|
|||||||
let sitemaps: SitemapIndex[] = [];
|
let sitemaps: SitemapIndex[] = [];
|
||||||
|
|
||||||
for (let i = 0; i < pages; i++) {
|
for (let i = 0; i < pages; i++) {
|
||||||
|
const selectedBlogs = blogs.slice(
|
||||||
|
((Number(i + 1) - 1) * settings.sitemap.perPage),
|
||||||
|
Number(i + 1) * settings.sitemap.perPage - 1
|
||||||
|
);
|
||||||
|
|
||||||
|
let dates = [
|
||||||
|
settings.sitemap.lastModified,
|
||||||
|
settings.blog.lastModified,
|
||||||
|
settings.website.lastModified
|
||||||
|
];
|
||||||
|
|
||||||
|
selectedBlogs.forEach((blog) => {
|
||||||
|
dates.push(blog.lastModified);
|
||||||
|
});
|
||||||
|
|
||||||
|
const lastModified = dates.sort((a: Date, b: Date) => {
|
||||||
|
return b.getTime() - a.getTime();
|
||||||
|
});
|
||||||
|
|
||||||
sitemaps.push({
|
sitemaps.push({
|
||||||
url: `/sitemap/blogs-${i + 1}.xml`,
|
url: `/sitemap/blogs-${i + 1}.xml`,
|
||||||
lastModified: new Date()
|
lastModified: lastModified[0]
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import { getAllBlogs } from "@/content/blogs/blogs";
|
||||||
import { getSettings } from "@/content/settings/settings";
|
import { getSettings } from "@/content/settings/settings";
|
||||||
import type { APIRoute } from "astro";
|
import type { APIRoute } from "astro";
|
||||||
import minifyXML from "minify-xml";
|
import minifyXML from "minify-xml";
|
||||||
@@ -13,9 +14,25 @@ export const GET = (async () => {
|
|||||||
];
|
];
|
||||||
|
|
||||||
if (settings.blog.enabled) {
|
if (settings.blog.enabled) {
|
||||||
|
const blogLastModifieds = [
|
||||||
|
settings.blog.lastModified,
|
||||||
|
settings.sitemap.lastModified,
|
||||||
|
settings.website.lastModified
|
||||||
|
];
|
||||||
|
|
||||||
|
let blogs = await getAllBlogs(settings);
|
||||||
|
|
||||||
|
blogs.forEach((blog) => {
|
||||||
|
blogLastModifieds.push(blog.lastModified);
|
||||||
|
});
|
||||||
|
|
||||||
|
const lastModifiedBlogs = blogLastModifieds.sort((a: Date, b: Date) => {
|
||||||
|
return b.getTime() - a.getTime();
|
||||||
|
});
|
||||||
|
|
||||||
sitemapIndex.push({
|
sitemapIndex.push({
|
||||||
url: "/sitemap/blogs.xml",
|
url: "/sitemap/blogs.xml",
|
||||||
lastModified: new Date()
|
lastModified: lastModifiedBlogs[0]
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
if (settings.project.enabled) {
|
if (settings.project.enabled) {
|
||||||
|
|||||||
Reference in New Issue
Block a user