Skip to content

Add docs to a project

Add a self-contained OINK documentation site inside an existing open-source repository’s docs/ directory, keep build outputs out of Git, and wire GitHub Pages and Cloudflare Pages auto-builds.

You already have an open-source repository with application code—a Go service, a Rust CLI, a Python package, or a database extension—and you want real documentation to live right beside the code so pull requests update code and docs together. Putting a self-contained OINK site inside docs/ keeps Hugo isolated from your main build while publishing cleanly on every push.

For a real production example of this layout, see AGW, which hosts its bilingual documentation and landing page inside a subfolder of its application repository.

Repository layout

Keep the Hugo configuration, module pin, and content completely inside docs/:

my-project/

  • my-project/
    • cmd/your project's own source code
    • internal/
    • go.modyour project's own Go module (if it is a Go project)
    • README.md
    • .gitignoreexcludes docs/ build outputs without hiding app files
    • .github/
      • workflows/
        • ci.yamlexisting application tests
        • docs.yamlbuilds and deploys docs/ only when docs/ changes
    • docs/self-contained OINK sub-project
      • hugo.ymlsite config with github_subdir: docs
      • go.modpins github.com/pgsty/oink@vX.Y.Z
      • go.sumverifies the pinned OINK release
      • content/
        • _index.md
        • docs/
          • _index.md
          • install.md
      • data/
        • home/
          • en.yaml
      • assets/
        • icons/logo.svg
      • static/
        • favicon.svg

Giving docs/ its own go.mod is deliberate: even if your project itself is written in Go and already has a go.mod at the repository root, the two module graphs stay completely separate so the documentation theme never enters your application’s dependency tree.

Initialize the docs/ sub-project

Install Git, Go and Hugo per Prerequisites, then run these steps from your project’s repository root:

  1. Create docs/ and pin OINK

    Terminal
    mkdir -p docs/content/docs
    cd docs
    hugo mod init github.com/OWNER/PROJECT/docs
    hugo mod get github.com/pgsty/oink@v1.8.0

    Ending the module path in /docs keeps it distinct from the root module. Commit both docs/go.mod and docs/go.sum so CI resolves the exact same theme tag you tested locally.

  2. Write docs/hugo.yml with github_subdir

    Create docs/hugo.yml. Compared to a standalone site, the crucial extra setting is params.github_subdir: docs: without it, every Edit this page and history link points to /content/... at the repository root and returns 404 on GitHub.

    docs/hugo.yml
    title: My Project
    baseURL: https://OWNER.github.io/PROJECT/
    defaultContentLanguage: en
    enableGitInfo: true
    
    languages:
      en:
        label: English
        locale: en-US
        weight: 1
        title: My Project
        params:
          description: Documentation for My Project
        menus:
          main:
            - { name: Docs, pageRef: /docs, weight: 20 }
    
    markup:
      goldmark:
        renderer:
          unsafe: true
        parser:
          attribute:
            block: true
          wrapStandAloneImageWithinParagraph: false
      highlight:
        noClasses: false
    
    params:
      offline_search: true
      github_repo: https://github.com/OWNER/PROJECT
      github_branch: main
      github_subdir: docs # required when the Hugo site lives in docs/
      ui:
        preset: paper
        preset_menu: [paper, slate, github, ink, news, terminal]
        dark_mode: true
        sidebar_menu_foldable: true
        section_index: cards
    
    outputs:
      home: [HTML, markdown, LLMS]
      page: [HTML, markdown]
      section: [HTML, RSS, print, markdown]
    
    module:
      imports:
        - path: github.com/pgsty/oink
  3. Add your first page and preview

    Write docs/content/docs/_index.md and docs/content/docs/install.md (see From scratch for minimal examples), then preview from the repository root with -s docs (or cd docs && hugo serve):

    Terminal (from repository root)
    hugo serve -s docs

    Open http://localhost:1313/docs/ and verify that the Edit this page entry in the page-actions menu beside the title opens docs/content/docs/... in your repository.

Manage .gitignore cleanly

Hugo writes generated HTML, processed images, lock files and module caches into the site directory. Add explicit docs/-prefixed ignore rules to your repository’s .gitignore before running your first build, so generated output never bloats Git history or creates merge conflicts—and so you never accidentally ignore a public/ or resources/ directory used by your main application:

.gitignore (repository root)
# OINK / Hugo documentation build outputs and local caches
docs/public/
docs/resources/
docs/.hugo_build.lock
docs/.hugo_cache/
go.work
go.work.sum

