Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

馃悰 Sitemaps generate with relative URLs in production #1438

Closed
joseph-allen opened this issue Apr 25, 2024 · 9 comments
Closed

馃悰 Sitemaps generate with relative URLs in production #1438

joseph-allen opened this issue Apr 25, 2024 · 9 comments
Labels
bug Something isn't working

Comments

@joseph-allen
Copy link

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
Copy link
Author

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

@joseph-allen
Copy link
Author

Screenshot 2024-04-25 at 10 55 35 pm

@joseph-allen
Copy link
Author

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?

@nunocoracao nunocoracao changed the title Sitemaps generate with relative URLs in production 馃悰 Sitemaps generate with relative URLs in production Apr 28, 2024
@nunocoracao nunocoracao added the bug Something isn't working label Apr 28, 2024
@nunocoracao
Copy link
Owner

realted to #1438

@joseph-allen
Copy link
Author

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
Copy link
Author

joseph-allen commented May 4, 2024

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.

@nunocoracao
Copy link
Owner

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

@nunocoracao
Copy link
Owner

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

@joseph-allen
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants