Sitemap for Google Search Console
Unanswered
Gazami crab posted this in #help-forum
Gazami crabOP
Hello Everyone,
I generated a sitemap with nextjs by following the steps. It works well. But when I want Google Search Console to fetch the data from my sitemap, it's written "couldn't fetch", it's been more than a month.
Anyone knows what's wrong? I've seen this problem also on Stackoverflow and Github, but nobody was able to solve this issue!
I generated a sitemap with nextjs by following the steps. It works well. But when I want Google Search Console to fetch the data from my sitemap, it's written "couldn't fetch", it's been more than a month.
Anyone knows what's wrong? I've seen this problem also on Stackoverflow and Github, but nobody was able to solve this issue!
20 Replies
Gazami crabOP
SO this is my sitemap. It's inside the app file
import { fetchAllData } from "@/lib/contentful/retrieveData";
export async function getPostData() {
const allPosts = await fetchAllData();
return {
allPosts
};
}
export default async function sitemap() {
const postData = await getPostData();
const website = [
{
url: 'roastmysaas.cc',
lastModified: new Date(),
changeFrequency: 'yearly',
priority: 1,
},
{
url: 'https://roastmysaas.cc/directory',
lastModified: new Date(),
changeFrequency: 'monthly',
priority: 0.8,
}
]
const companiesName = postData.allPosts.map(data => {
return data.fields.companyName
})
const xml = companiesName.map(info => {
return {
url: `https://roastmysaas.cc/directory/${info.toLowerCase()}`,
lastModified: new Date(),
changeFrequency: 'monthly',
priority: 1
}
})
const xmlMerged = [...xml, ...website];
return xmlMerged
}Asian paper wasp
And the generated
sitemap.xml? What does it look like?One thing I can tell is that the
I guess you mean https://roastmysaas.cc/sitemap2.xml ?
robots.txt suggests the sitemap should be https://roastmysaas/sitemap2.xml, which doesn't exist.I guess you mean https://roastmysaas.cc/sitemap2.xml ?
Which URL did you submitted to serarch console?
Gazami crabOP
I iterated multiple times based on what I found on Stackoverflow.
But initially it was the sitemap generated by the code above.
The new one is this code:
But initially it was the sitemap generated by the code above.
The new one is this code:
import { fetchAllData } from "@/lib/contentful/retrieveData";
const URL = 'https://roastmysaas.cc'
export async function getPostData() {
const allPosts = await fetchAllData();
return {
allPosts
};
}
export async function GET() {
const postData = await getPostData();
const companiesName = postData.allPosts.map(data => {
return data.fields.companyName
})
const body = generateSiteMap(companiesName);
return new Response(body, {
status: 200,
headers: {
"Cache-control": "public, s-maxage=86400, stale-while-revalidate",
"content-type": "application/xml",
},
});
}
function generateSiteMap(companiesName) {
return `<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="https://www.sitemaps.org/schemas/sitemap/0.9">
<!--We manually set the two URLs we know already-->
<url>
<loc>${URL}</loc>
<lastmod>${new Date()}</lastmod>
<changefreq>monthly</changefreq>
<priority>1</priority>
</url>
<url>
<loc>${URL}/directory</loc>
</url>
${companiesName
.map((id ) => {
return `
<url>
<loc>${`${URL}/directory/${id.toLowerCase()}`}</loc>
<lastmod>${new Date()}</lastmod>
<changefreq>monthly</changefreq>
<priority>1</priority>
</url>
`;
})
.join("")}
</urlset>
`;
}Gazami crabOP
My current sitemap is:
https://roastmysaas/sitemap2.xml
https://roastmysaas/sitemap2.xml
with the latest code
Asian paper wasp
Note that the domain doesn't have .cc
American Crow
klick that url it doesnt work
Gazami crabOP
ah good catch!
would it solve the issue
?
I dont think this a nextjs issue
Gazami crabOP
ah got it
why does it work correctly when the sitemap is generated through webflow.com for example?
No idea tbh, even my sites dont have their sitemaps working on search console.. but the sites are correctly indexed by just google bot crawling them
American Crow
I have good experience with GSC and sitemaps automatically generated by
https://github.com/iamvishnusankar/next-sitemap?tab=readme-ov-file#generating-dynamicserver-side-sitemaps
be aware though next-sitemap does not integrate with next-auth nor next-intl but if you dont use those i can commend
https://github.com/iamvishnusankar/next-sitemap?tab=readme-ov-file#generating-dynamicserver-side-sitemaps
be aware though next-sitemap does not integrate with next-auth nor next-intl but if you dont use those i can commend