Skip to content

Commit 1ad2a54

Browse files
committed
feat:RSS Update Alerts
1 parent 67698b2 commit 1ad2a54

2 files changed

Lines changed: 44 additions & 16 deletions

File tree

extension.js

Lines changed: 43 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,13 @@ const xmlParser = require("fast-xml-parser");
55
const RSS_LINKS_CONFIG_KEY = 'allblog.rssLinks';
66
const RSS_LINK_REGEX = /^(https?|ftp):\/\/[^\s/$.?#].[^\s]*$/;
77

8+
// 记录每个 RSS 的最新文章链接
9+
const latestArticleLinks = {};
10+
11+
// 定时检查 RSS 更新的时间间隔(毫秒)
12+
const RSS_CHECK_INTERVAL = 3600000; // 1小时
13+
814
async function activate(context) {
9-
// 获取保存的RSS链接列表,如果为空则初始化为空对象
1015
let rssLinks = context.globalState.get(RSS_LINKS_CONFIG_KEY, {});
1116

1217
async function parseArticles(link) {
@@ -49,23 +54,46 @@ async function activate(context) {
4954

5055
let height = parseInt(heightInput) || 500;
5156
webViewPanel.webview.html = `
52-
<!DOCTYPE html>
53-
<html>
54-
<head>
55-
<style>
56-
body {
57-
font-family: Arial, sans-serif;
58-
}
59-
</style>
60-
</head>
61-
<body>
62-
<iframe src="${link}" width="100%" height="${height}px"></iframe>
63-
</body>
64-
</html>
65-
`;
57+
<!DOCTYPE html>
58+
<html>
59+
<head>
60+
<style>
61+
body {
62+
font-family: Arial, sans-serif;
63+
}
64+
</style>
65+
</head>
66+
<body>
67+
<iframe src="${link}" width="100%" height="${height}px"></iframe>
68+
</body>
69+
</html>
70+
`;
6671
}
6772
}
6873

74+
// 定时检查 RSS 更新
75+
setInterval(async () => {
76+
for (const rssLink in rssLinks) {
77+
const response = await axios.get(rssLink);
78+
const articles = xmlParser.parse(response.data).rss.channel.item;
79+
80+
// 获取当前 RSS 的最新文章链接
81+
let latestArticleLink = latestArticleLinks[rssLink];
82+
if (!latestArticleLink) {
83+
latestArticleLink = articles[0].link; // 默认取第一篇文章
84+
}
85+
86+
// 检查是否有新文章
87+
const newArticles = articles.filter(article => article.link !== latestArticleLink);
88+
if (newArticles.length > 0) {
89+
latestArticleLinks[rssLink] = newArticles[0].link; // 更新最新文章链接
90+
91+
// 提示用户有新文章
92+
vscode.window.showInformationMessage(`${rssLinks[rssLink]} 更新了文章`);
93+
}
94+
}
95+
}, RSS_CHECK_INTERVAL);
96+
6997
let disposable = vscode.commands.registerCommand('allblog.searchBlog', async () => {
7098
const choiceItems = [
7199
{ label: 'Add new RSS link', isNew: true },

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"publisher": "isolcat",
55
"description": "Turn VScode into your personal RSS reader!",
66
"icon": "docs/Logo.png",
7-
"version": "0.0.6",
7+
"version": "0.0.7",
88
"engines": {
99
"vscode": "^1.82.0"
1010
},

0 commit comments

Comments
 (0)