diff --git a/docs/en/programming.md b/docs/en/programming.md index 72ca60ebc..328a0c8a7 100644 --- a/docs/en/programming.md +++ b/docs/en/programming.md @@ -82,6 +82,18 @@ Category +## CNCF + +### Category + + + +| Blog | News | Announcements | Reports | +|------|------|---------------|---------| +| blog | news | announcements | reports | + + + ## Codeforces ### Latest contests diff --git a/docs/programming.md b/docs/programming.md index 57c544708..7d6a18bcb 100644 --- a/docs/programming.md +++ b/docs/programming.md @@ -96,6 +96,18 @@ Rated 对象 +## CNCF + +### 栏目 + + + +| Blog | News | Announcements | Reports | +| ---- | ---- | ------------- | ------- | +| blog | news | announcements | reports | + + + ## Codeforces #### 最新比赛 diff --git a/lib/v2/cncf/index.js b/lib/v2/cncf/index.js new file mode 100644 index 000000000..89597dc27 --- /dev/null +++ b/lib/v2/cncf/index.js @@ -0,0 +1,43 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const { parseDate } = require('@/utils/parse-date'); + +const rootURL = 'https://www.cncf.io'; + +module.exports = async (ctx) => { + const cate = ctx.params.cate ?? 'blog'; + const url = `${rootURL}/${cate}/`; + + const response = await got(url); + const $ = cheerio.load(response.data); + const title = $('h1.is-style-page-title').text(); + const list = $('div.post-archive__item') + .map((_index, item) => ({ + title: $(item).find('span.post-archive__title').text().trim(), + link: $(item).find('span.post-archive__title > a').attr('href'), + pubDate: parseDate($(item).find('span.post-archive__item_date').text().split('|')[0]), + })) + .get(); + + const items = await Promise.all( + list.map((item) => + ctx.cache.tryGet(item.link, async () => { + const detailResponse = await got(item.link); + const content = cheerio.load(detailResponse.data); + + content('div.post-author').remove(); + content('div.social-share').remove(); + + item.description = content('article').html(); + + return item; + }) + ) + ); + + ctx.state.data = { + title: `CNCF - ${title}`, + link: url, + item: items, + }; +}; diff --git a/lib/v2/cncf/maintainer.js b/lib/v2/cncf/maintainer.js new file mode 100644 index 000000000..b09f20604 --- /dev/null +++ b/lib/v2/cncf/maintainer.js @@ -0,0 +1,3 @@ +module.exports = { + '/:cate?': ['Fatpandac'], +}; diff --git a/lib/v2/cncf/radar.js b/lib/v2/cncf/radar.js new file mode 100644 index 000000000..d30db6900 --- /dev/null +++ b/lib/v2/cncf/radar.js @@ -0,0 +1,31 @@ +module.exports = { + 'cncf.io': { + _name: 'CNCF', + '.': [ + { + title: 'Blog', + docs: 'https://docs.rsshub.app/programming.html#cncf', + source: ['/blog'], + target: '/cncf/blog', + }, + { + title: 'News', + docs: 'https://docs.rsshub.app/programming.html#cncf', + source: ['/news'], + target: '/cncf/news', + }, + { + title: 'Announcements', + docs: 'https://docs.rsshub.app/programming.html#cncf', + source: ['/announcements'], + target: '/cncf/announcements', + }, + { + title: 'Reports', + docs: 'https://docs.rsshub.app/programming.html#cncf', + source: ['/reports'], + target: '/cncf/reports', + }, + ], + }, +}; diff --git a/lib/v2/cncf/reports.js b/lib/v2/cncf/reports.js new file mode 100644 index 000000000..e4214417d --- /dev/null +++ b/lib/v2/cncf/reports.js @@ -0,0 +1,38 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const { parseDate } = require('@/utils/parse-date'); + +const rootURL = 'https://www.cncf.io'; + +module.exports = async (ctx) => { + const url = `${rootURL}/reports/`; + + const response = await got(url); + const $ = cheerio.load(response.data); + const list = $('div.report-item') + .map((_index, item) => ({ + title: $(item).find('a.report-item__link').attr('title'), + link: $(item).find('a.report-item__link').attr('href'), + })) + .get(); + + const items = await Promise.all( + list.map((item) => + ctx.cache.tryGet(item.link, async () => { + const detailResponse = await got(item.link); + const content = cheerio.load(detailResponse.data); + + item.parseDate = parseDate(content('p.is-style-spaced-uppercase').splice(':')[1]); + item.description = content('article > div.has-background').html(); + + return item; + }) + ) + ); + + ctx.state.data = { + title: `CNCF - Reports`, + link: url, + item: items, + }; +}; diff --git a/lib/v2/cncf/router.js b/lib/v2/cncf/router.js new file mode 100644 index 000000000..9d730a432 --- /dev/null +++ b/lib/v2/cncf/router.js @@ -0,0 +1,4 @@ +module.exports = function (router) { + router.get('/reports', require('./reports')); + router.get('/:cate?', require('./index')); +};