持续集成hexo博客到github

一、本地安装hexo并启动

1.本地安装
node.js: https://nodejs.org/dist/v12.18.2/node-v12.18.2-x64.msi
git: https://github.com/git-for-windows/git/releases/download/v2.27.0.windows.1/Git-2.27.0-64bit.exe
cnpm: npm install -g cnpm --registry=http://registry.npm.taobao.org
hexo:cnpm install -g hexo-cli

2.安装基础软件后查看版本

admin@DESKTOP-29F07JR MINGW64 ~/Desktop
$ git --version
git version 2.27.0.windows.1

admin@DESKTOP-29F07JR MINGW64 ~/Desktop
$ npm -v
6.14.5

admin@DESKTOP-29F07JR MINGW64 ~/Desktop
$ node -v
v12.18.2

admin@DESKTOP-29F07JR MINGW64 ~/Desktop
$ cnpm -v
cnpm@6.1.1 (C:\Users\admin\AppData\Roaming\npm\node_modules\cnpm\lib\parse_argv.js)
npm@6.14.6 (C:\Users\admin\AppData\Roaming\npm\node_modules\cnpm\node_modules\npm\lib\npm.js)
node@12.18.2 (C:\Program Files\nodejs\node.exe)
npminstall@3.27.0 (C:\Users\admin\AppData\Roaming\npm\node_modules\cnpm\node_modules\npminstall\lib\index.js)
prefix=C:\Users\admin\AppData\Roaming\npm
win32 x64 10.0.14393
registry=https://r.npm.taobao.org

admin@DESKTOP-29F07JR MINGW64 /d/Myblog
$ hexo -v
hexo-cli: 3.1.0
os: Windows_NT 10.0.14393 win32 x64
node: 12.18.2
v8: 7.8.279.23-node.39
uv: 1.38.0
zlib: 1.2.11
brotli: 1.0.7
ares: 1.16.0
modules: 72
nghttp2: 1.41.0
napi: 6
llhttp: 2.0.4
http_parser: 2.9.3
openssl: 1.1.1g
cldr: 37.0
icu: 67.1
tz: 2019c
unicode: 13.0

3.初始化博客并启动

#git设置代理
git config --global http.proxy localhost:1080
git config --global --unset http.proxy

#创建博客目录
mkdir /d/Blog
cd /d/Blog

#生成博客页面
$ hexo init blog/

#启动hexo
admin@DESKTOP-29F07JR MINGW64 /d/blog
$ hexo s
INFO  Start processing
INFO  Hexo is running at http://localhost:4000 . Press Ctrl+C to stop.

4.更换blog主题

#下载主题
git clone https://github.com/theme-next/hexo-theme-next themes/next

#修改配置文件
admin@DESKTOP-29F07JR MINGW64 /d/blog
$ grep  "theme" _config.yml
## Themes: https://hexo.io/themes/
theme: next

#重新生成hexo页面
hexo clean
hexo g
hexo s

#选择next主题风格
admin@DESKTOP-29F07JR MINGW64 /d/blog/themes/next (master)
$ grep "scheme" _config.yml
#scheme: Muse
#scheme: Mist
#scheme: Pisces
scheme: Gemini
# Custom Logo (Do not support scheme Mist)
# To avoid space between header and sidebar in scheme Pisces / Gemini, Web Safe fonts are recommended for `global` (and `title`):

二、部署hexo到github

创建github仓库

https://github.com/lanzhw5/lanzhw5.github.io.git

添加ssh密钥到github

ssh-keygen.exe -t rsa -C "lanzhw5@gmail.com"
cd /c/Users/admin/.ssh/
shh -T -v git@github.com

配置env

git config --global http.proxy localhost:1080
git config --global user.email "lanzhw5@gmail.com"
git config --global user.name "lanzhw5"

部署hexo到github

#安装部署插件
admin@DESKTOP-29F07JR MINGW64 /d/blog
$ cnpm install --save hexo-deployer-git

#配置_config设置github仓库
admin@DESKTOP-29F07JR MINGW64 /d/blog
$ grep -a2 "deploy" _config.yml
deploy:
  type: git
  repo: https://github.com/lanzhw5/lanzhw5.github.io.source.git
  
#生成页面并部署到github
hexo clean
hexo g
hexo d

三、hexo持续集成

1.配置环境变量

http://feg.netease.com/archives/634.html

name value
STATIC_SITE_REPO https://github.com/lanzhw5/lanzhw5.github.io
TARGET_BRANCH master
GIT_USER_EMAIL lanzhw5@gmail.com
GIT_USER_NAME lanzhw5

2.配置appveyor

clone_depth: 5
 
environment:
  nodejs_version: "6"
  access_token:
    secure: jPcVZ4WRDm97S4+5IqH0M/l4Bb+/m8xtCtyU1uff0Kqj3aaFZETme4KU2OqS7YPL
 
install:
  - ps: Install-Product node $env:nodejs_version
  - node --version
  - npm --version
  - npm install
  - npm install hexo-cli -g
 
build_script:
  - hexo generate
 
artifacts:
  - path: public
 
on_success:
  - git config --global credential.helper store
  - ps: Add-Content "$env:USERPROFILE\.git-credentials" "https://$($env:access_token):x-oauth-basic@github.com`n"
  - git config --global user.email "%GIT_USER_EMAIL%"
  - git config --global user.name "%GIT_USER_NAME%"
  - git clone --depth 5 -q --branch=%TARGET_BRANCH% %STATIC_SITE_REPO% %TEMP%\static-site
  - cd %TEMP%\static-site
  - del * /f /q
  - for /d %%p IN (*) do rmdir "%%p" /s /q
  - SETLOCAL EnableDelayedExpansion & robocopy "%APPVEYOR_BUILD_FOLDER%\public" "%TEMP%\static-site" /e & IF !ERRORLEVEL! EQU 1 (exit 0) ELSE (IF !ERRORLEVEL! EQU 3 (exit 0) ELSE (exit 1))
  - git add -A
  - if "%APPVEYOR_REPO_BRANCH%"=="master" if not defined APPVEYOR_PULL_REQUEST_NUMBER (git diff --quiet --exit-code --cached || git commit -m "Update Static Site" && git push origin %TARGET_BRANCH% && appveyor AddMessage "Static Site Updated")
posted @ 2020-07-23 01:02  深入决定深度  阅读(228)  评论(0)    收藏  举报