插件引入

因为我只需要bangumis的追番数据,所以用的不是大多数人用的**hexo-bilibili-bangumi**插件,我使用的是hexo-bangumis插件,其实区别不大,这里附上参考文献[1]

安装

1
$ cnpm install hexo-bangumis --save

将下面的配置写入 站点 的配置文件 _config.yml 中:

1
2
3
4
5
6
7
8
9
10
11
12
13
bangumis:
enable: true # 是否启用
path: bangumis/index.html # 生成追番页面的路径
show: 1 # 想看,在看,看完
title: '追番列表' # 标题
quote: '生命不息,追番不止' # 格言
color_meta: "#555" # 追番项元数据的颜色
color_summary: "#555" # 追番项简介的颜色
bgmtv_uid: mmdjiji # bgm.tv的uid
download_image: true # 下载图片并使用本地图片,否则使用bgm.tv提供的网络图源
image_level: c # 图片高清等级 (l, c, m, s, g)
lazyload: true # 是否开启懒加载
margin: 20px # 封面图的偏移量微调

插件可以下载图片到本地,就算bangumis寄了也没影响,只是不能更新数据,bgmtv_uid填自己的uid,F12进入控制台,输入 CHOBITS_UID 后按回车,得到的数字就是 uid

更新追番数据

插件会自动爬取你在看 已看 想看的番剧,所以这一步得自己手点添加😅😅,然后更新追番数据就行

1
$ hexo bangumis -u

删除数据是:

1
$ hexo bangumis -d

优化工作流

在bangumi一顿手点完之后,我们还得手动更新追番数据,手动构建博客再push上去才能更新

这未免太过繁琐,所以这里可以将手点之后的工作实现自动化

  1. .github/workflows'目录里创建 auto-update.yml文件,

  2. 复制以下内容到文件内

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
42
43
44
45
46
47
name: Auto update
on:
workflow_dispatch:
schedule:
- cron: '0 0 * * *' # Every day

jobs:
meta:
name: Update meta
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- name: Checkout
uses: actions/checkout@v3
with:
ref: main

- name: Do meta update
shell: bash
run: |
npm install
npx hexo bangumis -u || echo

- name: Commit files
run: |
git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com"
git config --local user.name "github-actions[bot]"
git add .
git commit -m "Update meta on $(date '+%Y-%m-%d %H:%M:%S')" || echo

- name: Push changes
uses: ad-m/github-push-action@master
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
branch: ${{ github.ref }}

- name: Do build
shell: bash
run: |
npm run build

- name: Deploy 🚀
uses: JamesIves/github-pages-deploy-action@releases/v3
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
BRANCH: gh-pages # The branch the action should deploy to.
FOLDER: public # The folder the action should deploy.

小tips

每次都要输入老三样[2]多少有点繁琐,我们可以在package.json文件里加入自己的命令,可以参考以下我的

1
2
3
4
5
6
7
8
9
"scripts": {
"build": "hexo generate",
"clean": "hexo clean",
"deploy": "hexo deploy",
"server": "hexo server",
"devs": "hexo cl && hexo generate && hexo s -p 8000",
"dev": "hexo bangumis -u && hexo generate && hexo s -p 8000",
"up": "hexo algolia && hexo cl && hexo generate && hexo s -p 8000"
},

我自己加的快捷命令dev用的不多,因为已经自动化了🤣

老三样直接用自己设置的快捷命令就行

1
npm run devs

  1. ↩︎
  2. hexo cl;hexo generate;hexo s ↩︎