七仔的博客

七仔的博客GithubPages分博

0%

博客新增支持RSS订阅啦~

在建站五年后,终于是把这个古老的RSS订阅功能做了支持。。。

博客新增支持RSS订阅啦~

在建站五年后,终于是把这个古老的RSS订阅功能做了支持。。。

  • 链接地址(订阅源):

https://www.baby7blog.com/feed

  • 另外在博客的顶部和底部也有订阅链接哦:

截图_20240826234837.png

截图_20240826234908.png

  • 如何使用:

在Win下比较方便的就是使用Fluent Reader进行订阅(在设置出添加上方的链接地址为订阅源即可)

1724687662101.png

  • 技术细节

用了一个rss的包,build.gradle:

1
2
// rss订阅
implementation 'com.rometools:rome:1.8.0'

然后是脱敏后的代码:

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
48
49
50
51
52
53
54
55
private String getRss() throws FeedException {
Channel channel = new Channel();
channel.setEncoding("Utf-8"); //不要改动
channel.setFeedType("rss_2.0"); //不要改动
channel.setTitle("博客标题");
channel.setLink("rss订阅地址");
channel.setDescription("博客简介");
channel.setLanguage("zh-cn"); //不要改动
channel.setCopyright("Copyright信息");
channel.setManagingEditor("邮箱(博主)");
channel.setWebMaster("邮箱(博主)");
channel.setUri("博客地址");
channel.setGenerator("由谁构建");

Image image = new Image();
image.setUrl("图标地址");
image.setTitle("博客标题");
image.setHeight(32);
image.setWidth(32);
channel.setImage(image);

// 博客最后更新的时间
Date lastDate = new Date(0L);
// 博客列表(倒序)
List<Blog> blogList = xxxxx.list();
// 结果列表
List<Item> itemList = new ArrayList<>();
for(Blog blog : blogList){
Item item = new Item();
item.setAuthor("博主");
item.setLink("博文地址");
item.setTitle("博文标题");
item.setUri("博文地址");
item.setComments("博文地址");
Date date = XXX; // 写博文的时间
com.rometools.rome.feed.rss.Category category = new com.rometools.rome.feed.rss.Category();
category.setValue("分类");
item.setCategories(Collections.singletonList(category));
// 详情
Description desc = new Description();
desc.setValue("博文XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX");
item.setDescription(desc);
item.setPubDate(date);
itemList.add(item);
// 更新时间
if(lastDate.before(date)){
lastDate = date;
}
}
channel.setItems(itemList);
channel.setLastBuildDate(lastDate);
// 输出
WireFeedOutput output = new WireFeedOutput();
return output.outputString(channel);
}

此为博主副博客,留言请去主博客,转载请注明出处:https://www.baby7blog.com/myBlog/141.html

欢迎关注我的其它发布渠道