Skip to main content

Hugo: How to Disable the Sitemap After Generating Your Public Files

··659 words·4 mins· loading · loading ·
SSG Hugo
UmmIt
Author
UmmIt
Loves to write about technology, and cybersecurity related topics :)

Introduction
#

If you’re using Hugo, a popular static site generator, you might be aware that it automatically generates certain files, such as sitemaps, to enhance your website’s functionality and search engine optimization. However, there are cases where you might want to disable the sitemap generation. In this article, we’ll explore how to disable the sitemap in Hugo after generating your public files.

Why Disable the Sitemap?
#

Before we dive into the how, let’s briefly discuss why you might want to disable the sitemap in Hugo:

  1. Customization: You might have specific needs for your website’s sitemap structure that Hugo’s default sitemap generation doesn’t fulfill. In such cases, you can choose to disable Hugo’s sitemap generation and create a custom sitemap yourself.

  2. Reducing Files: If you want to reduce the number of files in your public directory or keep it clean, disabling the sitemap can help accomplish this.

Steps to Disable the Sitemap in Hugo
#

To disable the sitemap in Hugo, follow these steps:

1. Open Your Hugo Configuration File
#

Start by opening your Hugo project’s configuration file. This file is typically named config.toml or config.yaml or hugo.toml this is located in the root directory of your Hugo project.

2. Add disableKinds Configuration
#

Inside your configuration file, locate or add the [outputs] section. Within this section, you can specify which Hugo output types you want to disable. To disable the sitemap, you can use the disableKinds parameter like this:

disableKinds = ["sitemap"]

If you want to disable multiple output types, you can list them within the square brackets. For example, to disable the sitemap, RSS feed, and robots.txt file, you can use the following configuration:

disableKinds = ["sitemap", "RSS", "robotsTXT"]

By adding sitemap, RSS, and robotsTXT to the disableKinds configuration, you have effectively disabled the generation of the sitemap, RSS feed, and the robots.txt file in your Hugo project.

Example for result
#

your result should look like that:

# Example Hugo Configuration File
# -------------------------------

# Basic Site Configuration
baseurl = "yourdomain.com"
title = "My Pages"
theme = "mytheme"

# Disable Output Kinds
disableKinds = ["sitemap", "RSS", "robotsTXT"]

This example demonstrates a simplified Hugo configuration file with some common settings, including the base URL, site title, theme, and the disabling of specific output kinds as discussed earlier in the article. You can customize these settings according to your actual Hugo project’s configuration.

3. Save the Configuration File
#

After adding or modifying the disableKinds configuration, save the changes to your configuration file.

4. Rebuild Your Hugo Site and Verify
#

To apply the changes and disable the sitemap, you need to rebuild your Hugo site. Open your terminal or command prompt, navigate to your Hugo project’s root directory, and run the following command:

hugo --logLevel debug

Hugo will recompile your site with the updated configuration, and the sitemap will no longer be generated in the public directory.

Delete absolutely
#

However, if you find that the sitemap file still exists in the public directory after running the command, you can take additional steps to remove it:

cd public && rm -rfv * && cd .. && hugo --logLevel debug

This one-liner combines the commands to navigate to the public directory, remove its contents, return to the project’s root directory, and rebuild Hugo with debug output in a concise and visually appealing manner.

Conclusion
#

Disabling the sitemap in Hugo is a straightforward process that allows you to have more control over your website’s output. Whether you have specific SEO requirements, customization needs, or simply want to keep your public directory cleaner, Hugo’s flexibility makes it easy to achieve your goals.

See also
#

In order to be added to the search engine completely unknowingly, check out this article:

Search Engine Crawlers: A Guide to custom robots.txt with Disallow or allow Rule

References
#

Related

Super Handy Linux Command Tips That Will Transform Your Terminal Experience
·923 words·5 mins· loading · loading
Linux Terminal
Building the Linux Kernel on your Linux System (systemd-boot): Step-by-Step Guide
··3748 words·18 mins· loading · loading
Linux Kernel
Customizing Your GNOME Desktop: Installing Icon and cursor themes
··982 words·5 mins· loading · loading
GNOME Linux
How to Ensure Your Operating System Stays Infection-Free
·2445 words·12 mins· loading · loading
Lore How Cyber Security
The Ultimate Guide to Pacman Package Manager Commands on Arch Linux
·570 words·3 mins· loading · loading
Arch Linux Pacman Package Manager
Using Different Linux Kernel Versions with systemd-boot and Bootctl
·582 words·3 mins· loading · loading
Linux Bootctl Boot-Loader