Written by: Geoffrey Callaghan
How to add a Static Page to Hugo
How To Add A Static Page To Hugo
Adding a static page to a Hugo site is straightforward and involves creating a new markdown file in the appropriate directory and optionally customizing it with front matter and content. Here’s a step-by-step guide:
If you haven’t already set up a Hugo site, you can create one by running:
hugo new site my-hugo-site
cd my-hugo-site
Choose and install a theme for your site. For example, to install the Ananke theme:
git init
git submodule add https://github.com/theNewDynamic/gohugo-theme-ananke.git themes/ananke
echo 'theme = "ananke"' >> config.toml
Create a new static page using the hugo new
command. For example, to create an about
page:
hugo new about.md
This command creates a new markdown file in the content
directory:
content/about.md
Open the newly created about.md
file in a text editor. It will contain some default front matter. Add your content below the front matter:
---
title: "About"
date: 2024-05-25T14:15:22Z
draft: true
---
Welcome to the About page of my Hugo site! Here you can find more information about me and my work.
Change the draft
status to false
to publish the page:
---
title: "About"
date: 2024-05-25T14:15:22Z
draft: false
---
Welcome to the About page of my Hugo site! Here you can find more information about me and my work.
To add a link to this page in your site’s navigation menu, you can edit the config.toml
file:
[[menu.main]]
identifier = "about"
name = "About"
url = "/about/"
weight = 2
Run the Hugo server to see your changes live:
hugo server
Open your browser and navigate to http://localhost:1313/about/
to view the new page.
Once you are satisfied with your new page, build the site and deploy it:
hugo
The generated static site will be in the public
directory, ready to be deployed to a web server or a hosting service like Netlify or GitHub Pages.
hugo new about.md
to create a new page.draft
to false
.hugo server
to preview the changes.hugo
and deploy the public
directory.By following these steps, you can easily add and manage static pages in your Hugo sit.