Code Monkey home page Code Monkey logo

auto-export-gitbook's Introduction

使用方法

申请Personal access token

登录github,点击 头像 -> Settings -> Developer settings -> Personal access tokens -> Generate new token。范围选择repo,点击生成token

image-20201123203638793

Make sure to copy your new personal access token now. You won’t be able to see it again!

请保存好这个值。

将token保存至仓库中的Secrets

进入仓库,点击Settings -> Secrets -> New repository secret。将上一步得到的值保存为TOKEN,点击Add secret。以便Github Actions能利用这个值,使得其有权限向你的仓库push。(同一个token可以保存在多个仓库)

image-20201123204745882

本地文件向仓库的main分支进行新的push

确认已有文件.github\workflows\auto-generate-gitbook.yml

❗请按提示修改下述文件中的邮箱

此文件为Github Actions执行的脚本,请确认其所在的目录为.github\workflows

若无其他需求,可只修改邮箱。

name: auto-generate-gitbook
on:                                 #在main分支上进行push时触发  
  push:
    branches:
    - main

jobs:
  main-to-gh-pages:
    runs-on: ubuntu-latest
        
    steps:                          
    - name: checkout main
      uses: actions/checkout@v2
      with:
        ref: main
            
    - 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.TOKEN }}
        REF: github.com/${{github.repository}}
        MYEMAIL: [email protected]                  # !!记得修改为自己邮箱
        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 main
        git push --force --quiet "https://${TOKEN}@${REF}" main:gh-pages

确认文件book.json

此文件为生成的gitbook的配置信息。

以下信息无需修改。

可参考.\Part II以及.\Part III\UpdateLog

{
	"title": "Summary",
    "links": {
        "sidebar": {
            "Home": "https://wangzhebufangqi.github.io"
        }
    },
	"plugins" : [
		"expandable-chapters",
		"copy-code-button",
		"page-footer-ex",
		"anchor-navigation-ex",
		"expandable-chapters-small",
		"prism", 
		"-highlight",
		"-lunr", 
		"-search", 
		"search-pro",
		"splitter"
	],
	"pluginsConfig": {	
		"page-footer-ex": {
            "copyright": "使用[知识共享 署名-相同方式共享 4.0协议](https://creativecommons.org/licenses/by-sa/4.0/)发布",
            "markdown": true,
            "update_label": "<i>updated</i>",
            "update_format": "YYYY-MM-DD HH:mm:ss"
		},	
		"prism": {
			"css": ["prismjs/themes/prism-solarizedlight.css"],
			"lang": {"flow": "typescript"}
		}
	},
	"ignores" : ["_book", "node_modules"]
}

确认目录结构等符合规范

请参考.\Part III\Attention

进行push

第一次提交时,请确认默认分支为main。否则需要修改.yml文件。

git init
git add .
git commit -m "first commit"
git branch -M main
git remote add origin https://github.com/wangzhebufangqi/auto-export-gitbook.git
git push -u origin main

以后的提交保证在main分支上更新即可

git add .
git commit -m "update"
git push

结果

请确认按上述流程操作而无错漏之处。

假设输入为:

auto-export-gitbook
│  book.json
│  README.md
│
├─.github
│  └─workflows
│          auto-generate-gitbook.yml
│
├─PART I
│  │  README.md
│  │
│  ├─SubPart I
│  │      Markdown.md
│  │      PicGo.md
│  │      README.md
│  │      Typora.md
│  │
│  └─SubPart II
│          Git.md
│          Github.md
│          README.md
│
├─PART II
│      Plugins I.md
│      Plugins II.md
│      README.md
│
└─PART III
        Attention.md
        README.md
        UpdateLog.md

push后等待两分钟左右,即可在网址<username>.github.io/<repository>查看生成的gitbook。

这里的示例是https://wangzhebufangqi.github.io/auto-export-gitbook/

image-20201123213004208

更多信息

auto-export-gitbook's People

Contributors

tetsuou avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.