Github分支管理

曾经练习过git的相关命令,而今忘的差不多了。

简单粗暴:把之前的lucifer9735.github.io仓库删除重建。

master

1
2
3
4
5
6
7
cd myblog
git init
git remote add origin [email protected]:lucifer9735/lucifer9735.github.io.git
echo 'myblog' > README.md
git add .
git commit -m 'myblog source'
git push -u origin master

ghpages

通过github页面在当前仓库创建ghpages分支:

创建ghpages分支

本地修改myblog/_config.yml文件中的部署分支:

1
2
3
4
deploy:
type: git
repo: [email protected]:lucifer9735/lucifer9735.github.io.git
branch: ghpages

执行hexo clean && hexo g && hexo d即可把博客内容部署到ghpages分支。

修改GitHub Pages源分支

修改到ghpages分支

到这儿就完成了本地博客源文件的备份(不包含Hexo环境)。

⚠️注意 不要合并这两个分支!

日常更新文章

1
2
3
4
5
cd myblog
hexo clean && hexo g && hexo d
git add .
git commit -m 'new post'
git push

Github Actions

之前的博客使用travis-CI更新,而今Github推出了Actions功能,尝试一下。

生成公私钥

1
ssh-keygen -t ed25519 -f hexoci -C "[email protected]" -N ""

仅供该仓库使用,配置成功后甚至在本地删除。

上传公私钥

公钥:

公钥上传

私钥:

私钥上传

创建Actions配置文件

myblog/.github/workflows/HexoCI.yml:

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
name: HexoCI

on:
push:
branches:
- master

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: '14'
- uses: actions/cache@v2
with:
path: node_modules
key: ${{ runner.OS }}-npm-cache
restore-keys: |
${{ runner.OS }}-npm-cache

- name: Setup Hexo
env:
HEXO_DEPLOY_PRIVATE_KEY: ${{ secrets.HEXOCI }}
run: |
mkdir -p ~/.ssh/
echo "$HEXO_DEPLOY_PRIVATE_KEY" > ~/.ssh/id_rsa
chmod 600 ~/.ssh/id_rsa
ssh-keyscan github.com >> ~/.ssh/known_hosts
git config --global user.name "lucifer9735"
git config --global user.email "[email protected]"
npm install hexo-cli -g
npm install

- name: Hexo deploy
run: |
hexo clean
hexo generate
hexo deploy

What’s more

1
alias hh="git add . && git commit -m 'update' && git push"
1
2
source ~/.zshrc
hh

永久链接

使用插件hexo-abbrlink生成永久链接。

Hexo根目录安装该插件:

1
npm install hexo-abbrlink --save

修改myblog/_config.yml配置:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# URL
## Set your site url here. For example, if you use GitHub Page, set url as 'https://username.github.io/project'
url: https://foopi.top
permalink: posts/:abbrlink/
permalink_defaults:
pretty_urls:
trailing_index: true # Set to false to remove trailing 'index.html' from permalinks
trailing_html: true # Set to false to remove trailing '.html' from permalinks

# abbrlink config
abbrlink:
alg: crc32 #support crc16(default) and crc32
rep: hex #support dec(default) and hex
drafts: false #(true)Process draft,(false)Do not process draft. false(default)
# Generate categories from directory-tree
# depth: the max_depth of directory-tree you want to generate, should > 0
auto_category:
enable: true #true(default)
depth: #3(default)
over_write: false
auto_title: false #enable auto title, it can auto fill the title by path
auto_date: false #enable auto date, it can auto fill the date by time today
force: false #enable force mode,in this mode, the plugin will ignore the cache, and calc the abbrlink for every post even it already had abbrlink.

Gulp压缩

参考Butterfly主题的文档

SEO

SEO(Search Engine Optimization):汉译为搜索引擎优化。是一种方式:利用搜索引擎的规则提高网站在有关搜索引擎内的自然排名。目的是让其在行业内占据领先地位,获得品牌收益。很大程度上是网站经营者的一种商业行为,将自己或自己公司的排名前移。

nofollow

使用插件hexo-filter-nofollow优化外链,有效加强网站SEO,防止权重流失。

1
npm install hexo-filter-nofollow --save
1
2
3
4
5
6
nofollow:
enable: true
field: site
exclude:
- 'exclude1.com'
- 'exclude2.com'