Use local built KaTeX on the main page for local and Netlify deploy preview (#1631)

* Use local built KaTeX on the main page for local and netlify builds

* Use KaTeX from CDN on Netlify production deploy
This commit is contained in:
ylemkimon
2018-09-04 07:25:29 +09:00
committed by GitHub
parent 48e5a26ee9
commit c8f8ebd880
3 changed files with 18 additions and 7 deletions

View File

@@ -11,6 +11,16 @@ ${option.description}${((option.bool && option.defaultValue !== undefined)
`),
'### `-h, --help`\nOutput usage information', ''].join('\n'));
// copy local built CSS and fonts
// copy local built KaTeX
fs.copySync('../dist/katex.min.js', 'static/static/katex.min.js');
fs.copySync('../dist/katex.min.css', 'static/static/katex.min.css');
fs.copySync('../dist/fonts', 'static/static/fonts');
// use KaTeX from CDN on the main page for Netlify production deploy
if (process.env.CONTEXT === 'production') {
const version = require('../versions.json')[0];
let indexHtml = fs.readFileSync('pages/index.html', 'utf8');
indexHtml = indexHtml.replace(/(["'])static\/(katex|fonts)/g,
`$1https://cdn.jsdelivr.net/npm/katex@${version}/dist/$2`);
fs.writeFileSync('pages/index.html', indexHtml);
}

View File

@@ -16,17 +16,17 @@
<meta property="og:image" content="https://katex.org/img/og_logo.png">
<meta property="og:description" content="Simple API, no dependencies yet super-fast on all major browsers.">
<link rel="preload" href="https://cdn.jsdelivr.net/npm/katex@0.10.0-rc.1/dist/fonts/KaTeX_Main-Regular.woff2" as="font" type="font/woff2" crossorigin="anonymous">
<link rel="preload" href="https://cdn.jsdelivr.net/npm/katex@0.10.0-rc.1/dist/fonts/KaTeX_Math-Italic.woff2" as="font" type="font/woff2" crossorigin="anonymous">
<link rel="preload" href="https://cdn.jsdelivr.net/npm/katex@0.10.0-rc.1/dist/fonts/KaTeX_Size2-Regular.woff2" as="font" type="font/woff2" crossorigin="anonymous">
<link rel="preload" href="https://cdn.jsdelivr.net/npm/katex@0.10.0-rc.1/dist/fonts/KaTeX_Size4-Regular.woff2" as="font" type="font/woff2" crossorigin="anonymous">
<link rel="preload" href="static/fonts/KaTeX_Main-Regular.woff2" as="font" type="font/woff2" crossorigin="anonymous">
<link rel="preload" href="static/fonts/KaTeX_Math-Italic.woff2" as="font" type="font/woff2" crossorigin="anonymous">
<link rel="preload" href="static/fonts/KaTeX_Size2-Regular.woff2" as="font" type="font/woff2" crossorigin="anonymous">
<link rel="preload" href="static/fonts/KaTeX_Size4-Regular.woff2" as="font" type="font/woff2" crossorigin="anonymous">
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Lato:300,400,700,700i">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.10.0-rc.1/dist/katex.min.css" integrity="sha384-D+9gmBxUQogRLqvARvNLmA9hS2x//eK1FhVb9PiU86gmcrBrJAQT8okdJ4LMp2uv" crossorigin="anonymous">
<link rel="stylesheet" href="static/katex.min.css" crossorigin="anonymous">
<link rel="stylesheet" href="static/index.css">
<script defer src="https://cdn.jsdelivr.net/npm/clipboard@2.0.1/dist/clipboard.min.js" integrity="sha256-hIvIxeqhGZF+VVeM55k0mJvWpQ6gTkWk3Emc+NmowYA=" crossorigin="anonymous"></script>
<script defer src="https://cdn.jsdelivr.net/npm/katex@0.10.0-rc.1/dist/katex.min.js" integrity="sha384-483A6DwYfKeDa0Q52fJmxFXkcPCFfnXMoXblOkJ4JcA8zATN6Tm78UNL72AKk+0O" crossorigin="anonymous"></script>
<script defer src="static/katex.min.js" crossorigin="anonymous"></script>
<script defer src="js/index.js" type="text/javascript"></script>
</head>
<body>