How to add a new hugo static page?
Asked Answered
P

5

44

From the "getting started" section it seems this should work, but it doesn't.

hugo new site my-site
hugo new privacy.md
hugo server --watch --includeDrafts

curl -L localhost:1313/privacy/index.html
# 404 page not found
curl -L localhost:1313/privacy.html
# 404 page not found
curl -L localhost:1313/privacy/
# 404 page not found

How can I add a new page?

Profiteer answered 17/2, 2015 at 19:22 Comment(1)
From what I understand: create it like any other post with the exception that it it should be in the content directory. i.e. don't put it inside the content/posts directoryCristincristina
R
24

Just tested OK with this on Hugo 0.13:

hugo new site my-site
cd my-site
hugo new privacy.md
hugo server -w -D
curl -L localhost:1313/privacy/

Note: You have to either use a theme or provide your own layout template to get something more than a blank page. And of course, some Markdown in privacy.md would also make it even nicer.

See http://gohugo.io/overview/introduction for up-to-date documentation.

Roseroseann answered 5/3, 2015 at 15:11 Comment(6)
Why do you need the -w -d?Pernod
With hugo 0.69.0, that's not working any longer for me. % curl -L localhost:1313/privacy/: 404 page not foundPseudohermaphrodite
Make sure to set draft: 'false' for the page to show upDaiseydaisi
If you're seeing a 404 page not found make sure you set type: page and have a single.html layout as explained in this post: #46216833Ascham
@Daiseydaisi you don't need to set draft: false if you use the -D flag on the hugo server, as this enables rendering of drafts as well I believeBarbule
Do you have to use hugo new? What if I already have a file? Do I really have to move it out of the way to use hugo new and then move it back?Rosenthal
M
46

This is the best tutorial how to create static "landing pages" on Hugo: https://discuss.gohugo.io/t/creating-static-content-that-uses-partials/265/19?u=royston

Basically, you create .md in /content/ with type: "page" in front matter, then create custom layout for it, for example layout: "simple-static" in front matter, then create the layout template in themes/<name>/layouts/page/, for example, simple-static.html. Then, use all partials as usual, and call content from original .md file using {{ .Content }}.

All my static (landing) pages are using this method.

By the way, I'm not using hugo new, I just clone .md file or copy a template into /content/ and open it using my iA Writer text editor. But I'm not using Hugo server either, adapted npm-build-boilerplate is running the server and builds.

Martella answered 29/5, 2016 at 21:10 Comment(3)
imo the process is bit complicated. But thanks u showed a direction ! =)Outrigger
This should have been the right answer and also aligns with the documentation of Hugo as on 2020.Kristopher
THIS WORKS, I just checked. I spent a shameful amount of time on this.Willard
R
24

Just tested OK with this on Hugo 0.13:

hugo new site my-site
cd my-site
hugo new privacy.md
hugo server -w -D
curl -L localhost:1313/privacy/

Note: You have to either use a theme or provide your own layout template to get something more than a blank page. And of course, some Markdown in privacy.md would also make it even nicer.

See http://gohugo.io/overview/introduction for up-to-date documentation.

Roseroseann answered 5/3, 2015 at 15:11 Comment(6)
Why do you need the -w -d?Pernod
With hugo 0.69.0, that's not working any longer for me. % curl -L localhost:1313/privacy/: 404 page not foundPseudohermaphrodite
Make sure to set draft: 'false' for the page to show upDaiseydaisi
If you're seeing a 404 page not found make sure you set type: page and have a single.html layout as explained in this post: #46216833Ascham
@Daiseydaisi you don't need to set draft: false if you use the -D flag on the hugo server, as this enables rendering of drafts as well I believeBarbule
Do you have to use hugo new? What if I already have a file? Do I really have to move it out of the way to use hugo new and then move it back?Rosenthal
S
14

I had a similar requirement, to add static page (aboutus in this case). Following steps did the trick,

  • Created an empty file content/aboutus/_index.md
  • Created aboutus.html page layouts/section/aboutus.html
Spiral answered 28/12, 2018 at 19:50 Comment(0)
T
4

Make you have some default frontmatter set in archetypes/default.md

# archetypes/default.md
+++
title: "{{ replace .Name "-" " " | title }}"
date: {{ .Date }}
draft: true
+++

And the single layout in layouts/_default/single.html to render some variable or content

# tags to render markdown content
<h1>{{ .Title }}</h1>
<p>{{ .Content }}</p>
<span>{{ .Params.date }}</span>

Now type hugo new privacy.md which will create a new page on the following directory in content/privacy.md

Treasonous answered 21/8, 2020 at 7:52 Comment(0)
E
3

Take "About" as example:

# will create content/about.md
hugo new about.md

Edit about.md and add the last 2 lines, the metadata/front matter looks like:

title: "About"
date: 2019-03-26
menu: "main"
weight: 50

That should work.

Elysia answered 26/3, 2019 at 7:16 Comment(2)
This got the link in menu. But I could see it as post as well in home page. Any way to remove that?Zigzagger
Do you have to use hugo new? What if I already have a file? Do I really have to move it out of the way to use hugo new and then move it back?Rosenthal

© 2022 - 2025 — McMap. All rights reserved.