3 Write a page and give it a place
Most of an OINK site is pages, and a page is a Markdown file whose path is its
address. You write no navigation: the directory tree becomes the sidebar, the
order of the files becomes the pager, and a file beside it with a .zh.md
suffix becomes the Chinese version. This chapter sets up the sample site and
adds one page to it.
Set up the sample site
-
Clone the Starter and start the preview:
-
Name the site. The first two settings in
hugo.yamlare markedCHANGE ME; the title is a YAML anchor that every language reuses:hugo.yaml -
Open http://localhost:1313/docs/. The Starter’s Docs section has four groups in the sidebar: Introduction, Get Started, Tutorial and Reference. The navbar now reads Acme DB.
Write the page
Create the Quick start page inside Get Started, with this complete content:
Save it and look at the preview. Quick start appears in the sidebar under Installation, the pager at the bottom of Installation now leads to it, and the outline on the right lists its three sections.
Each front matter key has one job:
titleis the page heading, the browser tab and the search result title. AddlinkTitlewhen the sidebar needs a shorter name.descriptionis one sentence about what the reader can do with the page. It appears on section cards, in search results and on social cards, so it decides whether someone opens the page.weightorders the page among its siblings. The Starter’s Requirements and Installation use 10 and 20, so 30 places Quick start after them, and steps of ten leave room for a page in between later.
Start the body with a sentence that says what the page achieves, not with a
heading. The theme renders title as the page’s only # heading, so body
sections start at ##.
Headings that last
Every heading in Example 3-1 carries an
explicit ID, such as {#start}. Without one, Hugo derives the ID from the
heading text, so rewording “Start the server” breaks every link to it, and the
Chinese heading would get a different ID from the English one. With the ID
written out, /docs/get-started/quick-start/#start keeps working through
rewrites and in both languages.
Link to other pages with their absolute site path, as the lead paragraph does
with /docs/get-started/installation/. The path names the published address,
survives moving the source file and is easy to find with a site-wide search.
Hugo does not check plain Markdown links, so when you move a page, add its old
path to aliases in its front matter and the old address keeps working:
Let the tree be the navigation
A directory with an _index.md becomes a group in the sidebar, and its
_index.md is the group’s own page. Add an Operations group with one page in
it:
Files added in this step
content/docs/
operations/
- _index.mdthe group: title, description, weight 35, an icon
- backup.mdits first page
Weight 35 places the group after the Tutorial group (30) and before Reference
(40). Its icon
shows because the Starter sets sidebar_icon_policy: groups, which gives icons
to groups and keeps leaf pages plain. The group’s page lists its children as
cards, because the Starter sets section_index: cards; the cards take their
text from each child’s description, which is one more reason to write it well.
Two front matter keys move a page out of the way without deleting it.
toc_hide: true keeps a published page out of the sidebar and the pager, and
draft: true keeps it out of the build until it is ready; preview drafts with
hugo server -D.
Add the Chinese peer
The Starter already has Chinese and French, so a translation is one more file beside the English one, with the same name and a language suffix:
The two files share the weight and every heading ID, and only the prose
changes; commands and code stay byte for byte the same. Open the English page
and switch to 简体中文 from the navbar: you land on /zh/docs/get-started/quick-start/,
and a link to #write lands on the same section in either language.
Chapter 9 covers adding and removing languages.
Check your work
With the preview open, you should see:
- Quick start in the sidebar after Installation, with the pager leading from one to the other;
- an Operations group with an icon between Tutorial and Reference, and a card for Back up a server on its page;
- the language switch on Quick start opening the Chinese page at the same section;
http://localhost:1313/docs/get-started/quick-start/index.mdreturning the page as plain Markdown.