2023年的博客从hexo
切换到hugo
迁移过程
搭建hugo
新环境
1
2
3
4
5
6
7
| hugo new site mickeyzzcblog
cd mickeyzzcblog
git init
git submodule add https://github.com/hugo-next/hugo-theme-next.git themes/hugo-theme-next
cp themes/hugo-theme-next/exampleSite/config.yaml .
vim config.yaml
hugo server
|
构建github ci
的workflows
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
| name: deploy
on:
push:
workflow_dispatch:
schedule:
# Runs everyday at 8:00 AM
- cron: "0 0 * * *"
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
with:
submodules: true
fetch-depth: 0
- name: Setup Hugo
uses: peaceiris/actions-hugo@v2
with:
hugo-version: "latest"
extended: true
- name: Build Web
run: hugo
- name: Deploy Web
uses: peaceiris/actions-gh-pages@v3
with:
PERSONAL_TOKEN: ${{ secrets.PERSONAL_TOKEN }}
EXTERNAL_REPOSITORY: mickeyzzc/mickeyzzc.github.io
PUBLISH_BRANCH: main
PUBLISH_DIR: ./public
commit_message: ${{ github.event.head_commit.message }}
|
2017年的博客建设
本地搭建hexo
环境
详细步骤请参考官方网站,这里只提及过程中的注意点
- 参考
hexo
在本地安装,我用的是
debian
系统。
在中国境内经常会遇到墙的问题,建议使用
淘宝的cnpm
。
1
| $ npm install -g cnpm --registry=https://registry.npm.taobao.org
|
然后使用cnpm
命令安装hexo-cli
1
| $ cnpm install -g hexo-cli
|
- 个性化的自己的配置,并且在
GitHub
上建立xxx.github.io
库。 - 在
hexo
的本地目录
source
下初始化git库,并在自己的git库上管理。
配置CDN和HTTPS
- 在
hexo
的本地目录
public
下创建CNAME
文件,内容为你的域名。 - 注册
CloudFlare
,
把域名的NS切换到
CloudFlare
管理。
- 在
CloudFlare
的Crypto页中,
SSL设置为Flexible。这将允许CDN到
github pages
之间的访问为http。 - CloudFlare
提供Page Rules功能,
可设置路由规则。通过规则中的
Always use https
选项,可以将用户强制跳转到https。
http://*.mickeyzzc.tech/*
使用Docker
构建Blog
静态文件
- 利用
DOCKERFILE
构建一个本地使用的hexo
镜像.
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
| # MAINTAINER MickeyZZC <[email protected]>
# DOCKER-VERSION 1.13.0
#
FROM node:6
MAINTAINER MickeyZZC <[email protected]>
RUN cp -f /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \
&& npm install -g cnpm --registry=https://registry.npm.taobao.org \
&& cnpm install -g hexo-cli \
&& mkdir -p /home/hexo/public \
&& cd /home/hexo \
&& hexo init \
&& git clone https://github.com/iissnan/hexo-theme-next themes/next \
&& cnpm install hexo-deployer-git --save \
&& git clone https://git.oschina.net/MickeyZZC/MiZDoc.git mickeyblog \
&& cp -f mickeyblog/hexo_config/_config.yml _config.yml \
&& cp -f mickeyblog/hexo_config/themes_next_config.yml themes/next/_config.yml \
&& cp -f mickeyblog/hexo_config/gitconfig.cfg ./.gitconfig \
&& cp -rf mickeyblog/hexo_source/* source/ \
&& rm -rf mickeyblog source/_posts/hello-world.md \
&& chown -R node.node /home/hexo && chown -R node /usr/local/lib/node_modules/ \
&& echo "blog.mickeyzzc.tech" > /home/hexo/public/CNAME \
&& hexo generate \
&& chown -R node.node /home/hexo
ENV HOME /home/hexo
WORKDIR /home/hexo
EXPOSE 4000
USER node
CMD ["hexo","server"]
|
1
2
3
| docker run --rm -p 4000:4000 \
-v $HOME/migit/miBlog:/home/hexo/source\
-it mickeyzzc/node-hexo
|
最后打包合并到GIT库管理
1
2
3
| # git add -A
# git commit -a -s -m "xxxx"
# git push
|