| 1 |
# Web assets (CSS/JS/Fonts) |
| 2 |
|
| 3 |
This theme includes several web assets to ease development and design. |
| 4 |
The configuration for our asset compilation is in `webpack.config.js`. |
| 5 |
|
| 6 |
## Compile and bundle assets |
| 7 |
|
| 8 |
When assets are compiled, static versions are placed in various places in the theme's static folder: |
| 9 |
|
| 10 |
``` |
| 11 |
src/pydata_sphinx_theme/theme/pydata_sphinx_theme/static |
| 12 |
``` |
| 13 |
|
| 14 |
For many assets, a `<hash>` is generated and appended to the end of its reference in the HTML templates of the theme. |
| 15 |
This ensures the correct asset versions are served when viewers return to your |
| 16 |
site after upgrading the theme. |
| 17 |
|
| 18 |
To compile the assets and bundle them with the theme, run this command: |
| 19 |
|
| 20 |
```console |
| 21 |
$ tox -e run compile |
| 22 |
``` |
| 23 |
|
| 24 |
## Styles (SCSS) and Scripts (JS) |
| 25 |
|
| 26 |
There are two relevant places for CSS/JS assets: |
| 27 |
|
| 28 |
- `src/pydata_sphinx_theme/assets/styles` has source files for SCSS assets. These will be compiled to CSS. |
| 29 |
- `src/pydata_sphinx_theme/assets/scripts` has source files for JS assets. These will be compiled to JS and import several vendored libraries (like Bootstrap). |
| 30 |
- `src/pydata_sphinx_theme/theme/pydata_sphinx_theme/static` has compiled versions of these assets (e.g. CSS files). This folder is not tracked in `.git` history, but it is bundled with the theme's distribution. |
| 31 |
|
| 32 |
## Vendored scripts |
| 33 |
|
| 34 |
We vendor several packages in addition to our own CSS and JS. |
| 35 |
For example, Bootstrap, JQuery, and Popper. |
| 36 |
This is configured in the `webpack.config.js` file, and imported in the respective `SCSS` or `JS` file in our assets folder. |
| 37 |
|
| 38 |
## FontAwesome icons |
| 39 |
|
| 40 |
Three "styles" of the [FontAwesome 6 Free](https://fontawesome.com/icons?m=free) |
| 41 |
icon font are used for {ref}`icon links <icon-links>` and admonitions and is |
| 42 |
the only `vendored` font. |
| 43 |
|
| 44 |
- It is managed as a dependency in `package.json` |
| 45 |
- Copied directly into the site statics at compilation, including licenses |
| 46 |
- Partially preloaded to reduce flicker and artifacts of early icon renders |
| 47 |
- Configured in `webpack.config.js` |
| 48 |
|
| 49 |
## Jinja macros |
| 50 |
|
| 51 |
Our Webpack build generates a collection of [Jinja macros](https://jinja.palletsprojects.com/en/stable/templates/) in the `static/webpack-macros.html` file. |
| 52 |
|
| 53 |
These macros are imported in the main `layout.html` file, and then inserted at various places on the page to link the static assets. |
| 54 |
|
| 55 |
Some assets [are "preloaded"](https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Attributes/rel/preload), meaning that the browser begins requesting these resources before they're needed. |
| 56 |
In particular, our JavaScript assets are preloaded in `<head>`, and the scripts are loaded at the end of `<body>`. |