Skip to content

Commit

Permalink
#964: fixed pagenumbering in PDF and part of teh styling
Browse files Browse the repository at this point in the history
  • Loading branch information
commjoen committed Sep 14, 2018
1 parent 1fab1f2 commit d758634
Show file tree
Hide file tree
Showing 8 changed files with 101 additions and 18 deletions.
Binary file added Generated/MSTG-EN.pdf
Binary file not shown.
Binary file removed Generated/MSTG.pdf
Binary file not shown.
16 changes: 5 additions & 11 deletions Tools/generate_document.sh
Expand Up @@ -7,8 +7,11 @@ type pandoc >/dev/null 2>&1 || { echo >&2 "I require pandoc but it's not install
# 2. add [Date] to tag+tag of Date

cd ../Document

pandoc -f gfm --toc -N --columns 10000 --self-contained --reference-doc ../Tools/reference.docx -t docx -o ../Generated/MSTG_2.docx \
# ../Tools/metadata.yml \
pandoc -f gfm --toc -N --columns 10000 --self-contained -s --reference-doc ../Tools/reference.docx -t docx -o ../Generated/MSTG.docx \
0x00-Header.md \
Foreword.md \
0x02-Frontispiece.md \
0x03-Overview.md \
0x04-General-Testing-Guide.md \
0x04a-Mobile-App-Taxonomy.md \
Expand Down Expand Up @@ -44,15 +47,6 @@ pandoc -f gfm --toc -N --columns 10000 --self-contained --reference-doc ../Tools
0x08-Testing-Tools.md \
0x09-Suggested-Reading.md

pandoc -f gfm -N --columns 10000 --reference-doc ../Tools/reference.docx -o ../Generated/MSTG_1.docx \
0x00-Header.md \
Foreword.md \
0x02-Frontispiece.md

pandoc -f docx -N --columns 10000 --reference-doc ../Tools/reference.docx -o ../Generated/MSTG.docx \
../Generated/MSTG_1.docx \
../Generated/MSTG_2.docx

# cd ../Document-ru
#
# pandoc -f gfm --toc -N --columns 10000 --self-contained --reference-doc ../Tools/reference.docx -t docx -o ../Generated/MSTG_2.docx \
Expand Down
61 changes: 54 additions & 7 deletions Tools/genpdf.js
Expand Up @@ -3,22 +3,31 @@ var markdownpdf = require("markdown-pdf"),
split = require("split"),
through = require("through"),
duplexer = require("duplexer");
var Remarkable = require("remarkable");
var replace = require("replace-in-file");
var lang = "";
var langdir = "";
var tag = "";
var help = false;

if (process.argv.includes("-h")) {
console.log("Helptext here");
help = true;
} else if (process.argv.includes("-lang")) {
}
if (process.argv.includes("-lang")) {
lang = process.argv[process.argv.indexOf("-lang") + 1];
} else if (process.argv.includes("-l")) {
lang = process.argv[process.argv.indexOf("-l") + 1];
}
if (process.argv.includes("-tag")) {
tag = process.argv[process.argv.indexOf("-tag") + 1];
} else {
tag = setDate();
}

if (!help) {
if (lang == "" || lang == null) {
lang = "EN"
lang = "EN";
langdir = "../Document/";
} else {
langdir = "../Document-" + lang + "/";
Expand All @@ -27,13 +36,41 @@ if (!help) {
runPDF();
}

function preProcessRunningJs() {
const options = {
files: "running.js",
from: "[DATE]",
to: "["+tag+"]"
};
try {
const changes = replace.sync(options);
console.log("Modified files:", changes.join(", "));
} catch (error) {
console.error("Error occurred:", error);
}
}

function postProcessRunningJS() {
const options = {
files: "running.js",
from: "["+tag+"]",
to: "[DATE]"
};
try {
const changes = replace.sync(options);
console.log("Modified files:", changes.join(", "));
} catch (error) {
console.error("Error occurred:", error);
}
}

function preProcessMd() {
// Split the input stream by lines
var splitter = split();

var replacer = through(function(data) {
this.queue(
data.replace("[date]", setDate()).replace("Images/", lang + "/Images/") +
data.replace("[date]", tag).replace("Images/", langdir + "/Images/") +
"\n"
);
});
Expand Down Expand Up @@ -99,20 +136,30 @@ function runPDF() {
langdir + "0x08-Testing-Tools.md",
langdir + "0x09-Suggested-Reading.md"
],
bookPath = "./../generated/MSTG" + lang + ".pdf";
bookPath = "./../generated/MSTG-" + lang + ".pdf";
// todo:
// 1. fix new page after before h1 starts
// 2. fix/add TOC
// 3. add changelog
// 4. Fix date to version-tag
// 5. Fix page numering
// A. make sure doc + pdf + html is uploaded by travis
// B. make sure a markdown linter runs at PR!
// C. update gitbook automatically
preProcessRunningJs();
var md = new Remarkable();

markdownpdf({ preProcessMd: preProcessMd })
md.set({
html: true,
breaks: true
});
markdownpdf({
preProcessMd: preProcessMd,
remarkable: md,
runningsPath: "running.js"
})
.concat.from(mdDocs)
.to(bookPath, function() {
console.log("Created", bookPath);
postProcessRunningJS();
});

}
9 changes: 9 additions & 0 deletions Tools/metadata.yml
@@ -0,0 +1,9 @@
---
title: My book title
author: Daniel Herzog
rights: Creative Commons Attribution 4.0 International
language: en-US
tags: [book, my-book, etc]
abstract: |
Your summary.
---
21 changes: 21 additions & 0 deletions Tools/modified.markdown
@@ -0,0 +1,21 @@
$if(titleblock)$
$titleblock$

$endif$
$for(header-includes)$
$header-includes$

$endfor$
$for(include-before)$
$include-before$

$endfor$
$if(toc)$
$table-of-contents$

$endif$
$body$
$for(include-after)$

$include-after$
$endfor$
3 changes: 3 additions & 0 deletions Tools/package.json
Expand Up @@ -9,10 +9,13 @@
"author": "Jeroen Willemsen",
"license": "MIT",
"dependencies": {
"ajv": "^6.5.3",
"duplexer": "^0.1.1",
"eslint": "^5.5.0",
"fs": "0.0.1-security",
"markdown-pdf": "9.0.0",
"remarkable": "^1.7.1",
"replace-in-file": "^3.4.2",
"split": "^1.0.1",
"through": "^2.3.8"
}
Expand Down
9 changes: 9 additions & 0 deletions Tools/running.js
@@ -0,0 +1,9 @@
exports.header = null


exports.footer = {
height: "1cm",
contents: function(pageNum, numPages) {
return "<span style='float:left;font-size:10px;'>[DATE]</span> <span style='float:right;font-size:10px;'>" + pageNum + " / " + numPages + "</span>"
}
}

0 comments on commit d758634

Please sign in to comment.