version.html

If the project you are documenting must be installed, it is likely that your documentation needs to be versioned. In this scenario, it’s especially useful to have a shortcode that can also version your download links, github links, announcements, and similar assets without having to manually update them across all of your articles.

How it Works

  1. Set up a content/latest directory to begin versioning your documentation.
  2. Add the following frontmatter to content/latest/_index.md, updating the version numbers:
    cascade:
        version:
            isLatest: true
            major: 0
            minor: 0 
            patch: 0
  3. Use the {{<version>}} shortcode to print out the collection’s versions anywhere beneath the directory.

Examples

MiloDocs Theme does not actually have versioned documentation; this is just for demonstration purposes.

Local Version

The default functionality for this shortcode uses the version numbers cascading from the root of the versioned directory (e.g., content/latest, content/1.0.2).

- **{{<version>}} is now live!**
- [{{<version>}} Download](https://github.com/org/project/releases/tag/v{{<version>}})

Global Version

In cases where you want to mention or link to the latest version in older versions of your content, you can add {{<version "global">}}. This uses the site-wide parameter to determine what version number to use.

<!-- hugo.yaml -->
# Theme Feature Settings
params: 
  [...]
  version: 
    major: 0
    minor: 0
    patch: 3
- **{{<version "global">}} is now live!**
- [{{<version "global">}} Download](https://github.com/org/project/releases/tag/v{{<version "global">}})

Source Code

{{- $source := index (.Params) 0 | default "local" }}
{{- $major := ""}}
{{- $minor := ""}}
{{- $patch := ""}}
{{- $value := ""}}
{{- if eq $source "global" }}
{{- $major = .Site.Params.Version.Major }}
{{- $minor = .Site.Params.Version.Minor }}
{{- $patch = .Site.Params.Version.Patch }}
{{- else}}
{{- $major = .Page.Params.Version.Major }}
{{- $minor = .Page.Params.Version.Minor }}
{{- $patch = .Page.Params.Version.Patch }}
{{- end}}
{{- $value = print $major "." $minor "." $patch }}
{{- $value }}