Skip to content

Commit 0dce2c3

Browse files
committed
尝试引入vuepress pdf插件
1 parent 37009e7 commit 0dce2c3

8 files changed

+204
-15
lines changed

.eslintrc.js

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ module.exports = {
66
env: {
77
// Your environments (which contains several predefined global variables)
88
'node': true,
9+
es6: true,
910
},
1011
globals: {
1112
// Your global variables (setting to false means it's not allowed to be reassigned)

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@
66
node_modules
77
*.bkp
88
*.log
9+
*.pdf
910

gen_pdf.js

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
const markdownpdf = require('markdown-pdf')
2+
const path = require('path')
3+
const fs = require('fs')
4+
5+
const bookPath = path.join(__dirname, 'output/book.pdf')
6+
const markdownPath = path.join(__dirname, 'text')
7+
const mdDocs = fs.readdirSync(markdownPath).filter(file => {
8+
return path.extname(file) === '.md'
9+
}).map(file => path.join(markdownPath, file))
10+
const paperFormat = 'A6'
11+
markdownpdf({
12+
paperFormat,
13+
}).concat.from(mdDocs).to(bookPath, function () {
14+
console.log('Created', paperFormat, bookPath)
15+
})

package.json

+2
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,14 @@
77
"dev": "npm run docs:dev",
88
"docs:build": "vuepress build text",
99
"build": "cross-env NODE_OPTIONS=--openssl-legacy-provider npm run docs:build",
10+
"pdf": "vuepress export text",
1011
"preview": "cd output && anywhere 8888"
1112
},
1213
"repository": "[email protected]:yunnysunny/nodebook.git",
1314
"author": "yunnysunny <[email protected]>",
1415
"license": "MIT",
1516
"devDependencies": {
17+
"@whyun/vuepress-plugin-pdf-export": "^1.2.0",
1618
"cross-env": "^7.0.3",
1719
"eslint": "^8.56.0",
1820
"markdown-it-disable-url-encode": "^1.0.1",

text/.vuepress/config.js

+23
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ const baseUrl = 'https://blog.whyun.com/nodebook'
44
module.exports = {
55
 title: 'nodebook',
66
 description: 'Node 基础教程',
7+
host: '127.0.0.1',
78
base,
89
locales: {
910
'/': {
@@ -59,6 +60,28 @@ module.exports = {
5960
hostname: baseUrl,
6061
// 排除无实际内容的页面
6162
exclude: ["/404.html"]
63+
},
64+
// 'vuepress-plugin-export': {
65+
66+
// },
67+
'@whyun/vuepress-plugin-pdf-export': {
68+
puppeteerLaunchOptions: {
69+
args: ['--no-sandbox', '--disable-setuid-sandbox']
70+
},
71+
filter: function(page) {
72+
return !(['/SUMMARY.html'].includes(page.path))
73+
},
74+
sorter: function(a, b) {
75+
const pathA = a.path
76+
const pathB = b.path
77+
if (pathA < pathB) {
78+
return -1
79+
}
80+
if (pathA > pathB) {
81+
return 1
82+
}
83+
return 0
84+
}
6285
}
6386
}
6487

text/11_node_optimization.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
## Node.js 调优
1+
## 11 Node.js 调优
22

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

text/a5_node_multi_versions.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
## A 5 安装多版本 Node
1+
## A5 安装多版本 Node
22

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

0 commit comments

Comments
 (0)