build.js 1.1 KB

123456789101112131415161718192021222324252627
  1. const fs = require('fs-extra');
  2. // generate cli.md
  3. const cli = require('../../cli');
  4. const template = fs.readFileSync('../docs/cli.md.template');
  5. fs.writeFileSync('../docs/cli.md', [template,
  6. ...cli.options.map(option => `### \`${option.flags}\`
  7. ${option.description}${((option.bool && option.defaultValue !== undefined)
  8. ? ' (default: ' + option.defaultValue + ')' : '')}
  9. `),
  10. '### `-h, --help`\nOutput usage information', ''].join('\n'));
  11. // copy local built KaTeX
  12. fs.copySync('../dist/katex.min.js', 'static/static/katex.min.js');
  13. fs.copySync('../dist/katex.min.css', 'static/static/katex.min.css');
  14. fs.copySync('../dist/fonts', 'static/static/fonts');
  15. // use KaTeX from CDN on the main page for Netlify production deploy
  16. if (process.env.CONTEXT === 'production') {
  17. const version = require('../versions.json')[0];
  18. let indexHtml = fs.readFileSync('pages/index.html', 'utf8');
  19. indexHtml = indexHtml.replace(/(["'])static\/(katex|fonts)/g,
  20. `$1https://cdn.jsdelivr.net/npm/katex@${version}/dist/$2`);
  21. fs.writeFileSync('pages/index.html', indexHtml);
  22. }