Skip to content

Commit

Permalink
🎉 docs
Browse files Browse the repository at this point in the history
  • Loading branch information
oddfar committed May 26, 2021
0 parents commit 26a9f90
Show file tree
Hide file tree
Showing 138 changed files with 32,988 additions and 0 deletions.
56 changes: 56 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
name: CI

#on: [push]

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

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

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

steps: # 步骤
- name: Checkout # 步骤1
# 使用的动作。格式:userName/repoName。作用:检出仓库,获取源码。 官方actions库:https://github.com/actions
uses: actions/checkout@v1

- name: Use Node.js ${{ matrix.node-version }} # 步骤2
uses: actions/setup-node@v1 # 作用:安装nodejs
with:
node-version: ${{ matrix.node-version }} # 版本
#-------------------------------------------------------------------
- name: Configure Private Key #★★★★★★步骤3:设置ssh
env:
SSH_PRIVATE_KEY: ${{ secrets.GITEE_RSA_PRIVATE_KEY }}
run: |
mkdir -p ~/.ssh
echo "$SSH_PRIVATE_KEY" > ~/.ssh/id_rsa
chmod 600 ~/.ssh/id_rsa
echo "StrictHostKeyChecking no" >> ~/.ssh/config
- name: Push Gitee Mirror #★★★★★★步骤4:推送到gitee
env:
SOURCE_REPO: 'https://github.com/oddfar/docs.git'
DESTINATION_REPO: '[email protected]:oddfar/docs.git'
run: |
git clone --mirror "$SOURCE_REPO" && cd `basename "$SOURCE_REPO"`
git remote set-url --push origin "$DESTINATION_REPO"
git fetch -p origin
git for-each-ref --format 'delete %(refname)' refs/pull | git update-ref --stdin
git push --mirror
#-------------------------------------------------------------------
- name: run deploy.sh # 步骤5:执行脚本deploy.sh
env: # 设置环境变量,未设置则不运行
GITHUB_TOKEN: ${{ secrets.ACCESS_TOKEN }} # toKen私密变量
SSH_PRIVATE_KEY: ${{ secrets.GITEE_RSA_PRIVATE_KEY }} # gitee的ssh

run: npm install && npm run deploy

## ★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★
## 注意:不需要同步到gitee镜像,则把步骤3和4删掉
12 changes: 12 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# npm
package-lock.json
node_modules

# vscode
.vscode

# vuepress
docs/.vuepress/dist

# 百度链接推送
urls.txt
128 changes: 128 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
**Table of Contents** *generated with [DocToc](https://github.com/thlorenz/doctoc)*

- [准备](#%E5%87%86%E5%A4%87)
- [写作](#%E5%86%99%E4%BD%9C)
- [部署](#%E9%83%A8%E7%BD%B2)
- [手动部署到github](#%E6%89%8B%E5%8A%A8%E9%83%A8%E7%BD%B2%E5%88%B0github)
- [自动部署到github](#%E8%87%AA%E5%8A%A8%E9%83%A8%E7%BD%B2%E5%88%B0github)
- [部署到自己服务器](#%E9%83%A8%E7%BD%B2%E5%88%B0%E8%87%AA%E5%B7%B1%E6%9C%8D%E5%8A%A1%E5%99%A8)

<!-- END doctoc generated TOC please keep comment here to allow auto update -->

使用[vuepress](https://vuepress.vuejs.org/zh)搭建,自动部署在[GitHub Pages](https://pages.github.com/)

使用[vdoing](https://github.com/xugaoyi/vuepress-theme-vdoing)主题

## 准备

VuePress 需要 [Node.js ](https://nodejs.org/en/)>= 8.6

1. 克隆到本地并进入目录

```sh
git clone https://github.com/oddfar/docs.git && cd docs
```

2. 安装本地依赖

```sh
npm install
```

3. 本地测试

```sh
npm run dev
```

默认访问链接:http://localhost:8080/doc

## 写作

使用`markdown`语法编写`md`文件,所有笔记`md`文件放在`docs/docs`目录下

例如添加`test`类,并编写`hello.md`文件

1. 创建目录

格式:序号+标题

例如:30.test

2. 添加笔记

例如:01.hello.md

3. 编写内容

```markdown
---
title: 笔记标题
permalink: /test/hello/
date: 2021-01-01 01:01:01
---

## 标题

hello world
```

tittle:标题,不填写则默认文件名中的标题,即`hello`

permalink:访问链接,不填写则自动生成

date:日期,默认文件创建时间

4. 测试运行

在项目根目录下

```sh
npm run dev
```

详情请看[vdoing主题介绍文档](https://doc.xugaoyi.com/)

## 部署

### 手动部署到github

创建分支:`gh-pages`

更改文件`deploy.sh`内容

```sh
[email protected]:oddfar/docs.git
```



```sh
githubUrl=https://oddfar:${GITHUB_TOKEN}@github.com/oddfar/docs.git
```

双击运行`deploy.sh`

之后配置 [GitHub Pages](https://pages.github.com/)

![image-20210517151354287](https://cdn.jsdelivr.net/gh/oddfar/static/img/20210517151356.png)

### 自动部署到github

详情查看:https://github.com/oddfar/docs/blob/master/docs/10.%E5%85%B3%E4%BA%8E/02.%E5%85%B3%E4%BA%8E%20-%20%E6%9C%AC%E7%AB%99/05.%E6%96%87%E6%A1%A3%E7%9A%84%E9%83%A8%E7%BD%B2.md

### 部署到自己服务器

根目录下执行命令

```sh
npm run build
```

生成文件在`docs\.vuepress\dist\`目录下

打包到服务器即可

注:本地不可直接访问,需要配合插件
1 change: 1 addition & 0 deletions base.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = '/'
72 changes: 72 additions & 0 deletions deploy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
#!/usr/bin/env sh

# 确保脚本抛出遇到的错误
set -e

initDist(){
echo $1 > base.js
}



#------------------------------------------

#url访问目录,这个是你 github 仓库的名字
initDist "module.exports = '/docs/'"

# 生成静态文件
npm run build
# 进入生成的文件夹
cd docs/.vuepress/dist

# deploy to github
if [ -z "$GITHUB_TOKEN" ]; then
# 手动部署
msg='deploy'
[email protected]:oddfar/docs.git
else
# 自动部署
msg='来自github actions的自动部署'
githubUrl=https://oddfar:${GITHUB_TOKEN}@github.com/oddfar/docs.git
git config --global user.name "oddfar"
git config --global user.email "[email protected]"
fi
git init
git add -A
git commit -m "${msg}"
git push -f $githubUrl master:gh-pages # 推送到github


cd - # 退回开始所在目录
rm -rf docs/.vuepress/dist

#------------------------------------------


#打包代码同步到 gitee gh-pages分支
if [ -z "$SSH_PRIVATE_KEY" ]; then
echo '如果是空字符串,则不部署到gitee'
else
#url访问目录
initDist "module.exports = '/'"
# 生成静态文件
npm run build
# 进入生成的文件夹
cd docs/.vuepress/dist

[email protected]:oddfar/docs.git #gitee 仓库ssh地址

git config --global user.name "oddfar"
git config --global user.email "[email protected]"
git init
git add -A
git commit -m "来自github actions的自动部署"
git push -f $giteeUrl master:gh-pages

cd - # 退回开始所在目录
rm -rf docs/.vuepress/dist
# 删除秘钥
rm -rf ~/.ssh
fi


Loading

0 comments on commit 26a9f90

Please sign in to comment.