@@ -5,8 +5,13 @@ const xmlParser = require("fast-xml-parser");
55const RSS_LINKS_CONFIG_KEY = 'allblog.rssLinks' ;
66const RSS_LINK_REGEX = / ^ ( h t t p s ? | f t p ) : \/ \/ [ ^ \s / $ . ? # ] .[ ^ \s ] * $ / ;
77
8+ // 记录每个 RSS 的最新文章链接
9+ const latestArticleLinks = { } ;
10+
11+ // 定时检查 RSS 更新的时间间隔(毫秒)
12+ const RSS_CHECK_INTERVAL = 3600000 ; // 1小时
13+
814async 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 } ,
0 commit comments