Hexo的Next主题集成RSS可以说是非常简单的一个操作,但也是一个极其容易搞错的操作,这里把失败和成功的过程都分享出来。
[TOC]
失败的操作
安装
执行npm install hexo-generator-feed
,安装成功。
1 | $ cd taoblog |
编辑配置文件
- Hexo站点配置文件添加如下配置
1 | # Extensions |
- NexT主题配置文件添加如下配置
1 | # Set rss to false to disable feed link. |
hexo生成报错
执行hexo g
后报错,如下:
1 | $ hexo clean |
卸载并恢复配置信息
卸载hexo-generator-feed
,删除站点配置文件、主题配置文件中的相关配置后,hexo生成即发布恢复正常。
卸载时的提示如下:
1 | $ npm uninstall hexo-generator-feed |
成功的操作
重点:参考hexo官方Plugins以及hexo-generator-feed插件官方页面的安装与配置指导,顺利完成集成,具体如下。
Generate Atom 1.0 or RSS 2.0 feed.
Install
1 | $ npm install hexo-generator-feed --save |
- Hexo 3: 1.x
- Hexo 2: 0.x
执行结果如下:
1 | $ cd taoblog |
Use
In the front-matter of your post, you can optionally add a description
, intro
or excerpt
setting to write a summary for the post. Otherwise the summary will default to the excerpt or the first 140 characters of the post.
Options
在hexo站点配置文件 _config.yml
中# Extensions字段
的#Plugins: https://hexo.io/plugins/
项下添加如下配置信息,即可完成。
1 | feed: |
- type - Feed type. (atom/rss2)
- path - Feed path. (Default: atom.xml/rss2.xml)
- limit - Maximum number of posts in the feed (Use
0
orfalse
to show all posts) - hub - URL of the PubSubHubbub hubs (Leave it empty if you don’t use it)
- content - (optional) set to ‘true’ to include the contents of the entire post in the feed.
- content_limit - (optional) Default length of post content used in summary. Only used, if content setting is false and no custom post description present.
- content_limit_delim - (optional) If content_limit is used to shorten post contents, only cut at the last occurrence of this delimiter before reaching the character limit. Not used by default.
- order_by - Feed order-by. (Default: -date)
- icon - (optional) Custom feed icon. Defaults to a gravatar of email specified in the main config.
Generate & deploy
1 | $ hexo clean |
原因分析
- 成功操作与失败操作安装的都是同一个版本的Feed插件即
hexo-generator-feed@1.2.2
版本,成功的操作只需配置站点配置文件,而且配置信息与失败操作中参考的配置信息不同,而且并不需要配置主题配置文件。 - 教训:首先要参考官方相关文档,会躲过很多坑。