Member-only story

Generating a sitemap for a static site

Bobby Jack
5 min readSep 30, 2020

--

Photo by Nik Shuliahin on Unsplash

I’ve previously written about the benefits of static sites and how to layer dynamic functionality on top of them. In this article I want to introduce a simple technique for adding a sitemap to your static site.

A sitemap file can be used by search engines, or any other software, to find out about the pages available on your site. It’s essentially a machine-readable index which lives on your site alongside your content. The XML-based sitemap protocol is very straightforward and an excellent starting point for those looking to evolve their knowledge beyond plain HTML.

The sitemap contains a list of URLs with some additional, optional information. You can experiment with the data you wish to include, but in this example, I’ll be including the following:

  • loc: this is required, and it’s simply the URL itself.
  • lastmod: this is the last modification date of the file; i.e. when the page was last updated. It can include the time if you want, but I’ll just focus on the date here.
  • changefreq: the ‘change frequency’ i.e. how often the content typically changes. This can vary wildly between your home page and a one-off article.

In theory, you can update your sitemap file manually, in a text editor, just as you might edit your HTML files. This is perfectly feasible for a small, rarely updated site, but automating the task gives you one less thing to worry about.

The aim

Once we’re done, we should have a simple script that we can run to generate a sitemap file for our collection of static pages. The script can be run on-demand, or via an automated process, depending on your personal setup.

The setup

Every site — even a simple collection of HTML files — is unique, with different requirements, and different standards. In this article, I will use my own site as a reference, and highlight aspects that might vary in your specific case.

Localhost

I edit my content on my own Mac laptop before uploading it to a server. It’s easy to use any available text editor to do so, and I have a…

--

--

Bobby Jack
Bobby Jack

Written by Bobby Jack

Bobby has worked as a writer and editor for publications including tech site makeuseof.com and gaming magazine Switch Player. More @ bobbyjack.me

No responses yet

Write a response