Skip to content

Commit

Permalink
feat: first shot of supporting gist
Browse files Browse the repository at this point in the history
close #72
  • Loading branch information
heycalmdown committed Dec 25, 2019
1 parent 7aa0834 commit 8ce1514
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/routes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}` });
});
84 changes: 84 additions & 0 deletions views/md.pug
Original file line number Diff line number Diff line change
@@ -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);

0 comments on commit 8ce1514

Please sign in to comment.