From 72d768ab0be54dded50c5cb9871a5c0cd535bcac Mon Sep 17 00:00:00 2001 From: Tony Date: Thu, 21 Jul 2022 08:01:36 -0700 Subject: [PATCH] feat(route): cpuid (#10290) * feat(route): cpuid * fix: add data.link --- docs/en/program-update.md | 6 ++++++ docs/program-update.md | 6 ++++++ lib/v2/cpuid/news.js | 30 ++++++++++++++++++++++++++++++ lib/v2/cpuid/radar.js | 13 +++++++++++++ lib/v2/cpuid/router.js | 3 +++ 5 files changed, 58 insertions(+) create mode 100644 lib/v2/cpuid/news.js create mode 100644 lib/v2/cpuid/radar.js create mode 100644 lib/v2/cpuid/router.js diff --git a/docs/en/program-update.md b/docs/en/program-update.md index 8bfa1a7b99..9ae52221e1 100644 --- a/docs/en/program-update.md +++ b/docs/en/program-update.md @@ -120,6 +120,12 @@ Language +## CPUID + +### News + + + ## CurseForge ### File Update diff --git a/docs/program-update.md b/docs/program-update.md index f7db033a04..034ede492c 100644 --- a/docs/program-update.md +++ b/docs/program-update.md @@ -146,6 +146,12 @@ pageClass: routes +## CPUID + +### 新闻 + + + ## cpython ### 正式版本发布 diff --git a/lib/v2/cpuid/news.js b/lib/v2/cpuid/news.js new file mode 100644 index 0000000000..b7eaed9dbb --- /dev/null +++ b/lib/v2/cpuid/news.js @@ -0,0 +1,30 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const { parseDate } = require('@/utils/parse-date'); +const newsUrl = 'https://www.cpuid.com/news.html'; + +module.exports = async (ctx) => { + const response = await got(newsUrl); + const $ = cheerio.load(response.data); + + const items = $('.block_100 .js-block-news') + .toArray() + .map((item) => { + item = $(item); + return { + title: item.find('.information a').text(), + description: item.find('.description').html(), + link: item.find('.information a').attr('href'), + pubDate: parseDate(item.find('time[itemprop=dateCreated]').attr('datetime')), + }; + }); + + ctx.state.data = { + title: $('head title').text(), + description: $('head description').attr('content'), + link: newsUrl, + image: $('link[rel=apple-touch-icon-precomposed]').attr('href'), + item: items, + language: $('html').attr('lang'), + }; +}; diff --git a/lib/v2/cpuid/radar.js b/lib/v2/cpuid/radar.js new file mode 100644 index 0000000000..ade1552548 --- /dev/null +++ b/lib/v2/cpuid/radar.js @@ -0,0 +1,13 @@ +module.exports = { + 'cpuid.com': { + _name: 'CPUID', + '.': [ + { + title: 'News', + docs: 'https://docs.rsshub.app/program-update.html#cpuid', + source: ['/news.html', '/'], + target: '/cpuid/news', + }, + ], + }, +}; diff --git a/lib/v2/cpuid/router.js b/lib/v2/cpuid/router.js new file mode 100644 index 0000000000..630036b8e4 --- /dev/null +++ b/lib/v2/cpuid/router.js @@ -0,0 +1,3 @@ +module.exports = (router) => { + router.get('/news', require('./news')); +};