sitemap.ts isnt updating the blog with id
Answered
Black Caiman posted this in #help-forum
Black CaimanOP
recently added new blog in my blogs portion but when i check sitemap.xml it only show build time only? how to fix this ?
import { MetadataRoute } from "next";
import { Blog } from "@/payload-types";
import { PaginatedDocs } from "payload";
import { queryClient } from "@/utils/payloadClient";
export const dynamic = "force-dynamic";
export default async function sitemap(): Promise<MetadataRoute.Sitemap> {
const allBlogs: Blog[] = [];
let currentPage = 1;
const limit = 100;
while (true) {
const response: PaginatedDocs<Blog> = await queryClient((p) =>
p.find({
collection: "blogs",
page: currentPage,
limit,
})
);
const blogs = response.docs;
if (blogs.length === 0) break;
allBlogs.push(...blogs);
currentPage++;
}
allBlogs.forEach((blog) => {
console.log(`Blog Slug: ${blog.slug}, Last Modified: ${blog.updatedAt || blog.createdAt}`);
});
const staticUrls: MetadataRoute.Sitemap = [
{
url: "https://www.pcgalaxyhub.com/",
lastModified: new Date().toISOString(),
changeFrequency: "daily",
},
{
url: "https://www.pcgalaxyhub.com/blogs",
lastModified: new Date().toISOString(),
changeFrequency: "daily",
},
{
url: "https://www.pcgalaxyhub.com/contact",
lastModified: new Date().toISOString(),
changeFrequency: "daily",
},
];
const blogUrls: MetadataRoute.Sitemap = allBlogs.map((blog) => {
if (!blog.slug) {
console.error('Missing slug for blog:', blog);
}
return {
url: `https://www.pcgalaxyhub.com/blogs/${blog.slug}`,
lastModified: new Date(blog.updatedAt || blog.createdAt || new Date()).toISOString(),
changeFrequency: "daily",
};
});
return [...staticUrls, ...blogUrls];
}
Answered by Black Caiman
issue solved found on Reddit !!!
using this
using this
export const dynamic = 'force-dynamic';
export const revalidate = 0;
export const dynamicParams = true;
1 Reply
Black CaimanOP
issue solved found on Reddit !!!
using this
using this
export const dynamic = 'force-dynamic';
export const revalidate = 0;
export const dynamicParams = true;
Answer