Skip to content

Commit 1bf45ad

Browse files
committed
Update build script
1 parent b6755e6 commit 1bf45ad

File tree

1 file changed

+36
-94
lines changed

1 file changed

+36
-94
lines changed

build.js

Lines changed: 36 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -1,84 +1,33 @@
11
'use strict';
22

3+
const now = new Date();
4+
35
const fs = require('fs');
46
const PdfPrinter = require('pdfmake');
7+
const config = require('./content/Book.js');
8+
const languages = Object.keys(config.languages);
59

6-
const fonts = {
7-
Roboto: {
8-
normal: 'fonts/Roboto-Regular.ttf',
9-
bold: 'fonts/Roboto-Medium.ttf',
10-
italics: 'fonts/Roboto-Italic.ttf',
11-
bolditalics: 'fonts/Roboto-MediumItalic.ttf',
12-
},
13-
Mono: {
14-
normal: 'fonts/RobotoMono-Regular.ttf',
15-
bold: 'fonts/RobotoMono-Medium.ttf',
16-
italics: 'fonts/RobotoMono-Italic.ttf',
17-
bolditalics: 'fonts/RobotoMono-MediumItalic.ttf',
18-
},
19-
};
20-
21-
const printer = new PdfPrinter(fonts);
22-
10+
const printer = new PdfPrinter(config.fonts);
2311
const content = [];
12+
const lang = 'en';
2413

25-
content.push({
26-
text: 'Metaprogramming',
27-
bold: true,
28-
fontSize: 28,
29-
alignment: 'center',
30-
margin: [40, 20, 40, 0],
31-
});
14+
const front = config.languages[lang];
3215

33-
content.push({
34-
text: 'Multi-paradigm approach in the\nSoftware Engineering',
35-
bold: true,
36-
fontSize: 14,
37-
alignment: 'center',
38-
margin: [40, 20, 40, 0],
39-
});
40-
41-
content.push({
42-
text: '© Timur Shemsedinov, Metarhia community',
43-
fontSize: 14,
44-
alignment: 'center',
45-
margin: [40, 60, 40, 0],
46-
});
47-
48-
content.push({
49-
text: 'Kiev, 2015 — 2022',
50-
fontSize: 14,
51-
alignment: 'center',
52-
margin: [40, 40, 40, 0],
53-
});
54-
55-
const pageBreak = (s) => content.push({ text: '', pageBreak: s });
16+
content.push({ text: front.title, ...config.title });
17+
content.push({ text: front.subtitle, ...config.subtitle });
18+
content.push({ text: front.copyright, ...config.copyright });
19+
content.push({ text: front.location, ...config.location });
5620

5721
const caption = (s) => {
58-
content.push({
59-
text: s,
60-
fontSize: 15,
61-
bold: true,
62-
margin: [30, 5, 30, 5],
63-
});
22+
content.push({ text: s, ...config.caption });
6423
};
6524

6625
const index = (s) => {
67-
content.push({
68-
text: s,
69-
fontSize: 12,
70-
margin: [30, 2, 30, 2],
71-
preserveLeadingSpaces: true,
72-
});
26+
content.push({ text: s, ...config.index });
7327
};
7428

7529
const para = (s) => {
76-
content.push({
77-
text: s,
78-
fontSize: 12,
79-
alignment: 'justify',
80-
margin: [30, 5, 30, 5],
81-
});
30+
content.push({ text: s, ...config.para });
8231
};
8332

8433
const code = (src) => {
@@ -94,37 +43,32 @@ const code = (src) => {
9443
],
9544
],
9645
},
97-
border: false,
98-
layout: 'noBorders',
99-
fontSize: 12,
100-
color: '#555',
101-
fillColor: '#EEE',
102-
font: 'Mono',
46+
...config.code,
10347
});
10448
};
10549

106-
pageBreak('before');
107-
108-
const abstract = fs.readFileSync('content/Abstract.en.md', 'utf8');
109-
const text = abstract.replace('#', '').split('\n');
110-
caption(text.shift());
111-
para(text.join(' '));
112-
113-
pageBreak('before');
114-
115-
const src = fs.readFileSync('content/Index.en.md', 'utf8');
116-
const data = src.split('\n');
117-
118-
for (let i = 0; i < data.length; i++) {
119-
const row = data[i];
120-
if (row.startsWith('#')) {
121-
const text = row.replace('#', '');
122-
caption(text);
123-
} else if (row.includes('. ')) {
124-
index(row);
125-
} else {
126-
para(row);
50+
const section = (name) => {
51+
content.push({ text: '', pageBreak: 'before' });
52+
const src = fs.readFileSync(`content/${name}.${lang}.md`, 'utf8');
53+
const rows = src.split('\n');
54+
let lines = [];
55+
for (const row of rows) {
56+
if (row.startsWith('#')) {
57+
const text = row.replace('#', '');
58+
caption(text);
59+
} else if (row.trim().substring(0, 3).includes('.')) {
60+
index(row);
61+
} else if (row === '') {
62+
para(lines.join(' '));
63+
lines = [];
64+
} else {
65+
lines.push(row);
66+
}
12767
}
68+
};
69+
70+
for (const name of config.sections) {
71+
section(name);
12872
}
12973

13074
/*
@@ -137,8 +81,6 @@ const res = id(5);
13781
console.log({ res });`);
13882
*/
13983

140-
const now = new Date();
141-
14284
const book = printer.createPdfKitDocument({
14385
content,
14486
pageSize: 'A5',

0 commit comments

Comments
 (0)