gitbook 发布 github pages

简介: gitbook 发布 github pages

Gitbook 发布 Github Pages

文章目录

Gitbook 发布 Github Pages

1. github 创建仓库

2. 本地创建github仓库

2.1 linux

3. 配置 github pages

3.1 新建分支

3.2 删除不需要的文件

3.3 添加忽略文件

3.4 复制_book文件夹到分支根目录

3.5 推送

3.6 验证

4. 推送至gitbook仓库

5. github action:master 同步 gh-pages

5.1 新建 Person Access Token

5.2 创建 secret

5.3 编写 .github/workflows/main.yml

5.4 推送 github

5.5 验证

1. github 创建仓库

例如:git-handbook

1832b220aa754cd18c504acc7686a560.png

2. 本地创建github仓库

2.1 linux

仓库名:git-handbook

初始化配置操作,推送github pages

$ mkdir git-handbook
$ cd git-handbook
$ gitbook init
$ gitbook build
$ ls _book/
gitbook  index.html  search_index.json
$  ls
_book  README.md  SUMMARY.md
$ git init
$ echo "*~" > .gitignore
$ echo "_book" >> .gitignore
$ ls
_book  gitbook  index.html  README.md  search_index.json  SUMMARY.md
$ git add --all
$ git commit -m "Publish book"
$ git remote add origin https://github.com/Ghostwritten/git-handbook.git
$ git push -u origin master
Username for 'https://github.com': ghostwritten
Password for 'https://ghostwritten@github.com':<token>

3. 配置 github pages

3.1 新建分支

git checkout --orphan gh-pages

3.2 删除不需要的文件

切换到pages分支后,我们需要将_books目录之外的文件都清理掉:

git rm --cached -r .
git clean -df
rm -rf *~

3.3 添加忽略文件

使用文本编辑器,创建名为.gitignore的文件,内容如下:

*~
_book
.DS_Store

通过.gitignore文件,本地仓库将忽略临时文件和_book文件夹。

3.4 复制_book文件夹到分支根目录

cp -r _book/* .

3.5 推送

git add .
git commit -m '更新说明'
git push -u origin gh-pages

master与gh-pages的不同之处:

1832b220aa754cd18c504acc7686a560.png

1832b220aa754cd18c504acc7686a560.png

3.6 验证

如果没有自定义的域名,你访问的方式地址为:http://<github名字>.github.io/git-handbook

这里我配置了自己的域名,ghostwritten*.github.io* 重定向到了个人站点 smoothies.com.cn

1832b220aa754cd18c504acc7686a560.png

1832b220aa754cd18c504acc7686a560.png

4. 推送至gitbook仓库

注册gitbook

1832b220aa754cd18c504acc7686a560.png

1832b220aa754cd18c504acc7686a560.png

1832b220aa754cd18c504acc7686a560.png

1832b220aa754cd18c504acc7686a560.png

5. github action:master 同步 gh-pages

5.1 新建 Person Access Token

1832b220aa754cd18c504acc7686a560.png

复制**Person Access Token**

5.2 创建 secret

创建secret:ACTIONS_DEPLOY_KEY ,value填写**Person Access Token**

1832b220aa754cd18c504acc7686a560.png

5.3 编写 .github/workflows/main.yml

name: auto-generate-gitbook
on:                                 #在master分支上进行push时触发  
  push:
    branches:
    - master
jobs:
  main-to-gh-pages:
    runs-on: ubuntu-latest
    steps:                          
    - name: checkout master
      uses: actions/checkout@v2
      with:
        ref: master
    - name: install nodejs
      uses: actions/setup-node@v1
    - name: configue gitbook
      run: |
        npm install -g gitbook-cli          
        gitbook install
        npm install -g gitbook-summary
    - name: generate _book folder
      run: |
        book sm
        gitbook build
        cp SUMMARY.md _book
    - name: push _book to branch gh-pages 
      env:
        TOKEN: ${{ secrets.ACTIONS_DEPLOY_KEY }}
        REF: github.com/${{ github.repository }}.git
        MYEMAIL: 1zoxun1@gmail.com                  # !!记得修改为自己github设置的邮箱
        MYNAME: ${{ github.repository_owner }}          
      run: |
        cd _book
        git config --global user.email "${MYEMAIL}"
        git config --global user.name "${MYNAME}"
        git init
        git remote add origin https://${REF}
        git add . 
        git commit -m "Updated By Github Actions With Build ${{github.run_number}} of ${{github.workflow}} For Github Pages"
        git branch -M master
        git push --force --quiet "https://${TOKEN}@${REF}" master:gh-pages

5.4 推送 github

git add .
git commit -m "update **[.github](https://github.com/rootsongjc/kubernetes-handbook/tree/master/.github)/[workflows](https://github.com/rootsongjc/kubernetes-handbook/tree/master/.github/workflows)/main.yml**"
git push origin master

5.5 验证

1832b220aa754cd18c504acc7686a560.png

相关文章
|
1月前
|
Shell 网络安全 开发工具
Github Pages + Jekyll 独立博客一小时快速搭建&上线指南
Github Pages + Jekyll 独立博客一小时快速搭建&上线指南
|
1月前
|
资源调度 前端开发 JavaScript
不花一分钱,用Hexo和GitHub Pages搭建个人博客🏢
不花一分钱,用Hexo和GitHub Pages搭建个人博客🏢
134 0
|
6月前
|
JavaScript 开发工具 git
保姆级教程:从零构建GitHub Pages静态网站(下)
保姆级教程:从零构建GitHub Pages静态网站(下)
206 0
|
6月前
|
前端开发 JavaScript
保姆级教程:从零构建GitHub Pages静态网站(上)
保姆级教程:从零构建GitHub Pages静态网站
2297 0
|
1月前
|
存储
github pages 部署单页面
github pages 部署单页面
75 0
|
1月前
|
缓存 网络协议 CDN
Docsify 配合 Github Pages 搭建一个自己的云笔记
Docsify 配合 Github Pages 搭建一个自己的云笔记
137 0
|
8月前
|
JavaScript 内存技术
[笔记]Github+Gitbook+Github Page+Typora搭建电子书
[笔记]Github+Gitbook+Github Page+Typora搭建电子书
108 0
|
9月前
Gridea 上手教程——小白也可以用的GitHub Pages 搭建工具
Gridea 上手教程——小白也可以用的GitHub Pages 搭建工具
Gridea 上手教程——小白也可以用的GitHub Pages 搭建工具
|
9月前
Github Pages自定义域名
Github Pages自定义域名
|
10月前
github pages 用法详解 发布自己的网站
github pages 用法详解 发布自己的网站
229 0