HTML sitemap

How can I create a HTML sitemap for my websites?

Did you have a look at the documentation?

Yes, but that’s for XML sitemaps, right?

Do you want a recursive sitemap? So 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>

I just want a page that lists all pages on my website. No sections.

Something like this:

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

But where do I need to place the code and how can I make it to work on /sitemap/ (e.g., https:///www.example.com/sitemap/)?

Create a shortcode with your code layout/shortcodes/sitemap.html (I modified the code):

<ul>
{{ range site.RegularPages }}
<li><a href="{{ .RelPermalink }}">{{ .Title }}</a></li>
{{ end }}
</ul>

Then create your sitemap page content/sitemap.md and insert the shortcode:

+++
title = "Sitemap"
+++

All the pages of my great site:

{{< sitemap >}}

And the text continues ;)
1 Like

Doesn’t work

Try again with my corrections. I wrote partials instead of shortcodes in the first line.

1 Like

Thank you. It works.

1 Like

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