Merge pull request #25 from ryan4yin/add-pdf

feat: generate pdf for this book
This commit is contained in:
Ryan Yin 2023-08-05 15:46:21 +08:00 committed by GitHub
commit a8c599fbce
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 1489 additions and 220 deletions

View file

@ -0,0 +1,7 @@
@media print {
.VPNav,
.VPLocalNav,
.VPDocFooter {
display: none !important;
}
}

View file

@ -0,0 +1,10 @@
// .vitepress/theme/index.ts
import DefaultTheme from "vitepress/theme";
// custom CSS
import "../style/print.css";
export default {
// Extending the Default Theme
...DefaultTheme,
};

View file

@ -0,0 +1,30 @@
import { defineUserConfig } from "vitepress-export-pdf";
import config from './config'
// convert `config.themeConfig?.sidebar` to a list of routes
let routeOrder = [];
const sidebar = config.locales.root.themeConfig?.sidebar;
if (sidebar) {
sidebar.forEach((it) => {
if (it.items) {
it.items.forEach((subItem) => {
routeOrder.push(subItem.link.replace(/\.md$/, ""));
});
}
});
}
// print routeOrder in terminal
console.log("routeOrder: ", routeOrder);
export default defineUserConfig({
routePatterns: ["!/zh/**"], // exclude zh-CN pages
sorter: (pageA, pageB) => {
const aIndex = routeOrder.findIndex(route => route === pageA.path);
const bIndex = routeOrder.findIndex(route => route === pageB.path);
const index = aIndex - bIndex;
// console.log(`sorter: ${pageA.path} vs ${pageB.path} = ${index}`);
return index;
},
});

View file

@ -29,7 +29,12 @@
shellHook = ''
echo "node `${pkgs.nodejs}/bin/node --version`"
# Set Puppeteer to not download Chrome, cause it doesn't work on NixOS
export PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=1
# Set Puppeteer to use Chromium from Nixpkgs
export PUPPETEER_EXECUTABLE_PATH=${pkgs.chromium.outPath}/bin/chromium
'';
};
});
}
}

View file

@ -1,14 +1,16 @@
{
"devDependencies": {
"vitepress": "1.0.0-beta.5"
"vitepress": "1.0.0-beta.7",
"vitepress-export-pdf": "1.0.0-beta.0"
},
"scripts": {
"docs:dev": "vitepress dev docs",
"docs:build": "vitepress build docs",
"docs:preview": "vitepress preview docs"
"docs:preview": "vitepress preview docs",
"export-pdf": "press-export-pdf export ./docs"
},
"dependencies": {
"markdown-it-footnote": "^3.0.3",
"sitemap-ts": "^1.4.0"
}
}
}

File diff suppressed because it is too large Load diff