-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate-pdf.js
More file actions
34 lines (34 loc) · 1.29 KB
/
Copy pathcreate-pdf.js
File metadata and controls
34 lines (34 loc) · 1.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
const fs = require("fs");
const path = require('path');
const matter = require('gray-matter');
const createHtmlFile = require('./src/js/render-html.js');
const createPdfFile = require("./src/js/render-pdf.js");
// Construct MD Paths
const mdFilepathFrom = path.resolve(process.argv[2]);
const mdFilepathParsed = path.parse(mdFilepathFrom);
// Construct HTML Paths
const htmlFilepathToDir = mdFilepathParsed.dir + '/HTML/';
const htmlFilepathTo = htmlFilepathToDir + mdFilepathParsed.name + '.html';
// Construct PDF Paths
const pdfFilepathToDir = mdFilepathParsed.dir + '/PDF/';
// We parse the frontmatter for filepath override.
const frontmatter = matter.read(mdFilepathFrom);
let nameParts = [];
if (frontmatter.data.date) {
const date = new Date(Date.parse(frontmatter.data.date));
const dateString = `${date.getFullYear()}-${date.getMonth()+1}-${date.getDate()}-`;
nameParts.push(dateString);
}
nameParts.push("Signal-");
if (frontmatter.data.title) {
nameParts.push(frontmatter.data.title);
}
nameParts.push(mdFilepathParsed.name);
const pdfFilepathTo = pdfFilepathToDir + nameParts.join("-") + '.pdf';
// Create files
(async () => {
// Create the html file.
await createHtmlFile(mdFilepathFrom, htmlFilepathTo);
// Create the pdf file.
await createPdfFile(htmlFilepathTo, pdfFilepathTo);
})();