diff --git a/commands/pdfpresgen.js b/commands/pdfpresgen.js index 7e38fdf..5684d04 100644 --- a/commands/pdfpresgen.js +++ b/commands/pdfpresgen.js @@ -5,6 +5,7 @@ import logging from '../lib/logging.js'; import glob from "fast-glob"; import path from "path"; import template from "lodash/template.js"; +import { defer } from "../lib/api.js"; import PDFDocument from "pdfkit"; const log = logging.create(import.meta.url); @@ -21,12 +22,12 @@ export const description = "Generates a PDF presentation from an input .md file export const options = [ ["--heading-font ", "Font file to use for headings.", "static/fonts/VictorMono-Bold.ttf"], ["--body-font ", "Font file to use for body text.", "static/fonts/VictorMono-Medium.ttf"], + ["--output ", "The output .pdf file to write. Defaults to .pdf"], ] // put required options in the required variable export const required = [ ["--input ", "The input .md file for the generated presentation."], - ["--output ", "The output .pdf file to write."], ["--template ", "The background template image to use."], ] @@ -69,7 +70,7 @@ const write_page = (doc, template, content) => { // create the left side constant summary doc.fontSize(40); doc.font("heading").text(content.title, title_box.x, title_box.y, title_box); - doc.fontSize(20); + doc.fontSize(30); doc.moveDown(); // the lesson summary doc.font("body").text(content.summary, summary_box); @@ -165,18 +166,27 @@ const parse_input = (input) => { return result; } -export const main = async (opts) => { +const make_pdf_path = (input) => { + const result = path.parse(input); + + return path.join(result.dir, `${result.name}.pdf`); +} + +const generate_presentation = (opts, waiting) => { try { + if(!opts.output) { + opts.output = make_pdf_path(opts.input); + } + const [doc, out_stream] = start_pdf(opts); - out_stream.on("finish", () => process.exit(0)); + out_stream.on("finish", () => waiting.resolve()); const pages = parse_input(opts.input); for(let i = 0; i < pages.length; i++) { const page = pages[i]; - console.log("PAGE", page); write_page(doc, opts.template, page); // don't add a page when at the end @@ -188,5 +198,21 @@ export const main = async (opts) => { end_pdf(doc); } catch(error) { console.error(error); + waiting.resolve(); } } + +export const main = async (opts) => { + const in_files = glob.sync(opts.input); + + for(let file of in_files) { + console.log(file); + const waiting = defer(file); + const settings = {...opts}; + settings.input = file; + generate_presentation(settings, waiting); + await waiting; + } + + process.exit(0); +} diff --git a/static/djenterator/pdfpres.md b/static/djenterator/pdfpres.md new file mode 100644 index 0000000..06ea942 --- /dev/null +++ b/static/djenterator/pdfpres.md @@ -0,0 +1,25 @@ +{ + "title": "Lesson 1", + "summary": "What we're doing today for this lesson." +} +=== +The Thing + +* Hello +* This is +* Something +* Cool +--- +Another Thing + +Then we'll have more to do, but for now we'll be able to do more things than this hopefully. +--- +Image Slide + +[static/images/zed.png] +--- +Slide Title Only +--- +The End + +# See You Soon! diff --git a/static/djenterator/pdfpres.md.vars b/static/djenterator/pdfpres.md.vars new file mode 100644 index 0000000..0967ef4 --- /dev/null +++ b/static/djenterator/pdfpres.md.vars @@ -0,0 +1 @@ +{} diff --git a/static/fonts/VictorMono-Bold.ttf b/static/fonts/VictorMono-Bold.ttf new file mode 100644 index 0000000..a836ee3 Binary files /dev/null and b/static/fonts/VictorMono-Bold.ttf differ diff --git a/static/fonts/VictorMono-Light.ttf b/static/fonts/VictorMono-Light.ttf new file mode 100644 index 0000000..8691c93 Binary files /dev/null and b/static/fonts/VictorMono-Light.ttf differ diff --git a/static/fonts/VictorMono-Medium.ttf b/static/fonts/VictorMono-Medium.ttf new file mode 100644 index 0000000..42ee77a Binary files /dev/null and b/static/fonts/VictorMono-Medium.ttf differ