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
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,19 @@ module.exports = {
};
```

## Self-hosting KaTeX assets

Loading stylesheets, fonts, and javascript libraries from CDN sources is a good practice for popular libraries and assets. Provided such assets are widely used across various websites, those assets will not be downloaded every time we visit a new website that uses the same assets, rather they would be cached by the browser 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 the `katex.css` or `katex.min.css` and the `fonts` directory to docusaurus `static` directory. And in `docusaurus.config.js`, replace the css `href` from CDN url to your local path (say, `/katex/katex.css`).

```js
stylesheets: [
{
href: '/katex/katex.css',
type: 'text/css',
},
],
```
pranabdas marked this conversation as resolved.
Show resolved Hide resolved

## Upgrading rehype-katex beyond recommended version

:::tip
Expand Down
6 changes: 2 additions & 4 deletions website/docusaurus.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,9 @@ const config = {
trailingSlash: isDeployPreview,
stylesheets: [
{
href: 'https://cdn.jsdelivr.net/npm/[email protected]/dist/katex.min.css',
// style lint fails for katex.min.css
Copy link
Collaborator

@Josh-Cena Josh-Cena Jan 21, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If stylelint fails, add it to the ignore file and commit with --no-verify. I have no idea why stylelint isn't respecting the ignore option in priority to the files passed to it during precommit—eslint/prettier are able to do that

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. Not much of a difference using the minified css though.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we do get a size reduction? Even if it's just a few KBs? Since we never touch the CSS, no need to keep the original :P

href: '/katex/katex.css',
type: 'text/css',
integrity:
'sha384-MlJdn/WNKDGXveldHDdyRP1R4CTHr3FeuDNfhsLPYrq2t0UBkUdK2jyTnXPEK1NQ',
crossorigin: 'anonymous',
},
],
i18n: {
Expand Down
Binary file added website/static/katex/fonts/KaTeX_AMS-Regular.ttf
Binary file not shown.
Binary file added website/static/katex/fonts/KaTeX_AMS-Regular.woff
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 added website/static/katex/fonts/KaTeX_Fraktur-Bold.ttf
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 added website/static/katex/fonts/KaTeX_Main-Bold.ttf
Binary file not shown.
Binary file added website/static/katex/fonts/KaTeX_Main-Bold.woff
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-Italic.ttf
Binary file not shown.
Binary file added website/static/katex/fonts/KaTeX_Main-Italic.woff
Binary file not shown.
Binary file not shown.
Binary file added website/static/katex/fonts/KaTeX_Main-Regular.ttf
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 added website/static/katex/fonts/KaTeX_Math-Italic.ttf
Binary file not shown.
Binary file added website/static/katex/fonts/KaTeX_Math-Italic.woff
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.
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.
Loading