#Sitemap for Google Search Console

22 messages · Page 1 of 1 (latest)

gentle stratus
#

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!

inner heraldBOT
#

🔎 This post has been indexed in our web forum and will be seen by search engines so other users can find it outside Discord

🕵️ Your user profile is private by default and won't be visible to users outside Discord, if you want to be visible in the web forum you can add the "Public Profile" role in id:customize

✅ You can mark a message as the answer for your post with Right click -> Apps -> Mark Solution
(if you don't see the option, try refreshing Discord with Ctrl + R)

worldly elkBOT
# gentle stratus Hello Everyone, I generated a sitemap with nextjs by following the steps. It w...
Please add more information to your question

Your question currently does not have sufficient information for people to be able to help. Please add more information to help us help you, for example: relevant code snippets, a reproduction repository, and/or more detailed error messages. See more info on how to ask a good question in https://discord.com/channels/752553802359505017/1138338531983491154 and #welcome message

gentle stratus
#

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
  }```
lilac drum
#

And the generated sitemap.xml? What does it look like?

#

Which URL did you submitted to serarch console?

gentle stratus
#

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:

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>
 `;
}```
safe sierra
gentle stratus
#

with the latest code

lilac drum
#

Note that the domain doesn't have .cc

safe sierra
#

klick that url it doesnt work

gentle stratus
#

ah good catch!

#

would it solve the issue

#

?

gentle stratus
#

ah got it

#

why does it work correctly when the sitemap is generated through webflow.com for example?

river flower
#

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