默认的 vuepress 程序没有集成 rss 订阅能力,不过第三方有插件集成了相应的能力,本文来介绍下如何通过插件来为博客集成 rss 订阅能力。

# 插件信息

# 安装

$ npm install -D vuepress-plugin-feed

# or

$ yarn add -D vuepress-plugin-feed

1
2
3
4
5

# 配置

docs/.vuepress/config.js 中进行如下配置:

// set your global feed options - override in page frontmatter `feed`
const feed_options = {
  canonical_base: "https://wiki.eryajf.net",
  count: 5000,
};

module.exports = {
  plugins: [["feed", feed_options]],
};

1
2
3
4
5
6
7
8
9

此处之所以将 count 配置为 5000,是因为该插件生成的 rss 记录并非按时间序列,因此如果你配置为 20,而文章有 100 篇都应用了 rss,此时可能最新更新的文章并不会出现在 rss 记录中,也就违背了 rss 的意义。因此这里可以给一个相对大一点的值,超过文章数量就可以了。

如上简单的配置信息已经足够使用,如果需要更多的配置信息,可以参考插件的:官方文档 (opens new window)

# 使用

注意,插件会取文章的 frontmatter 信息来判断是否将文章放到 rss 记录中,因此写文章的时候,需要在文章的 frontmatter 中添加如下内容(最后三行):

---
title: 学习周刊-总第91期-2023年第04周
date: 2023-01-27 16:05:44
permalink: /pages/644c4d/
categories:
  - 周刊
  - 学习周刊
  - 2023年
tags:
  -
feed:
  enable: true
description: 如要阅读全文,点击标题跳转。学习周刊-总第91期-一个开源的Git客户端
---

1
2
3
4
5
6
7
8
9
10
11
12
13
14

然后编译的时候才会将对应的文章放入到 rss 记录当中。

插件还提供了更丰富的能力来作为判断依据,感兴趣的同学同样可以依据官方文档来进行配置,我的博客是根据如上流程步骤进行配置的。