Compare commits

...

2 commits

Author SHA1 Message Date
1fa7da9ebb
Use JSDelivr CDN for highlight.js
All checks were successful
continuous-integration/drone/pr Build is passing
continuous-integration/drone/push Build is passing
- downside: is somebody else's CDN
- upside: changes hljs download size from >1MB to 33k

Feel free to debate this.
2020-11-05 18:03:25 +13:00
b74f0cc0dd
Don't highlight very short code blocks 2020-11-05 17:57:27 +13:00
4 changed files with 13 additions and 9 deletions

View file

@ -19,11 +19,6 @@ module.exports = [
source: "/js/main.js",
target: "/static/bundle.js"
},
{
type: "module",
source: "/js/hljs.js",
target: "/static/hljs.js"
},
{
type: "file",
source: "/assets/fonts/whitney-500.woff",

View file

@ -40,7 +40,6 @@ html
!= JSON.stringify([...static.keys()].map(k => [k, getStatic(k)]))
| )
link(rel="stylesheet" type="text/css" href=getStatic("/sass/main.sass"))
link(rel="preload" as="script" href=getStatic("/js/hljs.js"))
script(type="module" src=getStatic("/js/main.js"))
body
main.main

View file

@ -12,7 +12,19 @@ class HighlightedCode extends ElemJS {
this.element.appendChild(child)
}
}
lazyLoad("./static/hljs.js").then(hljs => hljs.highlightBlock(this.element))
if (this.element.textContent.length > 80) {
/*
no need to highlight very short code blocks:
- content inside might not be code, some users still use code blocks
for plaintext quotes
- language detection will almost certainly be incorrect
- even if it's code and the language is detected, the user will
be able to mentally format small amounts of code themselves
feel free to change the threshold number
*/
lazyLoad("https://cdn.jsdelivr.net/gh/highlightjs/cdn-release@10/build/highlight.min.js").then(hljs => hljs.highlightBlock(this.element))
}
}
}

View file

@ -1,2 +0,0 @@
const hljs = require("highlight.js")
module.exports = hljs