How to produce a link to PDF file under post folder

My content/post folder structure looks like this:

├── post
│   ├── my-post-title
│   │   ├── file
│   │   │   └── cis-k8s-v161.pdf
│   │   └──

How do I generate a link in the 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.


└── posts
    └── post-1
        ├── foo.pdf


title = "Post 1"
date = 2020-11-04T19:48:25-05:00
draft = false

{{< download "foo.pdf" >}}


{{- with .Get 0 -}}
  <a href="{{ . }}" download>{{ . }}</a>
{{- else -}}
  {{- errorf "The %s shortcode requires a single positional parameter, a URL. See %s" .Name .Position -}}
{{- end -}}
1 Like

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