使用vuepress-deploy自動部署vuepress靜態網站至GitHub Pages

使用vuepress-deploy自動部署vuepress靜態網站至GitHub Pages

vuepress是個靜態網站(博客)生成器,具有非常好的加載性能和搜索引擎優化,如果你使用過vue的話,不妨試試,一定會讓你愛不釋手。

vuepress提供了幾種部署方法,有本地腳本、Travis CI、Netlify,但是不能完全滿足我的需求。所以我開發了一個vuepress-deploy的自動化部署工具。可以去GitHub Action市場查看:https://github.com/marketplace/actions/vuepress-deploy

#特性

  • 自動部署,可自由設置觸發時機(如push完代碼後)
  • 同時跑多個部署任務
  • 可以部署到本倉庫、\u0004亦可部署到任何有權限的倉庫
  • 支持自定義GitHub Pages域名,即支持自定義CNAME

在你項目倉庫.github/workflows目錄下創建一個 .yml文件,舉例:vuepress-deploy.yml。

<code>name: Build and Deployon: [push]jobs:  build-and-deploy:    runs-on: ubuntu-latest    steps:    - name: Checkout      uses: actions/checkout@master    - name: vuepress-deploy      uses: jenkey2011/vuepress-deploy@master      env:        ACCESS_TOKEN: ${{ secrets.ACCESS_TOKEN }}        TARGET_REPO: username/repo        TARGET_BRANCH: master        BUILD_SCRIPT: yarn && yarn build        BUILD_DIR: blog/.vuepress/dist/        CNAME: https://www.dachangxiaoyuan.top/<code>

上述配置的結果是:每次推送代碼,將自動構建、部署到username/repo的master分支。就是這麼簡單~

如果不瞭解github workflow什麼的,看下面的詳細教程

#使用示例

倉庫:

  • 示例源碼倉庫:https://github.com/jenkey2011/vuepress-deploy-demo
  • 示例目標倉庫:https://github.com/jenkey2011/vuepress-deploy-demo-target

對應情況與部署文件設置:

  • A TO A:gh_pages: deploy-to-current-repo-gh_pages.yml
  • A TO B:master: deploy-to-other-repo-master.yml
  • A TO B:custom_branch: deploy-to-other-repo-custom_branch.yml

效果查看:

  • 部署任務詳情: https://github.com/jenkey2011/vuepress-deploy-demo/actions
  • A TO A:gh_pages: https://github.com/jenkey2011/vuepress-deploy-demo/tree/gh_pages
  • A TO B:master:https://github.com/jenkey2011/vuepress-deploy-demo-target/tree/master
  • A TO B:custom_branch:https://github.com/jenkey2011/vuepress-deploy-demo-target/tree/custom_branch

#參數


使用vuepress-deploy自動部署vuepress靜態網站至GitHub Pages


#詳細教程

#創建token

點擊你的頭像 > Settings > Developer settings > Personal access tokens > Generate new token. 權限至少要勾選repo,不清楚的,直接無腦全選就行~ 問題不大,不要慌。

詳細信息看:https://help.github.com/en/github/authenticating-to-github/authorizing-a-personal-access-token-for-use-with-saml-single-sign-on

#創建secrets

你的vuepress項目源碼倉庫下 > Settings > Secrets, 創建ACCESS_TOKEN, 值就填寫你剛才創建的token,確定。

#創建一個任務文件

在項目根目錄下,創建.github/workflows,然後再創建一個 .yml文件,名字隨便取,例:vuepress-deploy.yml。

詳細信息看:https://help.github.com/en/actions/automating-your-workflow-with-github-actions/configuring-a-workflow

#相關鏈接

  • vuepress: https://vuepress.vuejs.org/zh/
  • vuepress-deploy: https://github.com/jenkey2011/vuepress-deploy


分享到:


相關文章: