【测试开发】基于gitbook构建自己学习总结的wiki

基于gitbook构建wiki

Date : 2021.02.03
Author: jwensh

关键词: gitbook webhook jenkins nginx wiki

文章目录

  • 基于gitbook构建wiki
    • 1.构建一个gitlab项目,并用初始化
    • 2.在jenkins上添加一个job
    • 3.使用nginx来挂在gitbook build后的html文件
    • 4.上面算是已经配置完毕
    • 5.book.json 备份内容

1.构建一个gitlab项目,并用初始化

  • 在本地和服务器上安装cnpm install -g gitbook-cli && cnpm install -g gitbook-summary
  • 在文件夹下执行gitbook init
    warn: no summary file in this book
    info: create README.md
    info: create SUMMARY.md
    info: initialization is finished
    
  • 将目录上传到gitlab

2.在jenkins上添加一个job

  • 在jenkins创建一个job,指定git后,并设gitlab webhook的方式,并生成token
    【测试开发】基于gitbook构建自己学习总结的wiki_第1张图片

  • 在gitlab对应项目上,设置webhook,填写对应jenkins的hook地址和token:为了git push触发更新

  • 在jenkins中的shell中设置gitbook的shell操作步骤

  • 使用gitbook-summary插件生成SUMMARY.md文件

  • 文件增量更新示例: rsync -vaci --delete --delete-after --exclude=patten origin dist

  • jenkins的shell

    BUILD_ID=DONTKILLME
    S=`pwd`
    gitbook install
    book sm
    gitbook build
    rsync -vaci --delete --delete-after  $S/_book /data/wiki/
    
  • jenkins job build后会将markdown文档转为html文件

3.使用nginx来挂在gitbook build后的html文件

  • 配置nginx.conf文件
    server {
        listen 80;
        server_name  wiki.***.***;
        
        ...省略
    
        location / {
            alias /usr/share/nginx/html/wiki/;
            index index.html index.htm;
            autoindex on;
        }
    
        error_page  500 502 503 504  /50x.html;
            location = /50x.html {
            root   html;
        }
    }
    
  • 因为nginx使用的是dcker版本,所以需要配置docker的内容: docker-compose.yml
    nginxgateway:
        container_name: nginxgateway
        restart: always
        image: nginx:1.15
        privileged: true
        volumes:
        - ./common/config/nginx/nginx.conf:/etc/nginx/nginx.conf
        - ./common/config/nginx/nginxgateway.conf:/etc/nginx/conf.d/default.conf
        - /usr/share/zoneinfo/Asia/Shanghai:/etc/localtime
        - /data/wiki/_book:/usr/share/nginx/html/wiki
        ports:
        - 80:80
        - 443:443
        dns:
        - 8.8.8.8
    

4.上面算是已经配置完毕

  • 在本地使用typoravs code来编辑这个工程
  • 编辑后,git push后就能触发jenkins job的执行,实现CI发布
  • 提交后,可能会有30ms左右的延迟

【测试开发】基于gitbook构建自己学习总结的wiki_第2张图片

5.book.json 备份内容

{
    "title" : "zYue wiki",
    "author" : "Jwensh",
    "description": "zYue,一个自定义知识wiki,是成长的记录",
    "language" : "zh-hans",
    "root": ".",
    "links": {
        "sidebar": {
        }
    },
    "style": {
        "website": "styles/website.css",
        "ebook": "styles/ebook.css",
        "pdf": "styles/pdf.css",
        "mobi": "styles/mobi.css",
        "epub": "styles/epub.css"
    },
    "plugins": [ 
        "-search", 
        "-sharing",
        "-lunr",
        "-highlight",
        "search-pro",
        "insert-logo",
        "back-to-top-button", 
        "chapter-fold",
        "expandable-chapters",
        "splitter",
        "lightbox",
        "favicon",
        "hide-element",
        "pageview-count",
        "signature",
        "page-toc-button",
        "simple-page-toc",
        "emphasize",
        "prism",
        "flexible-alerts",
        "code",
        "theme-hqbook",
        "expandable-chapters-samll",
        "tbfed-pagefooter",
        "page-treeview",
        "anchor-navigation-ex",
        "page-toc-button",
        "ancre-navigation"
    ],
    "pluginsConfig": { 
        "tbfed-pagefooter": { 
            "copyright": "Copyright & jwensh 2021",
            "modify_label": "该文件修订时间:",
            "modify_format": "YYYY-MM-DD HH:mm:ss"
        },
        "anchor-navigation-ex": {
            "showLevel": false,
            "showGoTop": false
        },
        "page-toc-button": {
            "maxTocDepth": 2,
            "minTocSize": 2
        },
        "hide-element": {
            "elements": [".gitbook-link", ".copyright"]
        },
        "insert-logo": {
            "url": "x***",
            "style": "background: none; max-height: 38px; min-height: 38px"
        },
        "gitbook-plugin-signature":{
            "autoTimeStamp":{
              "color":"gray",
              "timeStampFormat": "YYYY/MM/DD HH:mm:ss"
            },
            "autoCopyright":{
               "color":"gray",
               "owner":"Jwensh",
               "center":true
            },
            "signature":{
              "key": "Jwensh wiki"
            }
        },
        "simple-page-toc": {
            "maxDepth": 5,
            "skipFirstH1": true
        },
        "prism": {
            "css": [
                "prismjs/themes/prism-solarizedlight.css"
            ]
        },
        "flexible-alerts": {
            "style": "flat"
        },
        "code": {
            "copyButtons": false
        },
        "theme-hqbook":{
            "favicon": "./favicon.ico",
            "logo":"./logo.png",
            "search-placeholder":"输入关键字搜索",
			"copyButtons": true,
			"copyLines": true,
			"dragSplitter": true,
            "hide-elements": [
                ".summary .gitbook-link"
            ],
            "flexible-linkcard": {
                "title": "flexible-linkcard",
                "hrefUrl": "https://github.com/HaoqiangChen/gitbook-plugin-flexible-linkcard",
                "target": "_blank",
                "imgSrc": "./book/logo.png",
                "imgClass": "rect"
            }
        }
    }
}

你可能感兴趣的:(工程效能与效率,#,GIT,gitlab,gitbook,wiki)