Skip to content

Commit

Permalink
尝试引入vuepress pdf插件
Browse files Browse the repository at this point in the history
  • Loading branch information
yunnysunny committed Mar 31, 2024
1 parent 37009e7 commit 0dce2c3
Show file tree
Hide file tree
Showing 8 changed files with 204 additions and 15 deletions.
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ module.exports = {
env: {
// Your environments (which contains several predefined global variables)
'node': true,
es6: true,
},
globals: {
// Your global variables (setting to false means it's not allowed to be reassigned)
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@
node_modules
*.bkp
*.log
*.pdf

15 changes: 15 additions & 0 deletions gen_pdf.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
const markdownpdf = require('markdown-pdf')
const path = require('path')
const fs = require('fs')

const bookPath = path.join(__dirname, 'output/book.pdf')
const markdownPath = path.join(__dirname, 'text')
const mdDocs = fs.readdirSync(markdownPath).filter(file => {
return path.extname(file) === '.md'
}).map(file => path.join(markdownPath, file))
const paperFormat = 'A6'
markdownpdf({
paperFormat,
}).concat.from(mdDocs).to(bookPath, function () {
console.log('Created', paperFormat, bookPath)
})
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@
"dev": "npm run docs:dev",
"docs:build": "vuepress build text",
"build": "cross-env NODE_OPTIONS=--openssl-legacy-provider npm run docs:build",
"pdf": "vuepress export text",
"preview": "cd output && anywhere 8888"
},
"repository": "[email protected]:yunnysunny/nodebook.git",
"author": "yunnysunny <[email protected]>",
"license": "MIT",
"devDependencies": {
"@whyun/vuepress-plugin-pdf-export": "^1.2.0",
"cross-env": "^7.0.3",
"eslint": "^8.56.0",
"markdown-it-disable-url-encode": "^1.0.1",
Expand Down
23 changes: 23 additions & 0 deletions text/.vuepress/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const baseUrl = 'https://blog.whyun.com/nodebook'
module.exports = {
 title: 'nodebook',
 description: 'Node 基础教程',
host: '127.0.0.1',
base,
locales: {
'/': {
Expand Down Expand Up @@ -59,6 +60,28 @@ module.exports = {
hostname: baseUrl,
// 排除无实际内容的页面
exclude: ["/404.html"]
},
// 'vuepress-plugin-export': {

// },
'@whyun/vuepress-plugin-pdf-export': {
puppeteerLaunchOptions: {
args: ['--no-sandbox', '--disable-setuid-sandbox']
},
filter: function(page) {
return !(['/SUMMARY.html'].includes(page.path))
},
sorter: function(a, b) {
const pathA = a.path
const pathB = b.path
if (pathA < pathB) {
return -1
}
if (pathA > pathB) {
return 1
}
return 0
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion text/11_node_optimization.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## Node.js 调优
## 11 Node.js 调优

作为一门后端语言,肯定要求运行的效率最优化,以实现对于资源最小损耗,这一章正是围绕这个话题展开。调优是一个有挑战性的活儿,可能经常让人摸不着头脑,下面的内容尽量使用实例来带入一个个调优的场景。

Expand Down
2 changes: 1 addition & 1 deletion text/a5_node_multi_versions.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## A 5 安装多版本 Node
## A5 安装多版本 Node

Node 基本上在每年国庆节放假回来后,就会发布一个 LTS 版本,会给开发者带来具有新特性的稳定版本。对于开发者来说,肯定会有跟进新版特性的需求,但是有可能在升级过程中又会发现部分项目的依赖包短时间内又不能兼容新版本的 Node,这样就导致一个比较尴尬的现象,你本地开发环境起码得维护两个 Node 版本来回切换。[nvm](https://github.com/nvm-sh/nvm) 就是解决这个需求的一个命令行工具。

Expand Down
Loading

0 comments on commit 0dce2c3

Please sign in to comment.