Sitemap

This is a Hugo theme component with layouts to add a configurable sitemap to your website. Hugo itself has internal templates that add sitemaps, but this component has additional setup options per page.

Add this module
[[module.imports]]
path = "github.com/davidsneighbour/hugo-sitemap"
disable = false
ignoreConfig = false
ignoreImports = false
Latest Version v1.0.1 (2022-08-10)
Fix to this version
hugo mod get github.com/davidsneighbour/[email protected]

Installing

Step 1: enable modules in your own repository:

1hugo mod init github.com/username/reponame

Then add this module to your required modules in config.toml.

1[module]
2[[module.imports]]
3path = "github.com/davidsneighbour/hugo-sitemap"

The next time you run hugo it will download the latest version of the module.

Updating

1hugo mod get -u github.com/davidsneighbour/hugo-sitemap
2hugo mod get -u # update all modules

Usage

There is no need to configure anything without having any special needs. Add the module to your repository structure and run it. Once you ran hugo you will find a file sitemap.xml in your public directory. This is the file you want to submit to search engines.

If you are using the Robots component, then your resulting robots.txt will have a pointer to the sitemap file as well.

Exclude page from sitemap

Add frontmatter to individual pages with the following setup:

1config:
2  sitemap: true

sitemap (boolean): include this page in the sitemap

Add/edit global defaults in config.toml > params or config/_defaults/params.toml:

1[dnb.sitemap]
2enabled = true

Without any configuration the default is true, meaning to include any page into the sitemap.

DEPRECATED: Frontmatter robotsdisallow from earlier hugo-robots versions did result in the page being ommited from the sitemap. This is deprecated, but currently still supported. The module will echo a note on CLI about this.

HTML Sitemap

If you want to add an HTML sitemap you can do so via shortcode:

1{{< sitemap >}}

This sitemap requires additional configuration via config.toml > params or config/_defaults/params.toml, have a look at this following sample:

 1[[dnb.sitemap.htmlmap.item]]
 2type = ".Type"
 3section = "blog"
 4label = "Blog Posts"
 5
 6[[dnb.sitemap.htmlmap.item]]
 7type = ".Type"
 8section = "components"
 9label = "GoHugo Components by DNB"
10
11[[dnb.sitemap.htmlmap.item]]
12type = ".Type"
13section = "tags"
14selection = "in-pages"
15label = "Tags"
16
17[[dnb.sitemap.htmlmap.item]]
18type = ".Type"
19selection = "not-in"
20section = ["blog", "tags", "components"]
21label = "Other pages"

Each item of the htmlmap needs the following parameters:

  • type - for the “where type in something” enquiry
  • selection - in-regular, in-pages, not-in
  • section - string or slice that defines the section to load into the page object
  • label - headline label for the overview of the object, defaults to titled section string