From 3d9aa18c05946b2f06fc9b49e199b13587914f2a Mon Sep 17 00:00:00 2001 From: NGPixel Date: Sat, 24 Jun 2017 15:54:31 -0400 Subject: [PATCH] refactor: Pre-render TeX + MathML server-side to SVG --- .build/_preinit.js | 5 - .build/_tasks.js | 65 -- client/js/app.js | 6 +- client/js/components/editor.component.js | 4 +- client/js/components/history.vue | 41 ++ client/js/components/search.vue | 152 ++-- client/js/components/tree.vue | 2 +- client/js/pages/content-view.component.js | 20 - client/js/pages/source-view.component.js | 4 +- client/js/pre-init/mathjax.js | 4 - config.sample.yml | 8 - fuse.js | 8 - npm/configs/config.docker.yml | 8 - npm/configs/config.heroku.yml | 8 - package.json | 15 +- server/libs/entries.js | 130 ++-- server/libs/markdown.js | 109 ++- server/views/pages/history.pug | 38 +- server/views/pages/view.pug | 4 +- yarn.lock | 808 ++++++++++++---------- 20 files changed, 759 insertions(+), 680 deletions(-) delete mode 100644 .build/_preinit.js create mode 100644 client/js/components/history.vue delete mode 100644 client/js/pre-init/mathjax.js diff --git a/.build/_preinit.js b/.build/_preinit.js deleted file mode 100644 index 5e6ecf25..00000000 --- a/.build/_preinit.js +++ /dev/null @@ -1,5 +0,0 @@ -window.MathJax = { - root: '/js/mathjax', - delayStartupUntil: 'configured' -} -; diff --git a/.build/_tasks.js b/.build/_tasks.js index e22f4a2b..df862224 100644 --- a/.build/_tasks.js +++ b/.build/_tasks.js @@ -65,56 +65,6 @@ module.exports = Promise.mapSeries([ } }) }, - /** - * MathJax - */ - () => { - return fs.accessAsync('./assets/js/mathjax').then(() => { - console.info(colors.white(' └── ') + colors.magenta('MathJax directory already exists. Task aborted.')) - return true - }).catch(err => { - if (err.code === 'ENOENT') { - console.info(colors.white(' └── ') + colors.green('Copy MathJax dependencies to assets...')) - return fs.ensureDirAsync('./assets/js/mathjax').then(() => { - return fs.copyAsync('./node_modules/mathjax', './assets/js/mathjax', { - filter: (src, dest) => { - let srcNormalized = src.replace(/\\/g, '/') - let shouldCopy = false - console.info(colors.white(' ' + srcNormalized)) - _.forEach([ - '/node_modules/mathjax', - '/node_modules/mathjax/jax', - '/node_modules/mathjax/jax/input', - '/node_modules/mathjax/jax/output' - ], chk => { - if (srcNormalized.endsWith(chk)) { - shouldCopy = true - } - }) - _.forEach([ - '/node_modules/mathjax/extensions', - '/node_modules/mathjax/MathJax.js', - '/node_modules/mathjax/jax/element', - '/node_modules/mathjax/jax/input/MathML', - '/node_modules/mathjax/jax/input/TeX', - '/node_modules/mathjax/jax/output/SVG' - ], chk => { - if (srcNormalized.indexOf(chk) > 0) { - shouldCopy = true - } - }) - if (shouldCopy && srcNormalized.indexOf('/fonts/') > 0 && srcNormalized.indexOf('/STIX-Web') <= 1) { - shouldCopy = false - } - return shouldCopy - } - }) - }) - } else { - throw err - } - }) - }, /** * i18n */ @@ -136,21 +86,6 @@ module.exports = Promise.mapSeries([ }) }) }, - /** - * Bundle pre-init scripts - */ - () => { - console.info(colors.white(' └── ') + colors.green('Bundling pre-init scripts...')) - let preInitContent = '' - return fs.readdirAsync('./client/js/pre-init').map(f => { - let fPath = path.join('./client/js/pre-init/', f) - return fs.readFileAsync(fPath, 'utf8').then(fContent => { - preInitContent += fContent + ';\n' - }) - }).then(() => { - return fs.outputFileAsync('./.build/_preinit.js', preInitContent, 'utf8') - }) - }, /** * Delete Fusebox cache */ diff --git a/client/js/app.js b/client/js/app.js index 0972238c..75f43a30 100644 --- a/client/js/app.js +++ b/client/js/app.js @@ -1,6 +1,6 @@ 'use strict' -/* global $ */ +/* global $, siteRoot */ /* eslint-disable no-new */ import Vue from 'vue' @@ -64,6 +64,7 @@ import colorPickerComponent from './components/color-picker.vue' import editorCodeblockComponent from './components/editor-codeblock.vue' import editorFileComponent from './components/editor-file.vue' import editorVideoComponent from './components/editor-video.vue' +import historyComponent from './components/history.vue' import loadingSpinnerComponent from './components/loading-spinner.vue' import modalCreatePageComponent from './components/modal-create-page.vue' import modalCreateUserComponent from './components/modal-create-user.vue' @@ -130,7 +131,7 @@ i18next .use(i18nextXHR) .init({ backend: { - loadPath: '/js/i18n/{{lng}}.json' + loadPath: siteRoot + '/js/i18n/{{lng}}.json' }, lng: siteLang, fallbackLng: siteLang @@ -176,6 +177,7 @@ $(() => { editorCodeblock: editorCodeblockComponent, editorFile: editorFileComponent, editorVideo: editorVideoComponent, + history: historyComponent, loadingSpinner: loadingSpinnerComponent, modalCreatePage: modalCreatePageComponent, modalCreateUser: modalCreateUserComponent, diff --git a/client/js/components/editor.component.js b/client/js/components/editor.component.js index 687ef251..c06bfdc4 100644 --- a/client/js/components/editor.component.js +++ b/client/js/components/editor.component.js @@ -1,6 +1,6 @@ 'use strict' -/* global $ */ +/* global $, siteRoot */ let mde @@ -30,7 +30,7 @@ export default { return resp.json() }).then(resp => { if (resp.ok) { - window.location.assign('/' + self.currentPath) + window.location.assign(siteRoot + '/' + self.currentPath) } else { self.$store.dispatch('alert', { style: 'red', diff --git a/client/js/components/history.vue b/client/js/components/history.vue new file mode 100644 index 00000000..5917c03f --- /dev/null +++ b/client/js/components/history.vue @@ -0,0 +1,41 @@ + + + diff --git a/client/js/components/search.vue b/client/js/components/search.vue index eb3d8810..cb6c45f0 100644 --- a/client/js/components/search.vue +++ b/client/js/components/search.vue @@ -10,7 +10,7 @@ li(v-if='searchres.length === 0') a: em {{ $t('search.nomatch') }} li(v-for='sres in searchres', v-bind:class='{ "is-active": searchmovekey === "res." + sres.entryPath }') - a(v-bind:href='"/" + sres.entryPath') {{ sres.title }} + a(v-bind:href='siteRoot + "/" + sres.entryPath') {{ sres.title }} p.searchresults-label(v-if='searchsuggest.length > 0') {{ $t('search.didyoumean') }} ul.searchresults-list(v-if='searchsuggest.length > 0') li(v-for='sug in searchsuggest', v-bind:class='{ "is-active": searchmovekey === "sug." + sug }') @@ -18,81 +18,81 @@ diff --git a/client/js/components/tree.vue b/client/js/components/tree.vue index 21f0b572..163510f9 100644 --- a/client/js/components/tree.vue +++ b/client/js/components/tree.vue @@ -16,7 +16,7 @@