Skip to content

Commit

Permalink
refactor: self-host KaTeX assets (#6429)
Browse files Browse the repository at this point in the history
Co-authored-by: Joshua Chen <[email protected]>
  • Loading branch information
pranabdas and Josh-Cena authored Jan 27, 2022
1 parent f377097 commit f415da1
Show file tree
Hide file tree
Showing 25 changed files with 19 additions and 4 deletions.
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 added website/static/katex/fonts/KaTeX_Main-Bold.woff2
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.

0 comments on commit f415da1

Please sign in to comment.