mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-05-14 07:04:45 -04:00
Replace handlebars with string.replace
The html.hbs template does not contain any logic, so we can replace the lib with good old string.replace calls. This significantly reduces the bundle size, as we don't have to ship a full template engine to the client. Signed-off-by: David Mehren <git@herrmehren.de>
This commit is contained in:
parent
b45b8b9c0d
commit
938afbddc3
6 changed files with 18 additions and 51 deletions
|
@ -17,7 +17,6 @@ import markdownitContainer from 'markdown-it-container'
|
|||
/* Defined regex markdown it plugins */
|
||||
import Plugin from 'markdown-it-regexp'
|
||||
|
||||
import handlebars from 'handlebars'
|
||||
import 'gist-embed'
|
||||
import abcjs from 'abcjs'
|
||||
|
||||
|
@ -669,19 +668,15 @@ export function exportToHTML (view) {
|
|||
tocAffix.find('*').removeClass('active').find("a[href^='#'][smoothhashscroll]").removeAttr('smoothhashscroll')
|
||||
// generate html via template
|
||||
$.get(`${serverurl}/build/html.min.css`, css => {
|
||||
$.get(`${serverurl}/views/html.hbs`, data => {
|
||||
const template = handlebars.compile(data)
|
||||
const context = {
|
||||
url: serverurl,
|
||||
title,
|
||||
css,
|
||||
html: src[0].outerHTML,
|
||||
'ui-toc': toc.html(),
|
||||
'ui-toc-affix': tocAffix.html(),
|
||||
lang: (md && md.meta && md.meta.lang) ? `lang="${md.meta.lang}"` : null,
|
||||
dir: (md && md.meta && md.meta.dir) ? `dir="${md.meta.dir}"` : null
|
||||
}
|
||||
const html = template(context)
|
||||
$.get(`${serverurl}/views/html.hbs`, template => {
|
||||
let html = template.replace('{{{url}}}', serverurl)
|
||||
html = html.replace('{{title}}', title)
|
||||
html = html.replace('{{{css}}}', css)
|
||||
html = html.replace('{{{html}}}', src[0].outerHTML)
|
||||
html = html.replace('{{{ui-toc}}}', toc.html())
|
||||
html = html.replace('{{{ui-toc-affix}}}', tocAffix.html())
|
||||
html = html.replace('{{{lang}}}', (md && md.meta && md.meta.lang) ? `lang="${md.meta.lang}"` : '')
|
||||
html = html.replace('{{{dir}}}', (md && md.meta && md.meta.dir) ? `dir="${md.meta.dir}"` : '')
|
||||
const blob = new Blob([html], {
|
||||
type: 'text/html;charset=utf-8'
|
||||
})
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue