Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add a new hugo static page?

Tags:

hugo

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?

like image 485
AJcodez Avatar asked Feb 17 '15 19:02

AJcodez


People also ask

Is Hugo a static website?

Hugo is one of the most popular open-source static site generators. With its amazing speed and flexibility, Hugo makes building websites fun again.

What is static in Hugo?

Hugo is a static site generator (SSG) written in Go (aka Golang), a high-performance compiled programming language often used for developing backend applications and services. Today, Hugo is capable of generating most websites within seconds (<1 ms per page).

How do you add a Hugo module?

To add a module as a dependency of a site, we have to run the command hugo mod get <module path> . Then add an entry for the module in site configuration (in a config. yaml or config. toml file).

Why Hugo com is a static website?

Hugo takes caching a step further and all HTML files are rendered on your computer. You can review the files locally before copying them to the computer hosting the HTTP server. Since the HTML files aren't generated dynamically, we say that Hugo is a static site generator.


3 Answers

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.

like image 167
revelt Avatar answered Oct 06 '22 03:10

revelt


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.

like image 21
bep Avatar answered Oct 06 '22 03:10

bep


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
like image 31
Balkrishna Avatar answered Oct 06 '22 02:10

Balkrishna