blowfish icon indicating copy to clipboard operation
blowfish copied to clipboard

🐛 Sitemaps generate with relative URLs in production

Open joseph-allen opened this issue 2 months ago • 6 comments

Describe the bug Sitemaps only generate links like

<url>
<loc>/tags/personal/</loc>
<lastmod>2024-04-22T00:00:00+00:00</lastmod>
</url>

and do not contain valid links in production, where is this set?

joseph-allen avatar Apr 25 '24 14:04 joseph-allen

You can see mine here https://landoftherisingmonkey.com/sitemap.xml

joseph-allen avatar Apr 25 '24 14:04 joseph-allen

Screenshot 2024-04-25 at 10 55 35 pm

joseph-allen avatar Apr 25 '24 14:04 joseph-allen

I don't think this is a case where you've chosen to generate relative URLs, but perhaps I've not declared the URL in all places I should have?

joseph-allen avatar Apr 26 '24 14:04 joseph-allen

realted to https://github.com/nunocoracao/blowfish/issues/1438

nunocoracao avatar Apr 28 '24 21:04 nunocoracao

In the interrim, I copied the above and placed it in layouts/_default/sitemap.xml generating the static version.

Then I added my domain before each relative path, and that worked for Google.

This still requires manual updating with each change, but will work until automation is done.

Thanks!

joseph-allen avatar Apr 29 '24 04:04 joseph-allen

I found this is happening in my SEO links too. This gave me a hunch that my locally served content was being served in production too. Looking into this, I am using Netlify which by default for a Hugo app simply serves the built public folder.

Re-reading the Hugo docs, I should be running hugo manually to build the production version of public, which I never did.

Despite this, the RSS and sitemaps still use relative URLs.

joseph-allen avatar May 04 '24 10:05 joseph-allen

@joseph-allen just double checking do you have the baseurl defined?

nunocoracao avatar May 13 '24 21:05 nunocoracao

I've just tested this and my sitemaps are being generated correctly I'll assume it's because you haven't set the base url let me know otherwise

nunocoracao avatar May 13 '24 21:05 nunocoracao

In my /config/_default/hugo.toml

I had all along.

theme = "blowfish"
baseURL = "https://landoftherisingmonkey.com/"
defaultContentLanguage = "en"

Running hugo correctly builds in public/sitemap.xml

  <url>
    <loc>https://landoftherisingmonkey.com/posts/</loc>
    <lastmod>2024-05-05T00:00:00+00:00</lastmod>
    <changefreq>daily</changefreq>
    <priority>0.5</priority>
  </url>

Deploying that same public on netlify, clearing cache from my browser I get

<url>
<loc>/posts/</loc>
<lastmod>2024-05-05T00:00:00+00:00</lastmod>
</url>

Looking at Netlify logs, Netlify rebuilds with the hugo command. I think that's enough to show that This may be a Netlify problem specifically. The number of pages built is far lower, with some warnings.

1:15:19 PM: WARN 2024/05/14 05:15:19 found no layout file for "HTML" for kind "home": You should create a template file which matches Hugo Layouts Lookup Rules for this combination.

To fix, I just took out the build step and have to run the hugo command manually before I release. Though that's not ideal.

I searched specifically for Hugo + Netlify issues and found this thread. https://discourse.gohugo.io/t/netlify-is-not-deploying-my-site-correctly-with-hugo/41169/8

I added a netlify.toml with the following:

[build]
 publish = "public"
 command = "hugo --gc --minify"

[context.production.environment]
 HUGO_VERSION = "0.125.0"
 HUGO_ENV = "production"
 HUGO_ENABLEGITINFO = "false"

Which fixed both my sitemap, RSS feed and other issues in production. Thanks @nunocoracao just failing to replicate was enough to single out netlify.

joseph-allen avatar May 14 '24 05:05 joseph-allen