Mystery resolved: Hugo sitemap.xml rendering localhost instead of domain name

hugo template

Mystery resolved: Hugo sitemap.xml rendering localhost instead of domain name

Started playing around with Hugo over the weekend. It is really a super fast and well implemented rendering engine. When I deploy the website to the production environment and submit the sitemap to Google Search console, I get the following error:

After checking the various locations, I realized that I will have to be very careful before I deploy the project to the production environment.

The culprit:

If you are used to developing the website using the command :

 Hugo server

it will always generate the following sitemap.xml and overrides that in the public folder:

<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
  xmlns:xhtml="http://www.w3.org/1999/xhtml">
  <url>
    <loc>http://localhost:1313/tags/cardiovascular/</loc>
    <lastmod>2024-03-06T06:36:09+08:00</lastmod>
  </url><url>
    <loc>http://localhost:1313/english/</loc>
    <lastmod>2024-03-06T06:36:09+08:00</lastmod>
  </url><url>
    <loc>http://localhost:1313/</loc>
    <lastmod>2024-03-06T06:36:09+08:00</lastmod>
  </url><url>
    <loc>http://localhost:1313/tags/heart/</loc>
    <lastmod>2024-03-06T06:36:09+08:00</lastmod>
  </url><url>
    <loc>http://localhost:1313/tags/heartbeat/</loc>
    <lastmod>2024-03-06T06:36:09+08:00</lastmod>
 </url>
</urlset>

Resolution:

As part of the CICD or your own deployment process, always run the Hugo command to rebuild for production purpose.

Leave a Reply

Back To Top