diff --git a/layouts/shortcodes/download.html b/layouts/shortcodes/download.html new file mode 100644 index 0000000..11bd8db --- /dev/null +++ b/layouts/shortcodes/download.html @@ -0,0 +1,28 @@ +{{/* This shortcode lets you create a link to download a file */}} +{{/* It accepts 2 strings: the path to the file to download, relative to the Hugo build context (aka, content or static directory); the name to display for the target file */}} +{{/* Usage: download */}} + + + +{{/* Sets the file path provided in the shortcode as the href target, prepended by the Hugo BaseURL */}} + +{{ $ref := .Get 0 | relURL }} + +{{/* If it exists, get the second string provided by the user and run it through the markdown processor */}} + +{{ if .Get 1 }} + {{ $linktext := .Get 1 | markdownify }} + {{$linktext}} + +{{/* Otherwise, just get the path to the file to be downloaded. This will be run through the markdown processor + and used as the filename. */}} + +{{ else if .Get 0 }} + {{ $linktext := .Get 0 | markdownify }} + {{$linktext}} + +{{ else }} + + {{ errorf "no file path value provided in download shortcode: %s" .Position }} + +{{ end }}