若此方法不适用:node 版本过低导致,可以下个 nvm 来控制 node 版本,建议安装较新的 node 版本(要求大于v18)

在Hexo博客中添加豆瓣插件

1. 安装豆瓣插件

前往博客根目录,打开cmd命令窗口执行npm install hexo-douban —save

1
npm install hexo-douban --save

2.注入豆瓣内容

修改站点配置文件_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
24
25
douban:
id: 228172215
builtin: false
item_per_page: 10
book:
path: books/index.html
title: 'This is my book title'
quote: 'This is my book quote'
option:
movie:
path: movies/index.html
title: 'This is my movie title'
quote: 'This is my movie quote'
option:
game:
path: games/index.html
title: 'This is my game title'
quote: 'This is my game quote'
option:
song:
path: songs/index.html
title: 'This is my song title'
quote: 'This is my song quote'
option:
timeout: 10000
  • id: 你的豆瓣ID(纯数字格式,不是自定义的域名)。获取方法可以参考 怎样获取豆瓣的数字 ID ?
  • builtin: 是否将 hexo douban 命令默认嵌入进 hexo g、hexo s,使其自动执行 hexo douban 命令。默认关闭。当你的豆瓣条目较多时,也建议关闭。
  • item_per_page: 每页展示的条目数,默认 10 。
  • path: 生成页面后的路径,默认生成在 movies/index.html 等下面。如需自定义路径,则可以修改这里。
  • title: 该页面的标题。
  • quote: 写在页面开头的一段话,支持 html 语法。
  • option: 该页面额外的 Front-matter 配置,参考 Hexo 文档。无特别需要,留空即可。
  • timeout: 爬取数据的超时时间,默认是 10000ms ,如果在使用时发现报了超时的错(ETIMEOUT)可以把这个数据设置的大一点。

3.主题中注入豆瓣

在主题配置文件_config.butterfly.yml中配置以下内容:

1
2
3
4
5
6
# 如果你有使用hexo-douban,可配置這個
douban:
meta: true
movies_img: https://fastly.jsdelivr.net/gh/jerryc127/butterfly_cdn@2.1.0/top_img/movie.jpg
books_img: https://fastly.jsdelivr.net/npm/blog-gallery@1.0.0/1/20200206161657.webp
# games_img:

4.执行Docs命令

前往博客根目录,打开cmd命令窗口执行hexo douban

1
hexo douban

等待命令执行完毕,出现下图所示内容即为成功。

我的博客只添加了电影页面

  • collect代表看过
  • wish代表想看
  • do代表在看
  • 括号中的数字代表影片数量,与你豆瓣档案里的一致

5.添加相关导航

如下图:

效果展示