26

I have written a post and would like to provide a file as attachment for download.

So far I have

  • created a link [Download files][download-file]
  • declared the link as [download-file]: download.zip
  • put download.zip in the _posts folder

However, the file does not get copied to the correct location.

I have

So neither page gave me an answer on how to provide files for download.

I don't know where to put static files in the directory structure. Once I knew that, it seems I could use some Liquid like {{ site.static_files }}, but even then I'd still need to specify a file name.

Thomas Weller
  • 55,411
  • 20
  • 125
  • 222

2 Answers2

24

Here is my solution. I have a "myname".github.io, I created a folder /download inside the myname.github.io and inside this download folder I uploaded the files I want to include in my posts.

In the single post then I created the following code:

some text and [here is possible to download the file in PDF][1]

[1]:{{ site.url }}/download/file.pdf
Suragch
  • 484,302
  • 314
  • 1,365
  • 1,393
SabDeM
  • 7,050
  • 2
  • 25
  • 38
  • 1
    I see how this could work on Github or anywhere else after copying the site to another webserver. If possible, I'd like to be able to test my site locally during `jekyll serve`. Adding a download folder into `_site` always gets deleted. – Thomas Weller Sep 20 '15 at 10:23
  • 2
    Doing this also works locally. Just place the `download` folder on top level. `jekyll serve` will copy it into `_site`. For the URL, I just use `/download/file.ext`. – Thomas Weller Sep 22 '15 at 21:02
  • 4
    The url for the working example has rotted away, I'm afraid. – Kim Jul 13 '19 at 21:16
2

You can place your download.zip file in the root of your project, and it will get copied over to {{ site.url }}/download.zip. If you'd like it contained in a folder, you can create any folder, eg download/, and any file will be able to accessed via {{ site.url }}/download/*.

Every other directory and file except for [the Jekyll files]—such as css and images folders, favicon.ico files, and so forth—will be copied verbatim to the generated site.

from the Jekyll Docs

Jack Humbert
  • 129
  • 2
  • 9
  • 1
    How is this answer different from the existing answer? – Thomas Weller Jun 07 '17 at 14:41
  • 1
    I tried editing the existing answer to add the reference/explanation, and it was rejected :/ just putting the info out there for anyone else that was looking for a more thorough explanation of the behavior or Jekyll doc reference (I was). The link in @SabDeM's answer was dead, too. – Jack Humbert Jun 07 '17 at 20:38
  • With your current reputation on Stack Overflow, your edit is placed into a review queue. It has better chances to be accepted if a) the edit is as small as possible b) you describe why you changed something in the edit comment. A dead link is IMHO a good reason for editing. I can't tell why exactly your edit was rejected. Thanks for the explanation. – Thomas Weller Jun 08 '17 at 05:35