Get-me-started sitemap

I have read all I can find on creating a sitemap, but it seems to assume something I do not know!
I am using the Wowchemy Academic theme and have created a multi-lingual site. I just want to add a sitemap.
I have created a menu-item in menus.toml:

> [[main]]
>   name = "Site-Map"
>   url = "sitemap.xml"
>   weight = 100

When selecting this menu on the site I get:

This XML file does not appear to have any style information associated with it. The document tree is shown below.

<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">

<sitemap>

<loc>http://localhost:1313/en/sitemap.xml</loc>

</sitemap>

<sitemap>

<loc>http://localhost:1313/fr/sitemap.xml</loc>

</sitemap>

</sitemapindex>

Do I need to create a markup file or something?

There are two kinds of sitemaps:

  1. A webpage for a person to see navigation for the entire website, or
  2. The Sitemaps protocol (Sitemaps - Wikipedia), which is XML-based and used by search engines (and other non-human applications)

Hugo comes with a sitemap.xml template that basically works out of the box, you can read about it at Sitemap Template | Hugo. That template covers the second scenario, the protocol.

If you’d like to create a human-readable version (the first scenario above), then you’d create a page with a template that listed all or a sub-section of the pages on your site. :slight_smile:

OK. So I’ve created a page-type “site-map” using the template “sitemap.html”.
This is what I have in the template:

<h1>{{ .Title }}</h1>
<aside class="related layout__related">
{{ range site.RegularPages.GroupBy "Section" }}
	<h3> {{ .Key }} </h3>
	<ul>
		{{ range .Pages }}
			{{ $depth := strings.Count "/" .RelPermalink }}
			{{ $indent := strings.Repeat (mul $depth 4) "." }}
			<li><a href="{{ .RelPermalink }}">{{ $indent }}{{ .Title }}</a></li>
		{{ end }}
	</ul>
{{ end }}
</aside>

It shows all the content, but not grouped by the directory each page is in.
How would I get it to group by the directories?

Something like:


{{ define "souspages" }}
{{ if .Pages }}
<ul>
    {{ range .Pages}}
    <li><a href="{{ .Permalink }}">{{ .Title }}</a>
        {{ template "souspages" . }}
    </li>
    {{ end }}
</ul>
{{ end }}
{{ end }}

<ul>
{{ range .Site.Sections }}
    <li><a href="{{ .Permalink }}">{{ .Title }}</a>
        {{ template "souspages" . }}</li>
{{ end }}
</ul>

souspages is subpages in French.

1 Like

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.