Sitexml is broken

Hi,

I did go over older posts, for some reason I can’t get the sitemap.xml to work on my page: https://ploomber.io/sitemap.xml

I did configure the baseUrl as https://ploomber.io/

For some reason it still takes the base as /

Well. Sample repo. What you have BEFORE hugo does use it to create a website.

I would have a look into the configuration. If you use a configuration directory you might have _default vs production issues. If you use TOML configuration you might configure your baseUrl at the wrong place and it’s not actually in the root config. If you are using a theme that theme might override the sitemap template. If… if… without seeing what you are doing the whole “it’s not working” becomes a comedy skit :slight_smile:

1 Like

Good point and thanks for the quick response, here’s my config.toml, sits within a _default folder :


######################## default configuration ####################
baseURL = "https://ploomber.io/"
title = "Ploomber - Build data pipelines. FAST.⚡️"
theme = "andromeda-light"
# post pagination
paginate = "6"
# post excerpt
summaryLength = "10"
# google analytics
googleAnalytics = "G-3EBJ127JJP" # example: UA-123-45, for more info, read the article https://support.google.com/analytics/answer/1008080?hl=en
# disqus short name
disqusShortname = "ploomber" # get your shortname form here : https://disqus.com

############################# Modules ##############################
[module]
[module.hugoVersion]
extended = true
min = "0.83.1"

############################# Outputs ##############################
[outputs]
home = ["HTML", "RSS", "WebAppManifest"]

[imaging]
quality = 90

[caches]
[caches.images]
dir = ":resourceDir/_gen"
maxAge = "720h"

[caches.assets]
dir = ":resourceDir/_gen"
maxAge = "720h"

[markup]
[markup.goldmark.renderer]
[markup.tableOfContents]
    endLevel = 3
    ordered = false
    startLevel = 1
unsafe= true

[mediaTypes]
[mediaTypes."application/manifest+json"]
suffixes = ["webmanifest"]

[mediaTypes."text/netlify"]
delimiter = ""
suffixes = [""]

[outputFormats]
[outputFormats.WebAppManifest]
mediaType = "application/manifest+json"
rel = "manifest"

[sitemap]
filename = "sitemap.xml"
priority = 0.5

I’ve been using this template: https://github.com/gethugothemes/andromeda-light

I’ve also tried just adding a custom template rn at default/sitemap.xml but it doesn’t seem to change anything:


{{ printf "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\" ?>" | safeHTML }}
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
  xmlns:xhtml="http://www.w3.org/1999/xhtml">
  {{ range .Data.Pages }}
  {{ if not (or (hasPrefix .RelPermalink "/tags") (hasPrefix .RelPermalink "/categories")) }}
  <url>
    <loc>{{ .Permalink }}</loc>{{ if not .Lastmod.IsZero }}
    <lastmod>{{ safeHTML ( .Lastmod.Format "2006-01-02T15:04:05-07:00" ) }}</lastmod>{{ end }}{{ with .Sitemap.ChangeFreq }}
    <changefreq>{{ . }}</changefreq>{{ end }}{{ if ge .Sitemap.Priority 0.0 }}
    <priority>{{ .Sitemap.Priority }}</priority>{{ end }}{{ if .IsTranslated }}{{ range .Translations }}
    <xhtml:link
                rel="alternate"
                hreflang="{{ .Lang }}"
                href="{{ .Permalink }}"
                />{{ end }}
    <xhtml:link
                rel="alternate"
                hreflang="{{ .Lang }}"
                href="{{ .Permalink }}"
                />{{ end }}
  </url>
  {{ end }}
  {{ end }}
</urlset>

That part looks like it will only use the path from your site root. If you have baseURL set you add canonifyURLs=true in the next line of your config and Hugo should add the full domain path.

Sidenote: Code in markdown (here in the discourse): use three backticks before code (```) then new line, then paste your code and end the whole thing with three more backticks. Then it becomes readable.

Thanks, I’ve added it but still no change.
What’s weirder is that locally I think it includes the whole url:

<url>
<loc>http://localhost:1313/blog/</loc>
<lastmod>2022-01-26T20:02:29-06:00</lastmod>
<priority>0.5</priority>
</url>

But in the website itself it doesn’t:

<url>
<loc>/blog/</loc>
<lastmod>2022-01-26T20:02:29-06:00</lastmod>
<priority>0.5</priority>
</url>

Do I have to use the xml template?

Also, I have this piece in the netlify.toml config:

[build.environment]
  HUGO_VERSION = "0.85.0"
  HUGO_BASEURL = "/"

well :wink: your HUGO_BASEURL does clearly state what you want there :wink: Give it a full domain name.

As to localhost:1313 - Hugo does that independent from your configuration on running hugo server.

Run locally (not with Netlify) hugo and see if the sitemap has full URLs. If so, it’s the HUGO_BASEURL env.

This was it! Thank you for jumping right in, much appreciated!!