Skip to main content

Backlinks

Published:

Yore embeds a backlink system based on jmooring/hugo-module-backlinks to track and display bidirectional links.

Principle

The system utilizes Hugo's render-link hook to capture internal references. It functions by passing the link's destination to the .GetPage method. If Hugo successfully resolves the path to a page, a backlink entry is recorded in the site-wide store.

Note

Backlinks rely on global state. You need to restart the development server to see updated reference.

Setup

Enable the backlinks output format in hugo.yaml:

hugo.yaml
outputs:
  home:
    - HTML
    - RSS
    - backlinks
outputFormats:
  backlinks:
    mediaType: application/json
    baseName: backlinks
    isPlainText: true
    notAlternative: true
    weight: 1
params:
  backlinkEnabled: true

To ensure backlinks are correctly indexed, use paths relative to the current file or the content directory.

For example, with this directory structure:

content/
├── docs/
│   ├── installation
│   │   └── index.md
│   └── usage.md
└── posts/
    └── feature-update.md

In docs/installation/index.md, you can reference the other content using:

  • [text](../usage.md)
  • [text](/posts/feature-update.md) or [text](../../posts/feature-update.md)

And in docs/usage.md, you can reference the other content using:

  • [text](./installation/index.md)
  • [text](/posts/feature-update.md) or [text](../posts/feature-update.md)
Caution

For a backlink to be detected, the link path must be resolvable by Hugo's GetPage method. If the path returns nil, the reference will not be indexed.