Know which files stay out of Git and which ones CI requires:

Path Track in Git? Why
docs/public/ Ignore Built HTML/CSS/JS output; regenerated cleanly by CI on every deploy
docs/resources/ Ignore Cached processed images (_gen/); stale copies bloat diffs
docs/.hugo_build.lock Ignore Ephemeral Hugo build lock file
docs/.hugo_cache/ Ignore Local or CI Hugo cache directory
go.work, go.work.sum Ignore Machine-local Go workspace paths break other contributors and CI
docs/hugo.yml, docs/go.mod, docs/go.sum Commit Site configuration and exact checksum-verified OINK release
docs/content/, docs/data/, docs/assets/, docs/static/ Commit Authored Markdown, landing data, logos, CSS and static files

Run a production build once and check git status --short to verify that zero generated files show up as untracked:

Terminal
hugo -s docs --cleanDestinationDir --gc --minify --environment production --printPathWarnings
git status --short

Auto-build on GitHub Pages

Add one GitHub Actions workflow at .github/workflows/docs.yaml. Two details differ from a standalone docs repository: every build step runs inside working-directory: docs (with cache-dependency-path: docs/go.sum and artifact path docs/public), and the paths: filter ensures code-only commits do not waste runner minutes rebuilding unchanged docs.

.github/workflows/docs.yaml
 1name: Deploy Docs to GitHub Pages
 2
 3on:
 4  push:
 5    branches: [main]
 6    paths:
 7      - 'docs/**'
 8      - '.github/workflows/docs.yaml'
 9  workflow_dispatch:
10
11permissions:
12  contents: read
13  pages: write
14  id-token: write
15
16concurrency:
17  group: github-pages
18  cancel-in-progress: false
19
20env:
21  # Never let a workspace override the release pinned in docs/go.mod.
22  GOWORK: off
23  HUGO_MODULE_WORKSPACE: off
24  HUGO_CACHEDIR: ${{ github.workspace }}/docs/.hugo_cache
25
26jobs:
27  build:
28    name: Build docs
29    runs-on: ubuntu-latest
30    defaults:
31      run:
32        working-directory: docs
33    steps:
34      - name: Check out repository
35        uses: actions/checkout@v7
36        with:
37          fetch-depth: 0 # required for enableGitInfo last-modified dates
38
39      - name: Set up Go
40        uses: actions/setup-go@v7
41        with:
42          go-version: stable
43          cache-dependency-path: docs/go.sum
44
45      - name: Configure GitHub Pages
46        id: pages
47        uses: actions/configure-pages@v6
48
49      - name: Install Hugo
50        uses: peaceiris/actions-hugo@v3
51        with:
52          hugo-version: latest
53
54      - name: Download OINK module
55        run: go mod download github.com/pgsty/oink
56
57      - name: Build production site
58        run: |
59          hugo --cleanDestinationDir --gc --minify --environment production \
60            --printPathWarnings \
61            --baseURL "${{ steps.pages.outputs.base_url }}/"
62
63      - name: Upload Pages artifact
64        uses: actions/upload-pages-artifact@v5
65        with:
66          path: docs/public
67
68  deploy:
69    name: Deploy
70    environment:
71      name: github-pages
72      url: ${{ steps.deployment.outputs.page_url }}
73    runs-on: ubuntu-latest
74    needs: build
75    steps:
76      - name: Publish
77        id: deployment
78        uses: actions/deploy-pages@v5

How the build logic hangs together:

  • paths: ['docs/**', '.github/workflows/docs.yaml'] triggers automatic deploys only when documentation or the workflow itself changes; workflow_dispatch still lets you trigger a deploy manually at any time.
  • defaults.run.working-directory: docs makes go mod download and hugo operate strictly on docs/go.mod and docs/hugo.yml without touching a root-level go.mod.
  • --baseURL "${{ steps.pages.outputs.base_url }}/" injects the exact URL GitHub Pages serves—including the /<PROJECT>/ subpath—so search indexes, stylesheets and canonical links never 404.
  • --printPathWarnings without --panicOnWarning keeps OINK’s warnings readable in the log without aborting on non-fatal diagnostics.

In GitHub, open Settings → Pages → Build and deployment → Source, choose GitHub Actions, and push to main.

Auto-build on Cloudflare Pages

Cloudflare Pages supports two deployment models for a docs/ sub-project. Pick one per Cloudflare Pages project—never connect both Git integration and Direct Upload to the same project:

