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 #
- Set up a
content/latest
directory to begin versioning your documentation. - Add the following frontmatter to
content/latest/_index.md
, updating the version numbers:cascade: version: isLatest: true major: 0 minor: 0 patch: 0
- 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 (for example, content/latest
, content/1.0.2
).
- 0.0.2 is now live!
- 0.0.2 Download
- **{{<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
- 0.0.3 is now live!
- 0.0.3 Download
- **{{<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 }}