How can I add a downloadable file to my Github.io page?
Asked Answered
S

2

11

I have set up my professional website/homepage using Github Pages. I know if this was just HTML being served up from somewhere, my downloadable file would need to be in the directory of my .html file, and then I could reference it in the .html file and link it up. However, since this is served by Github through repository, I am unsure on how to do this.

  1. Do I put my downloadable file in my repo under version control like the rest of the project?
  2. If so, what path do I use in the .html file?

Also, I am aware that the Automatic Page Generator makes it possible to hardly touch the HTML, but it seems pretty restrictive as far as customizing where links and other content appears on your page...

Shulem answered 5/8, 2013 at 15:58 Comment(0)
R
10

You could just link it normally in your html. Commit it to your repository and have users right click to save.

I just tried this on one of my repositories where I put a link to my CSS file.

<a href="css/style.css">style.css</a>

I was able to right click the link and download the file. If you wanted to create a download from the root you would do:

<a href="file.txt">Download File</a>

I'm pushing my repositories manually instead of using the Automatic Page Generator. The steps are pretty straight forward Creating Project Pages Manually - GitHub Help

Rotator answered 5/8, 2013 at 16:17 Comment(4)
Don't forget you can add the "download" attribute to the <a> tag. This allows the user to download the file by clicking on it. <a href="/files/ryan_pelletier_resume.docx" download>Download My Resume</a>Tusker
@ryanp102694 I'm fairly sure it should be download="download", though that's only for compatibility reasons (at least in HTML5, the two are exactly equivalent)Shalandashale
@QPaysTaxes That is probably true, I only tested it in a recent version of Chrome.Tusker
@FundMonica'sLawsuit "The download attribute, if present, indicates that the author intends the hyperlink to be used for downloading a resource. The attribute may have a value; the value, if any, specifies the default file name that the author recommends for use in labeling the resource in a local file system. " html.spec.whatwg.org/multipage/…Sumerlin
T
0

Since it is done in GitHub pages. It can also be done like this (in markdown fashion): [download]({{ site.baseurl }}{% link file.txt %}). It has the advantage to work locally without pushing the file to the repo.

Thordis answered 7/1, 2023 at 23:8 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.