From c2fdbb5df10518798ba3a08ef1143511549289a0 Mon Sep 17 00:00:00 2001 From: Tony Date: Sun, 23 Jan 2022 03:01:44 +0700 Subject: [PATCH] feat(route): add firefox monitor (#8680) --- docs/en/other.md | 6 +++ docs/other.md | 6 +++ lib/v2/firefox/index.js | 65 ++++++++++++++++++++++++ lib/v2/firefox/maintainer.js | 3 ++ lib/v2/firefox/radar.js | 13 +++++ lib/v2/firefox/router.js | 3 ++ lib/v2/firefox/templates/description.art | 5 ++ 7 files changed, 101 insertions(+) create mode 100644 lib/v2/firefox/index.js create mode 100644 lib/v2/firefox/maintainer.js create mode 100644 lib/v2/firefox/radar.js create mode 100644 lib/v2/firefox/router.js create mode 100644 lib/v2/firefox/templates/description.art diff --git a/docs/en/other.md b/docs/en/other.md index ea9355faff..b61119bb1e 100644 --- a/docs/en/other.md +++ b/docs/en/other.md @@ -142,6 +142,12 @@ Official Website: +## Mozilla + +### Firefox Monitor + + + ## Nobel Prize ### List diff --git a/docs/other.md b/docs/other.md index f65440f13f..d6ed2aded4 100644 --- a/docs/other.md +++ b/docs/other.md @@ -206,6 +206,12 @@ pageClass: routes +## Mozilla + +### Firefox Monitor + + + ## NOI 全国青少年信息学奥林匹克竞赛 ### 新闻 diff --git a/lib/v2/firefox/index.js b/lib/v2/firefox/index.js new file mode 100644 index 0000000000..7809c5760f --- /dev/null +++ b/lib/v2/firefox/index.js @@ -0,0 +1,65 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const { parseDate } = require('@/utils/parse-date'); +const timezone = require('@/utils/timezone'); +const { art } = require('@/utils/render'); +const path = require('path'); + +module.exports = async (ctx) => { + const baseUrl = 'https://monitor.firefox.com'; + + const response = await got({ + url: baseUrl + '/breaches', + header: { + Referer: baseUrl, + }, + }); + + const $ = cheerio.load(response.body); + + const list = JSON.parse($('div#breach-array-json').attr('data-breach-array')).breaches.map((item) => ({ + title: item.Title, + link: baseUrl + '/breach-details/' + item.Name, + pubDate: timezone(parseDate(item.AddedDate), 0), + category: item.DataClasses.split(', '), + })); + + const items = await Promise.all( + list && + list.map((item) => + ctx.cache.tryGet(item.link, async () => { + const article = await got({ + url: item.link, + header: { + Referer: baseUrl + '/breaches', + }, + }); + const content = cheerio.load(article.body); + + item.description = art(path.join(__dirname, 'templates/description.art'), { + header: content('#breach-detail').html(), + overview: content('section.detail-section.jst-cntr.flx.flx-col').html(), + dataClasses: content('section.detail-section.bg-white.jst-cntr.flx.flx-col').html(), + }); + + return item; + }, 31536000) + ) + ); + + ctx.state.data = { + title: $('title').text(), + link: baseUrl, + description: String($('head meta[name=description]').attr('content').trim()), + item: items, + image: $('head meta[property=og:image]').attr('content'), + }; + + ctx.state.json = { + title: $('title').text(), + link: baseUrl, + description: String($('head meta[name=description]').attr('content').trim()), + item: items, + image: $('head meta[property=og:image]').attr('content'), + }; +}; diff --git a/lib/v2/firefox/maintainer.js b/lib/v2/firefox/maintainer.js new file mode 100644 index 0000000000..90f425f1c1 --- /dev/null +++ b/lib/v2/firefox/maintainer.js @@ -0,0 +1,3 @@ +module.exports = { + '/breaches': ['TonyRL'], +}; diff --git a/lib/v2/firefox/radar.js b/lib/v2/firefox/radar.js new file mode 100644 index 0000000000..a04fc29e8f --- /dev/null +++ b/lib/v2/firefox/radar.js @@ -0,0 +1,13 @@ +module.exports = { + 'firefox.com': { + _name: 'Mozilla', + monitor: [ + { + title: 'Firefox Monitor', + docs: 'https://docs.rsshub.app/other.html#mozilla', + source: ['/', '/breaches'], + target: '/firefox/breaches', + }, + ], + }, +}; diff --git a/lib/v2/firefox/router.js b/lib/v2/firefox/router.js new file mode 100644 index 0000000000..46dacc2eb0 --- /dev/null +++ b/lib/v2/firefox/router.js @@ -0,0 +1,3 @@ +module.exports = function (router) { + router.get('/breaches', require('./index')); +}; diff --git a/lib/v2/firefox/templates/description.art b/lib/v2/firefox/templates/description.art new file mode 100644 index 0000000000..fff86f8ef3 --- /dev/null +++ b/lib/v2/firefox/templates/description.art @@ -0,0 +1,5 @@ +{{@ header }} +
+{{@ overview }} +
+{{@ dataClasses }}