From b0096a85177d218d5ac220cbf2d9fff3dc64bf98 Mon Sep 17 00:00:00 2001 From: heycalmdown Date: Fri, 4 Oct 2019 11:56:47 +0900 Subject: [PATCH] feat: support print-dpf --- src/routes/index.ts | 3 ++- views/page.pug | 7 +++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/routes/index.ts b/src/routes/index.ts index d3f2a5d4..168a911b 100644 --- a/src/routes/index.ts +++ b/src/routes/index.ts @@ -47,6 +47,7 @@ router.get('/', (_req, res) => { }); router.get('/page/:id', (req, res, next) => { + const printPdf = req.query['print-pdf'] === ''; const theme = THEMES[req.query.theme] || 'black'; const transition = TRANSITIONS[req.query.transition] || 'slide'; @@ -78,7 +79,7 @@ router.get('/page/:id', (req, res, next) => { section.sections = section.sections.map(section => map(section)); return section; }); - res.render('page', { title: page.title, req, sections, theme, transition }); + res.render('page', { title: page.title, req, sections, theme, transition, printPdf }); }).catch(next); }); diff --git a/views/page.pug b/views/page.pug index ffadf5d8..5d8d0cce 100644 --- a/views/page.pug +++ b/views/page.pug @@ -8,6 +8,13 @@ html 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