Skip to content

Spaces (roles)

Build public manuals, enterprise editions, and internal specifications from one Hugo project using native roles, scoped navigation, and output confinement.

Hugo roles add a third dimension beside languages and versions. In OINK, each role acts as an audience space — for example, a public documentation site alongside an internal /spec/ manual or an /enterprise/ edition built from the same repository.

Access control belongs to your server or CDN

Hugo builds static files. listed: false hides the space from public space menus. Search indexes are scoped by role. index: false empties the role’s sitemap and asks crawlers to skip its pages. Enforce authentication for /<role>/* at the reverse proxy or CDN.

Asymmetric spaces in one project

Different spaces rarely share the exact same languages and versions. A public manual might publish English and Chinese across v4.2 and v4.1, while an internal spec space is written in Chinese only on v4.2. The default role keeps its configured sites, including data-driven Landing pages. For other roles, OINK uses the published content to determine the available languages and versions, their defaults, and the entry page.

hugo.yml
defaultContentLanguage: en
defaultContentVersion: v4.2
defaultContentRole: public

languages:
  en: { label: English, weight: 1 }
  zh: { label: 中文, weight: 2 }

versions:
  v4.2: { weight: 1 }
  v4.1: { weight: 2 }

roles:
  public: { weight: 1 }
  spec: { weight: 2 }

module:
  imports:
    - path: github.com/pgsty/oink
  mounts:
    - source: manual/v4.2
      target: content
      sites: { matrix: { roles: [public], versions: [v4.2] } }
    - source: manual/v4.1
      target: content
      sites: { matrix: { roles: [public], versions: [v4.1] } }
    - source: spec
      target: content
      sites: { matrix: { roles: [spec], versions: [v4.2], languages: [zh] } }

# Optional: skip generating unused empty matrix combinations in spec
cascade:
  - build: { list: never, render: never }
    target:
      kind: '{page,section,taxonomy,term}'
      sites: { matrix: { roles: [spec], versions: [v4.2], languages: ['**', '! zh'] } }
  - build: { list: never, render: never }
    target:
      sites: { matrix: { roles: [spec], versions: ['**', '! v4.2'] } }

params:
  offline_search: true
  ui:
    role_menu: Space
    roles:
      public:
        label: Docs
        icon: fa-solid fa-book
      spec:
        label: Internal Specs
        icon: fa-solid fa-lock
        listed: false
        index: false

On /spec/zh/:

  • No language switcher, version switcher, or archived-version banner renders, because spec has one language and one version.
  • Visiting /spec/ redirects automatically to /spec/zh/.
  • Public pages show no role switcher (only one listed: true space exists), while /spec/zh/ shows the Space compass. Its menu switches back to Docs (C or the Command Palette switch_role action).

Role metadata (params.ui.roles)

Configure per-space presentation under params.ui.roles.<role> (or per language under languages.<lang>.params.ui.roles.<role>):

Key Type Default Description
label string role name Space name in the menu and in the compass’s accessible label
icon string "" Optional Font Awesome class pair, such as fa-solid fa-lock
listed boolean true Include this space in public role switchers and switch_role choices
index boolean true When false, emits <meta name="robots" content="noindex, nofollow"> and an empty <urlset> in sitemap.xml

params.ui.role_menu overrides the localized Space menu title.

Scoped menus, commands, links, and versions

Shared configuration blocks accept an optional roles allowlist evaluated before URL resolution:

  • Main menu (menus.main): set params.roles: [spec] on top-level or child menu items.
  • Command Palette (params.ui.command_palette.commands): set roles: [spec] to expose internal shortcuts only inside spec.
  • Page context links (params.ui.page_context_menu.links): set roles: [public] or roles: [spec].
  • External version archives (params.versions): entries without roles appear automatically on multi-version spaces (or listed: true spaces in single-version builds); set roles explicitly to override, and surrounding "---" dividers are trimmed automatically.
  • Default-role fallback: inside a non-default space such as spec, an ordinary root-relative link like [Install](/docs/install/) that does not exist in spec resolves automatically to the default space (public), preferring the current version and language before falling back to the default space’s default version and language.
  • Explicit space path: [RFC 001](/spec/rfc/001/) resolves inside spec using spec’s own versions and languages.
  • Unlisted leak warning: if a listed: true space links to a listed: false space (in Markdown or an unscoped menu/command/link), the build logs a warning naming the source file or configuration key so internal URLs do not leak by accident.

Confinement of generated files and history

Every prefixed role publishes its local search index (offline-search-index.*.json), llms.txt, navigation.json, and sitemap.xml inside its own /<role>/ directory. Check authored URLs and aliases before deploying. A prefixed unlisted space stores its browsing history under its directory key, such as td-history:/manual/spec/. If the unlisted default space occupies the site root, it and the listed spaces start separate histories. To protect a default space with a directory-based gateway rule, set defaultContentRoleInSubdir: true.

Build environments and the Design example

Use a fresh destination for each deployment. For example, build into hugo --environment production --destination "$(mktemp -d)" and hugo --environment internal --destination "$(mktemp -d)". Deploy only the selected tree. Hugo can leave files from a previous build in a reused directory.

Hugo lets authors override publication paths. In a prefixed role, use a relative front-matter url such as guides/install/. Check the log from the same build before deploying a mixed tree:

output_dir=$(mktemp -d)
build_log=$(mktemp)
hugo --environment internal --destination "$output_dir" >"$build_log" 2>&1 &&
  python3 ../oink/bin/check-version-links.py --public "$output_dir" --build-log "$build_log"

An [oink-role-path] diagnostic identifies the source and misplaced output or alias. Correct it and rebuild into a clean directory. A gateway rule for the role directory covers files physically under that path. Project-owned static files and custom templates also need to publish protected material there.

Chinese working space example

Run make spec in the companion site. Read the Chinese working copy at /spec/ or open its architecture contract at /spec/architecture/. The preview sets defaultContentLanguage: zh and defaultContentVersion: v1.9. Hugo omits both default prefixes. Chinese Docs therefore lives at /docs/ and English Docs at /en/docs/ in this build.

For a new site, declare the role and add this mount to module.mounts. An unqualified manuscript inherits the project’s default language and version. spec/architecture.md therefore publishes at /spec/architecture/.

- source: spec
  target: content
  sites: {matrix: {roles: [spec]}}

The same configuration works with a role named rfc or adr. A role with one published slot has no language or version choices. Hugo uses the project defaults to construct URLs. In an English-default project, a Chinese working copy lives under /<role>/zh/. A language suffix such as .en.md can select another slot even when the mount specifies Chinese. Use a file filter or disable the other slots with cascade to keep one working copy.

The companion site selects the *.zh.md manuscripts in content/docs/design/ and disables the other slots. Its compass opens a menu back to Docs. Search and print cover the working copy. Earlier /spec/zh/ and Design bookmarks forward to each page with its query and fragment. Old Markdown addresses link to the current source. Existing print URLs and feed subscriptions still work. Unmounted English and historical SPEC pages return 404.

Docs offers the v1.9 development manual and the archived v1.8 manual in both languages, the two versions the site declares in hugo.yml. Open /en/docs/start/from-scratch/ and switch versions to read each installation guide. Press V to compare them side by side. Run make spec-check and make spec-browser to verify this configuration.