Skip to content

Commit

Permalink
Merge pull request #192 from qmlbook/main
Browse files Browse the repository at this point in the history
Release the pdf for Contributors' Summit
  • Loading branch information
e8johan authored Jun 6, 2022
2 parents ab2b5c7 + ac2e702 commit 7291c38
Show file tree
Hide file tree
Showing 7 changed files with 1,466 additions and 1,136 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -117,3 +117,4 @@ __pycache__

# Qt Shaders
*.qsb
qt6book.pdf
Binary file added assets/frontpage.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/frontpage.pdf
Binary file not shown.
77 changes: 73 additions & 4 deletions docs/.vuepress/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,15 @@ module.exports = {
title: 'The Qt 6 Book',
description: "A book about QML",
plugins: [
'vuepress-plugin-mermaidjs'
'vuepress-plugin-mermaidjs',
[ '@e8johan/vuepress-plugin-pdf-export', {
puppeteerLaunchOptions: { args: [ '--no-sandbox', '--disable-setuid-sandbox' ] },
outputFileName: 'qt6book.pdf',
sorter: (a, b) => { return pageSorter(a.relativePath, b.relativePath); },
filter: (p) => { return pageFilter(p.relativePath); },
tocLevel: (p) => { return tocLevel(p.relativePath); },
frontPage: 'assets/frontpage.pdf',
}],
],
themeConfig: {
displayAllHeaders: false,
Expand All @@ -16,7 +24,69 @@ module.exports = {
lastUpdated: 'Last Updated',
nav: [
],
sidebar: [
sidebar: sidebarOrder(),
},
}

function _pageOrder() {
pageOrder = []

const chapterOrder = sidebarOrder();
chapterOrder.forEach(chapter => {
pages = chapter.children
pages.forEach(page => pageOrder.push(page));
});

return pageOrder;
}

function tocLevel(p) {
const tocTopLevel = sidebarOrder().map(s => { return s.path; });
if (p.endsWith('.md'))
p = '/' + p.slice(0, -3)
if (tocTopLevel.indexOf(p) != -1)
return 0;
else
return 1;
}

function pageFilter(p) {
const pageOrder = _pageOrder()

if (p.endsWith('.md'))
p = '/' + p.slice(0, -3);

const indexP = pageOrder.indexOf(p);

return (indexP != -1);
}

function pageSorter(a, b) {
const pageOrder = _pageOrder();

if (a.endsWith('.md'))
a = '/' + a.slice(0, -3);
if (b.endsWith('.md'))
b = '/' + b.slice(0, -3);

const indexA = pageOrder.indexOf(a);
const indexB = pageOrder.indexOf(b);

if (indexA == -1)
console.log("Page not found in index " + a);
if (indexB == -1)
console.log("Page not found in index " + b);

if (indexA < indexB)
return -1;
if (indexA > indexB)
return 1;

return 0;
}

function sidebarOrder() {
return [
prefaceSidebar(),
ch01Sidebar(),
ch02Sidebar(),
Expand All @@ -38,8 +108,7 @@ module.exports = {
ch18Sidebar(),
ch19Sidebar(),
ch20Sidebar(),
],
},
];
}

function ch20Sidebar() {
Expand Down
35 changes: 35 additions & 0 deletions docs/.vuepress/styles/index.styl
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
@media print {

/* The page */
@page {
size: portrait;

margin-left: 2.54cm;
margin-right: 2.54cm;
margin-top: 2.54cm;
margin-bottom: 3.76cm;
}

/* Tips, caveats, etc */
div.custom-block {
/* Avoid page-breaks */
page-break-inside: avoid;
}

/* All images */
img {
/* Center */
display: block;
margin-left: auto;
margin-right: auto;

/* Avoid page-breaks */
page-break-inside: avoid;
}

/* Print links */
p a::after {
content: " (" attr(href) ") ";
}

}
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,13 @@
"scripts": {
"docs:dev": "vuepress dev docs --host 127.0.0.1",
"docs:build": "vuepress build docs",
"docs:pdf": "vuepress export docs",
"examples:build": "./scripts/build-examples.sh",
"examples:lint": "./scripts/lint-examples.sh",
"examples:package": "./scripts/package-examples.sh"
},
"dependencies": {
"@e8johan/vuepress-plugin-pdf-export": "^1.4.0",
"vuepress-plugin-export": "^0.2.0"
}
}
Loading

0 comments on commit 7291c38

Please sign in to comment.