Skip to content

Commit

Permalink
Use local built CSS and fonts for master documentation (#1584)
Browse files Browse the repository at this point in the history
* Change `npm run` to `yarn`

* Export `commander` program if required as module

* Move `prestart` (cli.md generation) to build.js

* Normalize script names

* Change `yarn prestart` to `node lib/build.js`

* Use local built CSS and fonts

* Move stylesheet after the first paragraph

* Remove prestart script
  • Loading branch information
ylemkimon committed Aug 10, 2018
1 parent d2f56ce commit b99de9a
Show file tree
Hide file tree
Showing 11 changed files with 60 additions and 37 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Expand Up @@ -24,3 +24,5 @@ website/build/
website/yarn.lock
website/node_modules
website/i18n/*
website/static/static/katex.*
website/static/static/fonts
5 changes: 4 additions & 1 deletion .stylelintrc
Expand Up @@ -2,5 +2,8 @@
"extends": "stylelint-config-standard",
"rules": {
"indentation": 4,
}
},
"ignoreFiles": [
"**/*.min.css"
]
}
17 changes: 4 additions & 13 deletions cli.js
Expand Up @@ -62,22 +62,13 @@ const program = require("commander")
.option("-i, --input <path>", "Read LaTeX input from the given file.")
.option("-o, --output <path>", "Write html output to the given file.");

program.command('markdown-help')
.description('Print markdown version of the help')
.action(() => {
console.log();
console.log(program.options.map(option => `### \`${option.flags}\`
${option.description}${((option.bool && option.defaultValue !== undefined)
? ' (default: ' + option.defaultValue + ')' : '')}
`)
.concat(['### `-h, --help`\nOutput usage information'])
.join('\n'));
process.exit();
});
if (require.main !== module) {
module.exports = program;
return;
}

const options = program.parse(process.argv);


