My content/post
folder structure looks like this:
├── post
│ ├── my-post-title
│ │ ├── file
│ │ │ └── cis-k8s-v161.pdf
│ │ └── index.md
How do I generate a link in the index.md so that user can download file/cis-k8s-v161.pdf
?
My content/post
folder structure looks like this:
├── post
│ ├── my-post-title
│ │ ├── file
│ │ │ └── cis-k8s-v161.pdf
│ │ └── index.md
How do I generate a link in the index.md so that user can download file/cis-k8s-v161.pdf
?
Does [Download file](./file/cis-k8s-v161.pdf)
not work? You can also make it relative to domain like [Download file](/my-post-title/file/cis-k8s-v161.pdf)
. However, both these methods might natively open PDF files in browser instead of starting to download it directly.
You want to learn more about Page Resources.
See also Page Bundles:
[Download file](./file/cis-k8s-v161.pdf)
will open PDF file in browser.
What I was trying to achieve is to download it.
See https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a#download
content
└── posts
└── post-1
├── foo.pdf
└── index.md
content/posts/post-1/index.md
+++
title = "Post 1"
date = 2020-11-04T19:48:25-05:00
draft = false
+++
{{< download "foo.pdf" >}}
layouts/shortcodes/download.html
{{- with .Get 0 -}}
<a href="{{ . }}" download>{{ . }}</a>
{{- else -}}
{{- errorf "The %s shortcode requires a single positional parameter, a URL. See %s" .Name .Position -}}
{{- end -}}
Nice, I didn’t know this one yet.
Another way would be to define the content-type of PDF files as application/octet-stream
via headers or htaccess file depending on where you deploy.
A post was split to a new topic: Title for download link