A complete noob here. How do I add a title to this link, so that instead of "Download files/sample.pdf
" it says "Download a sample file?
For reference, I want to add a few links to my writing samples that a potential visitor can download.
A complete noob here. How do I add a title to this link, so that instead of "Download files/sample.pdf
" it says "Download a sample file?
For reference, I want to add a few links to my writing samples that a potential visitor can download.
Is that a markdown question?
I think more of a shortcode question. What Iβm trying to achieve is so that the file is downloaded instead of having it open in the browser window.
It might help to provide some more information. As it stands, Iβd refer you to the documentation on HTML a
elements. Which is probably not what youβre looking for here.
Also, if something is downloaded or not might depend on the browser settings.
structure
content/
βββ post/
βββ test/
βββ index.md
βββ sample.pdf
layouts/shortcodes/download.html
{{- with .Get 0 }}
{{- $href := . }}
{{- $content := . }}
{{- with $.Inner }}
{{- $content = strings.Trim . "\r\n" }}
{{- end }}
<a href="{{ $href }}" download>{{ $content }}</a>
{{- else }}
{{- errorf "The %q shortcode requires a single positional parameter, a URL. See %s" .Name .Position }}
{{- end -}}
content/post/test/index.md
{{< download sample.pdf />}}
produces:
<a href="sample.pdf" download>sample.pdf</a>
content/post/test/index.md
{{< download sample.pdf >}}
Download this file
{{< /download >}}
produces:
<a href="sample.pdf" download>Download this file</a>
https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a#attr-download
Another suggestion would be to use the Page Resources Metadata to associate download resources with titles. See Page Resources | Hugo. You can find examples of using resources in Page Resources | Hugo.