Skip to main content

Backlinks

Published:

Series: Documentation

  1. 1. Introduction
  2. 2. Getting Started
  3. 3. Color Schemes
  4. 4. Directory Structure and Assets
  5. 5. Feature Images
  6. 6. Favicon
  7. 7. Series
  8. 8. Archive
  9. 9. Search
  10. 10. Backlinks
  11. 11. Related Article
  12. 12. Rich Content
  13. 13. Markdown and Hugo
  14. 14. Customization
  15. 15. Reference - Configuration
  16. 16. Reference - Front matter
  17. 17. Reference - Icons

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.

Posts referencing this article

Series: Documentation

  1. 1. Introduction
  2. 2. Getting Started
  3. 3. Color Schemes
  4. 4. Directory Structure and Assets
  5. 5. Feature Images
  6. 6. Favicon
  7. 7. Series
  8. 8. Archive
  9. 9. Search
  10. 10. Backlinks
  11. 11. Related Article
  12. 12. Rich Content
  13. 13. Markdown and Hugo
  14. 14. Customization
  15. 15. Reference - Configuration
  16. 16. Reference - Front matter
  17. 17. Reference - Icons