hugo license helpers
Some license helpers if
- you may use different licenses for different page
- you don’t want to micromanage license URLs.
(simple way): specify license in page frontmatter:
And simply call {{.Params.license}}
in your page footer partial. This is
simple and versatile (you can type anything you want in this field). But there
is no link to the license text.
---
title: "hugo license helpers"
license: Public Domain or CC0
---
with spdx data
-
download the license data from spdx to e.g.
/site/data/spdx.json
-
have a template or shortcode that queries the data and parse a link
shortcodes/spdx.html
example{{- $id := .Get 0}} {{- $target:= dict}} {{- $spdxall := site.Data.spdx.licenses}} {{- range $spdxall}} {{- if (eq $id .licenseId)}} {{- $target = .}} {{- end}} {{- end}} {{- with $target.name}} <a href="{{$target.reference}}">{{$target.licenseId}}</a> {{- else}} {{- warnf "%s is not valid spdx license id, using default." $id}} <a href="/license">[license]</a> {{- end}}
-
(e.g.) call from a post (remove the spaces..)
{{ < spdx EUPL-1.2 > }}