Building in GitHub Actions and uploading docs/public via Wrangler lets you run the latest Hugo release (even when Cloudflare’s default build image ships an older Hugo), plus native paths: filtering so application-only pushes skip doc deploys.

.github/workflows/docs-cloudflare.yaml
 1name: Deploy Docs to Cloudflare Pages
 2
 3on:
 4  push:
 5    branches: [main]
 6    paths:
 7      - 'docs/**'
 8      - '.github/workflows/docs-cloudflare.yaml'
 9  workflow_dispatch:
10
11permissions:
12  contents: read
13  deployments: write
14
15concurrency:
16  group: cloudflare-docs-${{ github.ref }}
17  cancel-in-progress: true
18
19env:
20  GOWORK: off
21  HUGO_MODULE_WORKSPACE: off
22  HUGO_CACHEDIR: ${{ github.workspace }}/docs/.hugo_cache
23
24jobs:
25  deploy:
26    name: Build and upload docs
27    runs-on: ubuntu-latest
28    defaults:
29      run:
30        working-directory: docs
31    steps:
32      - name: Check out repository
33        uses: actions/checkout@v7
34        with:
35          fetch-depth: 0
36
37      - name: Set up Go
38        uses: actions/setup-go@v7
39        with:
40          go-version: stable
41          cache-dependency-path: docs/go.sum
42
43      - name: Install Hugo
44        uses: peaceiris/actions-hugo@v3
45        with:
46          hugo-version: latest
47
48      - name: Download OINK module
49        run: go mod download github.com/pgsty/oink
50
51      - name: Build production site
52        env:
53          SITE_URL: ${{ vars.CLOUDFLARE_SITE_URL || 'https://my-project.pages.dev/' }}
54        run: |
55          hugo --cleanDestinationDir --gc --minify --environment production \
56            --printPathWarnings \
57            --baseURL "${SITE_URL}"
58
59      - name: Upload to Cloudflare Pages
60        uses: cloudflare/wrangler-action@v4
61        with:
62          apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
63          accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
64          command: pages deploy docs/public --project-name=${{ vars.CLOUDFLARE_PROJECT_NAME || github.event.repository.name }} --branch=${{ github.ref_name }}
65          gitHubToken: ${{ secrets.GITHUB_TOKEN }}

Set up Cloudflare once:

  1. In the Cloudflare dashboard, create a Direct Upload Pages project.
  2. Add repository secrets CLOUDFLARE_ACCOUNT_ID and CLOUDFLARE_API_TOKEN (scoped to Account → Cloudflare Pages → Edit).
  3. Set optional repository variables CLOUDFLARE_PROJECT_NAME (defaults to the repository name) and CLOUDFLARE_SITE_URL once you attach a custom domain such as https://docs.example.com/.

If you prefer Cloudflare to run Hugo directly with no GitHub Actions workflow, connect the repository in Workers & Pages → Create → Pages → Connect to Git and configure these build settings:

Setting Value Why
Root directory (path) docs Runs hugo inside docs/ so it reads docs/hugo.yml and docs/go.mod
Build command hugo --cleanDestinationDir --gc --minify --environment production --printPathWarnings Matches OINK’s production build flags
Build output directory public Relative to Root directory (docs), publishing docs/public
Include watch paths docs/* Skips doc builds on commits that only touch application source code
HUGO_VERSION 0.170.1 (or current release) Overrides Cloudflare’s older default Hugo (OINK is tested on 0.170+)
GOWORK / HUGO_MODULE_WORKSPACE off Prevents workspaces from overriding docs/go.mod

For branch preview builds, override the preview build command with --environment staging --baseURL "$CF_PAGES_URL" so Cloudflare preview URLs emit noindex and never compete with your production domain in search engines.

Verify before you merge

  1. Run hugo -s docs --cleanDestinationDir --gc --minify --environment production --printPathWarnings and confirm the log ends with Total in … and no unexpected warnings.
  2. Run git status --short: docs/public/, docs/resources/ and docs/.hugo_build.lock must not appear.
  3. Commit docs/hugo.yml, docs/go.mod, docs/go.sum, docs/content/, .gitignore and your workflow file.
  4. After the workflow turns green, open the live URL and check search, dark mode, canonical links, and Edit this page (it must open the file under docs/content/).
  • Deploy — custom domains, baseURL, CSP headers, preview indexing, and rollback
  • Browse locally — run hugo serve -s docs while writing code and docs side by side
  • From scratch — standalone OINK setup and offline / submodule install methods
  • Configuration — full hugo.yml reference, including github_subdir