资料总结 资料总结
首页
go
java
云原生
  • mysql
  • redis
  • MongoDB
  • 设计模式详解
  • 数据结构与算法
  • 前端
  • 项目
  • 理论基础
  • 运营
  • 分类
  • 标签
  • 归档
GitHub (opens new window)

linghui Wu

一只努力学飞的鱼
首页
go
java
云原生
  • mysql
  • redis
  • MongoDB
  • 设计模式详解
  • 数据结构与算法
  • 前端
  • 项目
  • 理论基础
  • 运营
  • 分类
  • 标签
  • 归档
GitHub (opens new window)
  • html
  • css
  • js

  • typeScript

  • icon

  • vue

  • vuepress

    • vuepress部署
      • base根目录设置
      • deploy.sh
      • Github Actions
      • GitHub Pages设置
      • 自定义域名
        • 博客评论组件 gitalk
      • Github OAuth2.0 的 注册
  • uni-app
  • node

  • node
  • 前端
  • vuepress
wulinghui
2023-01-23
目录

vuepress部署

# 部署基础

vuepress的官网部署 (opens new window)

核心指令是: vuepress build docs
输出的位置是 docs.vuepress\dist

# 部署到GitHub Pages

原理: 除了特定支持的项目类型[Hexo、Nuxt],不管什么部署到pages都是静态的html格式。
所以用一个分支保存dist编译后的静态。master 保存源码。

# base根目录设置

如果你打算发布到 https://<USERNAME>.github.io/<REPO>/(也就是说你的仓库在 https://github.com/<USERNAME>/<REPO>),
则将在docs/.vuepress/config.js中的base设置为 /<REPO>/。

# deploy.sh

见 官网的脚本 (opens new window) 不合适因为需要第三方的ci/cd工具集成。 他是最基本的实现。

	#!/usr/bin/env sh
	
	# 确保脚本抛出遇到的错误
	set -e
	
	# 生成静态文件
	npm run docs:build
	
	# 进入生成的文件夹
	cd docs/.vuepress/dist
	
	# 如果是发布到自定义域名
	# echo 'www.example.com' > CNAME
	
	git init
	git add -A
	git commit -m 'deploy'
	
	# 如果发布到 https://<USERNAME>.github.io
	# git push -f git@github.com:<USERNAME>/<USERNAME>.github.io.git master
	
	# 如果发布到 https://<USERNAME>.github.io/<REPO>
	# git push -f git@github.com:<USERNAME>/<REPO>.git master:gh-pages
	
	cd -
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25

# Github Actions

name: CI

#on: [push]

# 在master分支发生push事件时触发。
on:
  push:
    branches:
      - master

env: # 设置环境变量
  TZ: Asia/Shanghai # 时区(设置时区可使页面中的`最近更新时间`使用该时区时间)

jobs:
  build: # 自定义名称
    runs-on: ubuntu-latest # 运行在虚拟机环境ubuntu-latest

    strategy:
      matrix:
        node-version: [14.x]

    steps:
      - name: Checkout # 步骤1
        uses: actions/checkout@v1 # 使用的动作。格式:userName/repoName。作用:检出仓库,获取源码。 官方actions库:https://github.com/actions
      - name: Use Node.js ${{ matrix.node-version }} # 步骤2
        uses: actions/setup-node@v1 # 作用:安装nodejs
        with:
          node-version: ${{ matrix.node-version }} # 版本
      - name: Build-and-deploy # 步骤3
        run: |
          remote_addr=`git remote get-url --push origin`
          commit_info=`git describe --all --always --long`
          user_name=`git log -1 --pretty=format:'%an'`
          user_email=`git log -1 --pretty=format:'%ae'`
          deploy_branch=gh-pages
          yarn
          yarn build
          cd docs/.vuepress/dist
          git config --global init.defaultBranch $deploy_branch
          git init
          git config user.name ${user_name}
          git config user.email ${user_email}
          git add -A
          git commit -m "auto deploy, $commit_info"
          remote_addr=`echo $remote_addr | awk -F'://' '{print $2}'`
          remote_addr=https://${user_name}:${{secrets.GITHUB_TOKEN}}@${remote_addr}
          git remote add origin ${remote_addr}
          git push origin HEAD:$deploy_branch --force # 推送到github $deploy_branch分支
      # 只提交到github pages也可以使用github-pages-deploy-action,详见: https://github.com/JamesIves/github-pages-deploy-action
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49

这个ci.yaml可以直接用。 每次提交过几分钟编译成功后就会在另一个分支提交拉。

这个改版了vuepress官网的github action部署。
${{secrets.GITHUB_TOKEN}}  
// 这就是默认的github的token啦。 
// 不需要额外设置。这是最新版本github自带的token。 不需要设置了。 见下面的文档:
// https://docs.github.com/en/actions/security-guides/automatic-token-authentication

1
2
3
4
5
6

# GitHub Pages设置

  1. 注意 base 设置和仓库名一致。
  2. 注意设置的分支名。
  3. 默认的域名访问,开启page之后。刷新一下就出来了。

# 自定义域名

三步搞定Github Pages自定义域名 (opens new window)

  1. 在域名解析配置cname 指向 对应的github的page域名
  2. 在github page中配置对应Custom domain
  3. 他会自动生成 CNAME 这个文件,同时还会触发github action重新发布,过几分钟就可以访问啦。
  4. 【坑】如果资源报404的话, 这里注意要把base 重新设置为 '/' ,再重新发布。
  5. 【坑】可以再docs.vuepress\public\CNAME 文件中写 自定义的域名(买的域名)

# 博客评论组件 gitalk

五分钟搭建博客评论组件-gitalk (opens new window)

# Github OAuth2.0 的 注册

【坑】回调地址得是 https: [因为github page 里面的回调会转化成https:]

修改Gitalk代理地址,解决无法登录问题 (opens new window)

由于Gitalk配置proxy的默认地址https://cors-anywhere.azm.workers.dev/...被墙了,导致无法登录。 这里需要自己写后端代理接口,不太现实。 还是建议科学上网。

编辑 (opens new window)
#vuepress#github#
上次更新: 2023/01/24, 19:59:48
vue全家桶
uni-app

← vue全家桶 uni-app→

最近更新
01
架构升级踩坑之路
02-27
02
总结
02-27
03
语法学习
02-27
更多文章>
| Copyright © 2021-2025 Wu lingui |
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式