Skip to content

Commit

Permalink
Update pdf exporter to custom version (to enable filtering)
Browse files Browse the repository at this point in the history
  • Loading branch information
Johan Thelin committed May 13, 2022
1 parent 45bf675 commit 9b4ac4c
Show file tree
Hide file tree
Showing 4 changed files with 1,419 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
65 changes: 61 additions & 4 deletions docs/.vuepress/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,13 @@ 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); }
}],
],
themeConfig: {
displayAllHeaders: false,
Expand All @@ -16,7 +22,59 @@ module.exports = {
lastUpdated: 'Last Updated',
nav: [
],
sidebar: [
sidebar: sidebarOrder(),
},
}

function _pageOrder() {
pageOrder = []

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

return pageOrder;
}

function pageFilter(p) {
pageOrder = _pageOrder()

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

indexP = pageOrder.indexOf(p);

return (indexP != -1);
}

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

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

indexA = pageOrder.indexOf(a);
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 +96,7 @@ module.exports = {
ch18Sidebar(),
ch19Sidebar(),
ch20Sidebar(),
],
},
];
}

function ch20Sidebar() {
Expand Down
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.2.0",
"vuepress-plugin-export": "^0.2.0"
}
}
Loading

0 comments on commit 9b4ac4c

Please sign in to comment.