Force download of source files
Context
See https://github.com/readthedocs/readthedocs.org/issues/11728 for the background. In short: When I click the .md or .ipynb download links, I would expect the files to be downloaded, rather than shown as plain text.
Proposal
While this can be set server-side using the Content-Disposition header, ReadTheDocs doesn't plan to do so. I imagine they are a common host for users of this theme, so that's a shame. Thankfully there's a workaround that can be implemented by the theme, using the download attribute on the anchor tags.
I glanced at the relevant source, and there wasn't a super-obvious place to add that attribute. I'm open to doing the work, but not sure when I can get to it. Would welcome guidance.
Thanks!
Tasks and updates
No response
Bump!
My workaround was to add it via JavaScript:
# _config.yml
sphinx:
config:
html_js_files:
- download.js
// download.js
window.addEventListener("load", () => {
const links = document.querySelectorAll(
'.dropdown-download-buttons a[href$=".ipynb"]'
);
for (const link of links) {
link.setAttribute("download", "");
}
});
Better yet, turns out there's an extension that handles this (including .md files)! https://github.com/TeachBooks/JupyterBook-Patches