title: 【记录】在 GitHub 上 搭建 Hexo urlname: -ji-lu--zai-GitHub-shang-da-jian-Hexo date: 2023-08-30 21:07:42 tags: ['Github', 'hexo', 'butterfly']
conda activate node
npm i hexo-cli -g
hexo -v
hexo init
npm install
npm install hexo-deployer-git --save
echo hexo.limour.top > source/CNAME
建立 <github usrname>.github.io
的仓库
仓库新建 gh-pages
分支
按 hexo-deployer-git 的指引获取 token
编辑 _config.yml
,添加内容如下
deploy:
type: git
repo: https://oauth2:ghp_xxxxx@xxx.limour.top/xxx/https://github.com/limour-blog/limour-blog.github.io.git
branch: gh-pages
token: ghp_xxxxx
name: xxx@limour.top # 注册 Github 的邮箱
email: xxx@limour.top # 注册 Github 的邮箱
npm install hexo-theme-butterfly --save
npm install hexo-renderer-pug hexo-renderer-stylus --save
mkdir scripts && touch scripts/CDN.js
编辑 _config.yml
,修改内容如下
theme: butterfly
编辑 scripts/CDN.js
,内容如下
'use strict';
const { filter } = hexo.extend;
// 替换 CDN
filter.register('before_generate', () => {
const { asset } = hexo.theme.config;
for (const name in asset) {
asset[name] = asset[name]
.replace('//cdn.jsdelivr.net/', '//你自己的反代/');
}
}, 99);
rm -rf .deploy_git && hexo c && hexo g && hexo d
编辑 .gitignore
,添加 _config.yml
git init && git branch -m main
git remote add origin https://oauth2:ghp_xxxxx@xxx.limour.top/xxx/https://github.com/limour-blog/limour-blog.github.io.git
git add . && git commit -m 'backup' && git push -u origin +main
0.0.0.0/0
2.2.12 or later
npm i hexo-filter-links --save
去 _config.yml
添加配置
links:
enable: true
field: "post"
exclude:
- "limour.top"
- "*.limour.top" #1.0.4及以上版本支持
cd ~/base/NGPM/data
git clone --depth=1 -b gh-pages --single-branch https://github.com/limour-blog/limour-blog.github.io.git
location / {
gzip on;
gzip_min_length 256;
gzip_comp_level 2;
gzip_types text/plain application/javascript application/x-javascript text/css application/xml text/javascript application/x-httpd-php image/jpeg image/gif image/png application/vnd.ms-fontobject font/ttf font/opentype font/x-woff image/svg+xml;
gzip_vary on;
gzip_buffers 32 4k;
if (!-e $request_filename){
rewrite ^(.*)$ /$1.html last;
break;
}
root /data/limour-blog.github.io;
index index.html index.htm;
error_page 404 /404.html;
}
后续更新
cd ~/base/NGPM/data/limour-blog.github.io
git fetch --depth=1 -f && git reset --hard origin/gh-pages