Static Sites with Sphinx and Markdown Transcripts
Chapter: More Authoring
Lecture: Downloads
Login or
purchase this course
to watch this video and the rest of the course contents.
0:00
We'll close out with two short segments. Sometimes you want to include a static file in your sight something that can be downloaded
0:10
by clicking a link. Maybe it's a pdf. Maybe it's some code, maybe it's an image and you don't want it rendered in
0:18
the page. For example, click here for the full sized image as it turns out. Sphinx has a role that you can add to your links to turn the
0:30
link into a downloadable link instead of something that would try to navigate to the URL for that link.
0:40
When it's processed, the downloadable file pointed to that by that link for example
0:46
'example.py' would be copied into a under downloads directory and then given some unique file
0:55
name so that it's hashed and whenever it changed it would get lead to a new
1:00
one and then that hash file name is inserted into the to the link text that's generated and put into the document. Let's take a look at this in action.
1:11
Going to go back to my editor gonna paste in a little bit of text that allows us to download the Python logo instead of just displaying it in line.
1:22
And for that we put the location of the file in back quotes which is kind of a common markdown thing to do but we preface it with curly brackets and a
1:34
directive. And what that's saying is this thing inside the curly brackets is a Sphinx roll, which is in our case download now that I save,
1:49
I can go back over, take a look at the rendered output, scroll down and I see that you can download the Python logo and then I get
1:59
some link text which is the file name, some styling and when I mouse over it I can see down in the bottom corner the URL.
2:10
Is some really long set of digits followed by Python-logo.png. So that when you download it it will actually save on your computer with that.
2:20
If I click on it's going to prompt me to save it with a file name and that's the file name by default.
2:29
What if I don't want that As the link text this follows a convention that you'll see a lot in MyST where you can put this in greater than less than and
2:42
put the logo some text that goes in the place of the file name and when I go back over I see that that is now my link text.
2:56
This download functionality uses roles. We talked about this a little bit earlier on the
3:03
figure element and how we can link to it using the role and we'll talk a
3:07
lot more about this later in the course because roles are a really unique facility for Sphinx.