MyST provides three independent mechanisms for bundling files with your site:
project.static_files— copies files or folders into the build output at a stable, predictable URL, without hashing and without rendering any link. Use this for files that must live at a known location (e.g. aCNAMEfile for a custom domain). See the static files section.{download}role — an inline role used directly in content to create a download link at the point of use. MyST content-hashes the filename (e.g.myfile.[HASH].png) so downstream caches invalidate when the file changes. See the{download}role section.downloads:frontmatter — page or project configuration that populates the page’s download panel in the site UI (not inline in content). Can reference local files, export IDs, or remote URLs. See thedownloads:frontmatter section.
Inline download links with the {download} role¶
The {download} role takes a path to a file and generates an inline download link at that point in the content.
For example:
{download}`references.bib`Include static files with stable links¶
Use the project.static_files option to copy files or folders into your build output.
This is useful when a file needs to keep a predictable name at a known location.
Declare static files in project configuration (myst.yml)¶
To do so, add a list of paths under project: in your myst.yml:
project:
static_files:
- path/to/CNAME # A file name, for example
- path/to/assets # A folder name, for exampleUse static files in your content¶
To refer to these files in your content:
if you have declared a specific file in
static_files, refer to it as e.g.➡️
[text](/CNAME)if the file is inside a folder declared in
static_files, refer to it as e.g.➡️
[text](/assets/image.png)
How static files are copied in the build
A file path (e.g.
path/to/CNAME) is copied to the root using only its filename. Parent directories are not preserved, so the file ends up at_build/html/CNAME.A folder path (e.g.
path/to/assets) is copied recursively using only the folder’s name. As with files, parent directories are not preserved, but sub-folder contents are preserved. The folder and its contents end up at_build/html/assets/....
Download panel with downloads: frontmatter¶
The downloads: key in page or project frontmatter populates the download panel shown in the site UI (typically in the page toolbar).
It is unrelated to the {download} role: downloads: configures a UI element, not inline content links.
There are some special configuration fields to specify files that should be bundled for download with your site. These are:
In project configuration:
project:
downloads:
- file: ...
- id: ...In page frontmatter:
---
downloads:
- file: ...
- id: ...
---Each entry in your download configuration may specify one of id, file, or url.
Descriptions of these fields and other available fields are in the table below from the downloads configuration.
Table 6:Frontmatter download definitions
Field | Description |
|---|---|
| a string - reference to an existing |
| a string - a path to a local file. If |
| a string - either a full URL or a relative URL of a page in your MyST project. If |
| a string - title of the |
| a string - name of the file upon download. By default, this will match the original filename. |
| a boolean - this is automatically set to |
Example: Define multiple downloads at once¶
The following example has several downloads: the source file, as above, an exported pdf, a remote file, and a link to another website.
In addition, when you specify downloads:, it will over-ride the default download behavior (which is to link to the source file of the current page).
This example manually includes a download to the source file to re-enable this.
---
exports:
- output: paper.pdf
template: lapreprint-typst
id: my-paper
downloads:
- file: index.md
title: Source File
- id: my-paper
title: Publication
- url: https://example.com/files/script.py
filename: script.py
title: Sample Code
- url: https://example.com/more-info
title: More Info
---How to include an exported PDF with your site¶
If you want to include a PDF of your document with the downloads, take these steps:
Create a PDF export target. For example, the following page frontmatter defines a PDF export, gives it the unique identifier
my-document-export, and will output the fileexports/my-document.pdf:article.md1 2 3 4 5 6 7--- exports: - format: pdf template: lapreprint-typst output: exports/my-document.pdf id: my-document-export ---Add a download for that export. The
idfield should match the one defined for your PDF, e.g.article.md1 2 3 4 5 6 7 8 9 10--- exports: - format: pdf template: lapreprint-typst output: exports/my-document.pdf id: my-document-export downloads: - id: my-document-export title: A PDF of this document ---Build the PDF. Run the
myst buildcommand to build the PDF, e.g.myst build --pdfBuild your website. Now that you’ve built the PDF and added frontmatter for the download button, re-building your site will add a new download dropdown linked to the PDF that you’ve exported.
Include exported files with GitHub Pages¶
If you’re deploying a static site with GitHub pages, then you will need two build steps to add exported PDF files to your website. Ensure your content has the proper PDF export frontmatter, then follow these two steps in your CI.
First, install the PDF build dependencies and build the PDF with
myst build --pdf. In the example below, we’ll show how to install Typst with thesetup-typstGitHub action.Second, build the website with
myst build --html. Because your PDF has already been generated, your website will now include it.
See below for sample configuration that accomplishes this:
Example GitHub Action configuration to include PDF with GitHub Pages
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34jobs: deploy: environment: name: github-pages url: ${{ steps.deployment.outputs.page_url }} runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - name: Setup Pages uses: actions/configure-pages@v3 - uses: actions/setup-node@v4 with: node-version: 18.x # Install MyST and PDF dependencies - name: Install MyST Markdown run: npm install -g mystmd - name: Setup Typst uses: typst-community/setup-typst@v4 # Build PDF and then HTML - name: Build PDF Assets run: myst build --pdf - name: Build HTML Assets run: myst build --html # Upload to GitHub Pages - name: Upload artifact uses: actions/upload-pages-artifact@v3 with: path: './_build/html' - name: Deploy to GitHub Pages id: deployment uses: actions/deploy-pages@v4
Include a raw source file¶
You may include the raw source of a file as a download by referencing the file itself in the download frontmatter.
For example inside file index.md, you may do:
downloads:
- file: index.md
title: Source File