diff --git a/src/routes/index.ts b/src/routes/index.ts index 168a911b..7c0d0d16 100644 --- a/src/routes/index.ts +++ b/src/routes/index.ts @@ -92,3 +92,11 @@ router.get(/\/emoticon\/(.*)/, (req, res, next) => { const uri = `/${encodeURI(req.params[0])}?${querystring.stringify(req.query)}`; return confluency.newRequest('get', uri, true).pipe(res); }); + +router.get('/gist/:userId/:gistId', (req, res, next) => { + res.render('md', { url: `https://gist.githubusercontent.com/${req.params.userId}/${req.params.gistId}/raw` }); +}); + +router.get('/gist/:userId/:gistId/:commitHash', (req, res, next) => { + res.render('md', { url: `https://gist.githubusercontent.com/${req.params.userId}/${req.params.gistId}/raw/${req.params.commitHash}` }); +}); diff --git a/views/md.pug b/views/md.pug new file mode 100644 index 00000000..8793fee0 --- /dev/null +++ b/views/md.pug @@ -0,0 +1,84 @@ +doctype html +html + head + title= title + link(rel='stylesheet', href=`/css/reveal.css`) + link(rel='stylesheet', href=`/css/theme/${theme || 'black'}.css`)#theme + link(rel='stylesheet', href=`/lib/css/zenburn.css`) + link(rel='stylesheet', href='https://cdn.rawgit.com/knsv/mermaid/7.0.0/dist/mermaid.css') + script(src='https://cdn.rawgit.com/knsv/mermaid/7.0.0/dist/mermaid.min.js') + script(src='https://cdn.rawgit.com/mathiasbynens/he/670991a4/he.js') + if printPdf + script. + var link = document.createElement( 'link' ); + link.rel = 'stylesheet'; + link.type = 'text/css'; + link.href = window.location.search.match( /print-pdf/gi ) ? '/css/print/pdf.css' : '/css/print/paper.css'; + document.getElementsByTagName( 'head' )[0].appendChild( link ); + + body + .reveal + .slides + section(data-markdown=url) + + script(src=`/lib/js/head.min.js`) + script(src=`/js/reveal.js`) + script. + // https://github.com/hakimel/reveal.js#configuration + Reveal.initialize({ + controls: true, + progress: true, + history: true, + center: true, + + transition: '#{transition || "slide"}', // none/fade/slide/convex/concave/zoom + + // Optional reveal.js plugins + dependencies: [ + { src: `/plugin/markdown/marked.js`, async: true }, + { src: `/plugin/markdown/markdown.js`, async: true }, + { src: `/lib/js/classList.js`, condition: function() { return !document.body.classList; } }, + { src: `/plugin/highlight/highlight.js`, async: true, callback: function() { hljs.initHighlightingOnLoad(); } }, + { src: `/plugin/zoom-js/zoom.js`, async: true }, + { src: `/plugin/notes/notes.js`, async: true } + ] + }); + var nextId = 0; + function onReadyToRenderMermaid(event) { + var mermaidContainer = event.currentSlide.getElementsByClassName('mermaid')[0]; + if (!mermaidContainer) return; + if (mermaidContainer.getAttribute('data-processed')) return; + mermaidContainer.setAttribute('data-processed', true); + var text = he.decode(mermaidContainer.innerHTML).trim(); + + var chart = document.createElement('div'); + mermaidContainer.appendChild(chart); + function insertSvg(svgCode, bindFunctions) { + chart.innerHTML = svgCode; + chart.firstChild.style.width = chart.getAttribute('viewbox').split(' ')[2] + 'px'; + chart.firstChild.style.height = chart.getAttribute('viewbox').split(' ')[3] + 'px'; + bindFunctions(chart); + } + if (!chart.id) { + chart.id = 'mermaidChart' + nextId++; + mermaidAPI.render(chart.id, text, insertSvg, mermaidContainer); + } + Reveal.layout(); + } + Reveal.addEventListener('ready', onReadyToRenderMermaid); + Reveal.addEventListener('slidechanged', onReadyToRenderMermaid); + mermaid.initialize({startOnLoad: false}); + document.addEventListener('keypress', function (event) { + if (typeof URL === 'undefined') return; + const url = new URL(document.location); + if (!url.searchParams) return; + if (event.keyCode === 116) { + const themes = [ + 'beige', 'black', 'blood', 'league', 'moon', 'night', 'serif', 'simple', 'sky', 'solarized', 'white' + ]; + const prevTheme = url.searchParams.get('theme'); + const prevIndex = themes.indexOf(prevTheme || 'black'); + url.searchParams.set('theme', themes[(prevIndex + 1) % themes.length]); + document.location = url.href; + } + }, false);