Skip to content

Commit 7291c38

Browse files
authored
Merge pull request #192 from qmlbook/main
Release the pdf for Contributors' Summit
2 parents ab2b5c7 + ac2e702 commit 7291c38

File tree

7 files changed

+1466
-1136
lines changed

7 files changed

+1466
-1136
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -117,3 +117,4 @@ __pycache__
117117

118118
# Qt Shaders
119119
*.qsb
120+
qt6book.pdf

assets/frontpage.jpg

467 KB
Loading

assets/frontpage.pdf

152 KB
Binary file not shown.

docs/.vuepress/config.js

+73-4
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,15 @@ module.exports = {
22
title: 'The Qt 6 Book',
33
description: "A book about QML",
44
plugins: [
5-
'vuepress-plugin-mermaidjs'
5+
'vuepress-plugin-mermaidjs',
6+
[ '@e8johan/vuepress-plugin-pdf-export', {
7+
puppeteerLaunchOptions: { args: [ '--no-sandbox', '--disable-setuid-sandbox' ] },
8+
outputFileName: 'qt6book.pdf',
9+
sorter: (a, b) => { return pageSorter(a.relativePath, b.relativePath); },
10+
filter: (p) => { return pageFilter(p.relativePath); },
11+
tocLevel: (p) => { return tocLevel(p.relativePath); },
12+
frontPage: 'assets/frontpage.pdf',
13+
}],
614
],
715
themeConfig: {
816
displayAllHeaders: false,
@@ -16,7 +24,69 @@ module.exports = {
1624
lastUpdated: 'Last Updated',
1725
nav: [
1826
],
19-
sidebar: [
27+
sidebar: sidebarOrder(),
28+
},
29+
}
30+
31+
function _pageOrder() {
32+
pageOrder = []
33+
34+
const chapterOrder = sidebarOrder();
35+
chapterOrder.forEach(chapter => {
36+
pages = chapter.children
37+
pages.forEach(page => pageOrder.push(page));
38+
});
39+
40+
return pageOrder;
41+
}
42+
43+
function tocLevel(p) {
44+
const tocTopLevel = sidebarOrder().map(s => { return s.path; });
45+
if (p.endsWith('.md'))
46+
p = '/' + p.slice(0, -3)
47+
if (tocTopLevel.indexOf(p) != -1)
48+
return 0;
49+
else
50+
return 1;
51+
}
52+
53+
function pageFilter(p) {
54+
const pageOrder = _pageOrder()
55+
56+
if (p.endsWith('.md'))
57+
p = '/' + p.slice(0, -3);
58+
59+
const indexP = pageOrder.indexOf(p);
60+
61+
return (indexP != -1);
62+
}
63+
64+
function pageSorter(a, b) {
65+
const pageOrder = _pageOrder();
66+
67+
if (a.endsWith('.md'))
68+
a = '/' + a.slice(0, -3);
69+
if (b.endsWith('.md'))
70+
b = '/' + b.slice(0, -3);
71+
72+
const indexA = pageOrder.indexOf(a);
73+
const indexB = pageOrder.indexOf(b);
74+
75+
if (indexA == -1)
76+
console.log("Page not found in index " + a);
77+
if (indexB == -1)
78+
console.log("Page not found in index " + b);
79+
80+
if (indexA < indexB)
81+
return -1;
82+
if (indexA > indexB)
83+
return 1;
84+
85+
return 0;
86+
}
87+
88+
function sidebarOrder() {
89+
return [
2090
prefaceSidebar(),
2191
ch01Sidebar(),
2292
ch02Sidebar(),
@@ -38,8 +108,7 @@ module.exports = {
38108
ch18Sidebar(),
39109
ch19Sidebar(),
40110
ch20Sidebar(),
41-
],
42-
},
111+
];
43112
}
44113

45114
function ch20Sidebar() {

docs/.vuepress/styles/index.styl

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
@media print {
2+
3+
/* The page */
4+
@page {
5+
size: portrait;
6+
7+
margin-left: 2.54cm;
8+
margin-right: 2.54cm;
9+
margin-top: 2.54cm;
10+
margin-bottom: 3.76cm;
11+
}
12+
13+
/* Tips, caveats, etc */
14+
div.custom-block {
15+
/* Avoid page-breaks */
16+
page-break-inside: avoid;
17+
}
18+
19+
/* All images */
20+
img {
21+
/* Center */
22+
display: block;
23+
margin-left: auto;
24+
margin-right: auto;
25+
26+
/* Avoid page-breaks */
27+
page-break-inside: avoid;
28+
}
29+
30+
/* Print links */
31+
p a::after {
32+
content: " (" attr(href) ") ";
33+
}
34+
35+
}

package.json

+5
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,13 @@
1414
"scripts": {
1515
"docs:dev": "vuepress dev docs --host 127.0.0.1",
1616
"docs:build": "vuepress build docs",
17+
"docs:pdf": "vuepress export docs",
1718
"examples:build": "./scripts/build-examples.sh",
1819
"examples:lint": "./scripts/lint-examples.sh",
1920
"examples:package": "./scripts/package-examples.sh"
21+
},
22+
"dependencies": {
23+
"@e8johan/vuepress-plugin-pdf-export": "^1.4.0",
24+
"vuepress-plugin-export": "^0.2.0"
2025
}
2126
}

0 commit comments

Comments
 (0)