9 Help readers find their way, in their language
Readers rarely arrive at the home page and click down. They come from search, jump between sections, look for one setting, or read in a second language. OINK builds most of the way-finding from what you already wrote, the content tree, the titles and the descriptions, and this chapter adjusts the rest for Acme DB.
Menu entries
The navbar’s Docs dropdown lists the Docs groups. The Starter puts each group there from the group’s own front matter, so add the Operations group from Chapter 3 the same way:
The entry appears under Docs, between Tutorial and Reference, in every
language that has an Operations page; translate only its title in
_index.zh.md. Top-level entries that are not pages, such as a link to a
forum, go under languages.<lang>.menus.main in hugo.yaml; the GitHub
button at the right end of the navbar comes from params.github_repo.
Navigation and menus covers dropdowns, icons
and the footer.
Local search
The Starter turns search on with params.offline_search: true. Hugo writes an
index per language while it builds, and a small engine in the browser searches
it, so no query leaves the site and the preview searches exactly like
production. It matches English with stemming and spelling fallback, code
identifiers, and Chinese typed without spaces. Press / on this
page and search for xref to see it.
A page can teach search the words readers type but the page never uses:
search_keywords usually helps more than a boost: a reader who types “hello
world” now finds a page titled Quick start. search_boost multiplies the
page’s score, and 1.5 lifts it without letting a partial match beat a complete
one.
The command palette and the keyboard
Ctrl with K, or ⌘ with K on a Mac, opens one box for
pages and actions: search, switch language or theme, copy the page as
Markdown, print the section. A query starting with > lists only actions. Add
your own under params.ui.command_palette.commands, the way
ddia.vonng.com offers “Start reading”:
The keyboard reaches everything without the mouse. Twenty-nine single-key shortcuts are on by default and stand aside while you type in a field; these are the ones readers use most:
| Key | Action |
|---|---|
| Q E | Previous and next page, in sidebar order |
| K J | Previous and next heading on the page |
| H | The pages you read recently |
| X | The next language |
| Z | Zen Mode, the article alone |
| ' | All twenty-nine shortcuts |
Press E now to go to Chapter 10, or ' to see the rest. Keyboard navigation explains how to turn shortcuts off for a site, a section or a page.
Backlinks
With params.ui.backlinks: true, which the Starter sets, each page lists the
pages that link to it in the right rail, under “Backlinks”. Hugo works the list
out at build time from your ordinary links, so it needs no new syntax and no
script. A reader who lands on Back up a server from search sees at once that
Quick start and the configuration reference point to it, which tells them
where it sits in the rest of the site.
Settle the languages
The Starter ships English, Chinese and French. Acme DB publishes in English
and Chinese, so remove French: delete its block under languages in
hugo.yaml, then its content and home page data:
What remains in hugo.yaml is one block per language:
label is the language’s own name in the picker, locale goes into
<html lang> and the alternate links search engines read, and weight orders
the languages. The default language has no path prefix and the others live
under their own, /zh/. The theme’s own labels, such as Search, Next and
Backlinks, come in 32 language packs, so a new language needs only your
content. Languages covers right-to-left scripts and
what happens to pages that have no translation yet.
Read two languages side by side
With params.ui.compare: true, also on in the Starter, a page with a
translation gets an Open duo view button beside the page actions: the page
on one side, its translation on the other, scrolling together section by
section. It is the quickest way to review a translation, because a missing
paragraph shows up as a gap. This chapter has a Chinese edition, so press
B to try it, and B again to close it.
Check your work
- The Docs dropdown lists Operations with its icon in both languages.
- Searching for “hello world” finds Quick start first.
- The palette, opened with
\(or by typing>), lists the Quick start command. - Back up a server shows Quick start under Backlinks.
- The language picker offers English and 简体中文 only, and the duo view pairs every translated page.