function readMacros() {
if (options.macroFile) {
fs.readFile(options.macroFile, "utf-8", function(err, data) {
Expand Down
10 changes: 5 additions & 5 deletions docs/support_table.md
Expand Up @@ -2,18 +2,18 @@
id: support_table
title: Support Table
---
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.10.0-beta/dist/katex.min.css" integrity="sha384-9tPv11A+glH/on/wEu99NVwDPwkMQESOocs/ZGXPoIiLE8MU/qkqUcZ3zzL+6DuH" crossorigin="anonymous">
This is a list of TeX functions, sorted alphabetically. This list includes functions that KaTeX supports and some that it doesn't support. There is a similar page, with functions [sorted by type](./supported.md).

If you know the shape of a character, but not its name, [Detexify](http://detexify.kirelabs.org/classify.html) can help.

{@stylesheet: katex.min.css}
<style>
table tr,
table td {
vertical-align: middle;
}
</style>

This is a list of TeX functions, sorted alphabetically. This list includes functions that KaTeX supports and some that it doesn't support. There is a similar page, with functions [sorted by type](./supported.md).

If you know the shape of a character, but not its name, [Detexify](http://detexify.kirelabs.org/classify.html) can help.

## Symbols

|Symbol/Function | Rendered | Source or Comment|
Expand Down
9 changes: 5 additions & 4 deletions docs/supported.md
Expand Up @@ -2,7 +2,11 @@
id: supported
title: Supported Functions
---
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.10.0-beta/dist/katex.min.css" integrity="sha384-9tPv11A+glH/on/wEu99NVwDPwkMQESOocs/ZGXPoIiLE8MU/qkqUcZ3zzL+6DuH" crossorigin="anonymous">
This is a list of TeX functions supported by KaTeX. It is sorted into logical groups.

There is a similar [Support Table](./support_table.md), sorted alphabetically, that lists both supported and un-supported functions.

{@stylesheet: katex.min.css}
<style>
p {overflow-wrap: break-word;}
table tr,
Expand All @@ -15,9 +19,6 @@ table td {
margin-left: 10px !important;
}
</style>
This is a list of TeX functions supported by KaTeX. It is sorted into logical groups.

There is a similar [Support Table](./support_table.md), sorted alphabetically, that lists both supported and un-supported functions.

<div class="katex-hopscotch">

Expand Down
12 changes: 6 additions & 6 deletions release.sh
Expand Up @@ -116,9 +116,9 @@ sed -i.bak -E '/^\/dist\/$/d' .gitignore
rm -f .gitignore.bak
git add .gitignore dist/

# Edit docs to use CSS from CDN (#1520)
# grep -l '{@stylesheet: static/katex.min.css}' docs/*.md | xargs sed -i.bak \
# 's|{@stylesheet: static/katex.min.css}|<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@./dist/katex.min.css" integrity="sha256-katex.min.css" crossorigin="anonymous"/>|'
# Edit docs to use CSS from CDN
grep -l '{@stylesheet: katex.min.css}' docs/*.md | xargs sed -i.bak \
's|{@stylesheet: katex.min.css}|<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@./dist/katex.min.css" integrity="sha384-katex.min.css" crossorigin="anonymous"/>|'

# Update the version number in CDN URLs included in the README and the documentation,
# and regenerate the Subresource Integrity hash for these files.
Expand All @@ -130,9 +130,9 @@ pushd website
yarn run version "${VERSION}"

# Restore docs to use local built CSS
# for file in ../docs/*.md.bak; do
# mv -f "$file" "${file%.bak}"
# done
for file in ../docs/*.md.bak; do
mv -f "$file" "${file%.bak}"
done

USE_SSH=true yarn publish-gh-pages
popd
Expand Down
16 changes: 16 additions & 0 deletions website/lib/build.js
@@ -0,0 +1,16 @@
const fs = require('fs-extra');

// generate cli.md
const cli = require('../../cli');
const template = fs.readFileSync('../docs/cli.md.template');

fs.writeFileSync('../docs/cli.md', [template,
...cli.options.map(option => `### \`${option.flags}\`
${option.description}${((option.bool && option.defaultValue !== undefined)
? ' (default: ' + option.defaultValue + ')' : '')}
`),
'### `-h, --help`\nOutput usage information', ''].join('\n'));

// copy local built CSS and fonts
fs.copySync('../dist/katex.min.css', 'static/static/katex.min.css');
fs.copySync('../dist/fonts', 'static/static/fonts');
File renamed without changes.
File renamed without changes.
13 changes: 7 additions & 6 deletions website/package.json
@@ -1,15 +1,16 @@
{
"scripts": {
"prestart": "cp ../docs/cli.md.template ../docs/cli.md && node ../cli.js markdown-help >> ../docs/cli.md",
"start": "docusaurus-start",
"build": "npm run prestart && docusaurus-build",
"publish-gh-pages": "npm run prestart && docusaurus-publish",
"start": "node lib/build.js && docusaurus-start",
"build": "node lib/build.js && docusaurus-build",
"publish-gh-pages": "node lib/build.js && docusaurus-publish",
"write-translations": "docusaurus-write-translations",
"version": "npm run prestart && docusaurus-version",
"version": "node lib/build.js && docusaurus-version",
"rename-version": "docusaurus-rename-version"
},
"devDependencies": {
"docusaurus": "^1.3.2"
"docusaurus": "^1.3.2",
"fs-extra": "^7.0.0",
"remarkable-embed": "^0.4.1"
},
"dependencies": {}
}
13 changes: 11 additions & 2 deletions website/siteConfig.js
Expand Up @@ -12,6 +12,14 @@
// If on netlify, use '/'. Otherwise use '/KaTeX/'.
const baseUrl = process.env.BASE_URL || (process.env.CONTEXT ? '/' : '/KaTeX/');

// Plugin for Remarkable to inject variables
const {Plugin: Embed} = require('remarkable-embed');
const embed = new Embed();

// {@stylesheet: path}
embed.register('stylesheet',
path => `<link rel="stylesheet" href="${baseUrl}static/${path}"/>`);

/* List of projects/orgs using your project for the users page */
const users = [
{
Expand Down Expand Up @@ -66,8 +74,9 @@ const siteConfig = {
},

markdownPlugins: [
require('./lib/remarkableKatex'),
require('./lib/empty_thead'),
embed.hook,
require('./lib/remarkable-katex'),
require('./lib/empty-thead'),
],

scripts: [
Expand Down

0 comments on commit b99de9a

Please sign in to comment.