Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: self-host KaTeX assets #6429

Merged
merged 11 commits into from
Jan 27, 2022
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ website/docusaurus.config.js
website/versioned_sidebars/*.json

examples/
website/static/katex/katex.min.css
1 change: 1 addition & 0 deletions .stylelintignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ packages/docusaurus-*/lib/*
packages/docusaurus-*/lib-next/
packages/create-docusaurus/lib/*
packages/create-docusaurus/templates/
website/static/katex/katex.min.css
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,21 @@ module.exports = {
};
```

## Self-hosting KaTeX assets

Loading stylesheets, fonts, and javascript libraries from CDN sources is a good practice for popular libraries and assets. If the same assets are used across various websites, they will be cached by the browser instead of being downloaded every time we visit a new website, reducing network load. In case you prefer to self-host the `katex.min.css` (along with required KaTeX fonts), you can download the latest version from [KaTeX GitHub releases](https://github.com/KaTeX/KaTeX/releases), extract and copy `katex.min.css` and `fonts` directory (only `.woff2` font types should be enough) to your site's `static` directory, and in `docusaurus.config.js`, replace the stylesheet's `href` from the CDN url to your local path (say, `/katex/katex.min.css`).

```js title="docusaurus.config.js"
module.exports = {
stylesheets: [
{
href: '/katex/katex.min.css',
type: 'text/css',
},
],
};
```

## Upgrading rehype-katex beyond recommended version

:::tip
Expand Down
5 changes: 1 addition & 4 deletions website/docusaurus.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,8 @@ const config = {
trailingSlash: isDeployPreview,
stylesheets: [
{
href: 'https://cdn.jsdelivr.net/npm/katex@0.15.2/dist/katex.min.css',
href: '/katex/katex.min.css',
type: 'text/css',
integrity:
'sha384-MlJdn/WNKDGXveldHDdyRP1R4CTHr3FeuDNfhsLPYrq2t0UBkUdK2jyTnXPEK1NQ',
crossorigin: 'anonymous',
},
],
i18n: {
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
1 change: 1 addition & 0 deletions website/static/katex/katex.min.css

Large diffs are not rendered by default.