Skip to content

Commit

Permalink
website: inline highlight css for the GFW
Browse files Browse the repository at this point in the history
  • Loading branch information
sorrycc committed Jan 31, 2018
1 parent b7aacdd commit b11ceae
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
3 changes: 2 additions & 1 deletion website/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"deploy": "npm run build:doc && now && now alias",
"dev": "docusaurus-start",
"build": "echo empty build",
"build:doc": "docusaurus-build",
"build:doc": "docusaurus-build && node scripts/transformHtml.js",
"publish-gh-pages": "docusaurus-publish",
"write-translations": "docusaurus-write-translations",
"version": "docusaurus-version",
Expand All @@ -18,6 +18,7 @@
},
"devDependencies": {
"docusaurus": "^1.0.5",
"globby": "^7.1.1",
"now": "^8.3.10"
}
}
19 changes: 19 additions & 0 deletions website/scripts/transformHtml.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
const globby = require('globby');
const { readFileSync, writeFileSync } = require('fs');

function transformFile(path) {
console.log(`[Replace] ${path}`);
let content = readFileSync(path, 'utf-8');
content = content.replace(
'<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/styles/default.min.css"/>',
'<style>.hljs{display:block;overflow-x:auto;padding:0.5em;background:#F0F0F0}.hljs,.hljs-subst{color:#444}.hljs-comment{color:#888888}.hljs-keyword,.hljs-attribute,.hljs-selector-tag,.hljs-meta-keyword,.hljs-doctag,.hljs-name{font-weight:bold}.hljs-type,.hljs-string,.hljs-number,.hljs-selector-id,.hljs-selector-class,.hljs-quote,.hljs-template-tag,.hljs-deletion{color:#880000}.hljs-title,.hljs-section{color:#880000;font-weight:bold}.hljs-regexp,.hljs-symbol,.hljs-variable,.hljs-template-variable,.hljs-link,.hljs-selector-attr,.hljs-selector-pseudo{color:#BC6060}.hljs-literal{color:#78A960}.hljs-built_in,.hljs-bullet,.hljs-code,.hljs-addition{color:#397300}.hljs-meta{color:#1f7199}.hljs-meta-string{color:#4d99bf}.hljs-emphasis{font-style:italic}.hljs-strong{font-weight:bold}</style>',
);
writeFileSync(path, content, 'utf-8');
}

function init() {
const files = globby.sync('build/umijs-site/**/*.html');
files.forEach(transformFile);
}

init();

0 comments on commit b11ceae

Please sign in to comment.