Skip to content

Commit

Permalink
feat(route): add CNCF (DIYgod#9790)
Browse files Browse the repository at this point in the history
* feat(route): add CNCF

* Update docs/en/programming.md

Co-authored-by: Tony <[email protected]>

* Update docs/programming.md

Co-authored-by: Tony <[email protected]>

* Update lib/v2/cncf/maintainer.js

Co-authored-by: Tony <[email protected]>

Co-authored-by: Tony <[email protected]>
  • Loading branch information
Fatpandac and Tony authored May 20, 2022
1 parent 950bfa6 commit e1347b3
Show file tree
Hide file tree
Showing 7 changed files with 143 additions and 0 deletions.
12 changes: 12 additions & 0 deletions docs/en/programming.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,18 @@ Category

<RouteEn author="elxy" example="/bitmovin/blog" path="/bitmovin/blog"/>

## CNCF

### Category

<RouteEn author="Fatpandac" example="/cncf" path="/cncf/:cate?" radar="1" rssbud="1" :paramsDesc="['blog by default']">

| Blog | News | Announcements | Reports |
|------|------|---------------|---------|
| blog | news | announcements | reports |

</RouteEn>

## Codeforces

### Latest contests
Expand Down
12 changes: 12 additions & 0 deletions docs/programming.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,18 @@ Rated 对象

<Route author="elxy" example="/bitmovin/blog" path="/bitmovin/blog"/>

## CNCF

### 栏目

<Route author="Fatpandac" example="/cncf" path="/cncf/:cate?" :paramsDesc="['默认为 blog']">

| Blog | News | Announcements | Reports |
| ---- | ---- | ------------- | ------- |
| blog | news | announcements | reports |

</Route>

## Codeforces

#### 最新比赛
Expand Down
43 changes: 43 additions & 0 deletions lib/v2/cncf/index.js
Original file line number Diff line number Diff line change
@@ -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,
};
};
3 changes: 3 additions & 0 deletions lib/v2/cncf/maintainer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
'/:cate?': ['Fatpandac'],
};
31 changes: 31 additions & 0 deletions lib/v2/cncf/radar.js
Original file line number Diff line number Diff line change
@@ -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',
},
],
},
};
38 changes: 38 additions & 0 deletions lib/v2/cncf/reports.js
Original file line number Diff line number Diff line change
@@ -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,
};
};
4 changes: 4 additions & 0 deletions lib/v2/cncf/router.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = function (router) {
router.get('/reports', require('./reports'));
router.get('/:cate?', require('./index'));
};

0 comments on commit e1347b3

Please sign in to comment.