安装gitbook
R bookdown太难用了,还是用gitbook吧
1. 安装
sudo npm install -g gitbook-cli
# 提示一下信息
# added 21 packages, and audited 579 packages in 9s
# 54 vulnerabilities (1 low, 19 moderate, 24 high, 10 critical)
# To address issues that do not require attention, run:
# npm audit fix
# To address all issues (including breaking changes), run:
# npm audit fix --force
# Run `npm audit` for details.
# 初始化我的第一本书
cd ~/Database_in_Mac/06_Study/12_gitbook/cg-first-book
gitbook init
# 报错,使用sudo了依然报错
# Installing GitBook 3.2.3
# /usr/local/lib/node_modules/gitbook-cli/node_modules/npm/node_modules/graceful-fs/polyfills.js:287
# if (cb) cb.apply(this, arguments)
# ^
# TypeError: cb.apply is not a function
# at /usr/local/lib/node_modules/gitbook-cli/node_modules/npm/node_modules/graceful-fs/polyfills.js:287:18
# at FSReqCallback.oncomplete (node:fs:199:5)
# 问了bing,可能是node版本太高了,安装nvm管理node版本
# 大家好像切换成node v10.21.0就好了
node -v
# v16.13.0
npm -v
# 8.1.0
# 安装nvm
wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.5/install.sh | bash
# 安装10.21.0后就自动use了,不需要手动nvm use 10.21.0
nvm install 10.21.0
# 初始化我的第一本书
cd ~/Database_in_Mac/06_Study/12_gitbook/cg-first-book
gitbook init
# 顺利完成
2. 出书
cd ~/Database_in_Mac/06_Study/12_gitbook/cg-first-book
# 将md文件安置在当前目录下
# 修改SUMMARY.md设置目录
# 举个例子,可以如下修改
#############
# SUMMARY.md
#############
# * [Introduction](README.md)
# * [第一章]
# * [01小节](20220611.M1芯片的mac如何安装单细胞轨迹分析软件monocle3.md)
# * [02小节](20220611.Mac安装homebrew.md)
gitbook build #本地构建
gitbook serve #本地构建并运行服务,可以在http://localhost:4000实时预览
3. 部署
# 一个输出目录的小脚本
for i in `ls *.md `
do
id=`echo $i | grep -o '\..*\.' | sed 's/\.//g'`
echo "\t* [$id]($i)"
done
将当前目录下的_book文件夹的内容全部上传到服务器,使用nginx部署即可,这是我现在的网址