From afcd21b3b363bbbb351abe1b5b4951aa5bf3b63a Mon Sep 17 00:00:00 2001 From: Desmond Stonie Date: Sun, 16 Apr 2023 03:40:36 +0800 Subject: [PATCH] =?UTF-8?q?feat(route):=20add=20Apache=20APISIX=20?= =?UTF-8?q?=E5=8D=9A=E5=AE=A2=20&=20=E4=BA=91=E5=8E=9F=E7=94=9F=E7=A4=BE?= =?UTF-8?q?=E5=8C=BA=E5=8D=9A=E5=AE=A2=20&=20=E6=94=AF=E6=B5=81=E7=A7=91?= =?UTF-8?q?=E6=8A=80=E5=8D=9A=E5=AE=A2=20(#12294)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Add apiseven blog * Add apache apisix blog * Add cloudnative blog * Add radar.js and docs * Fix code styles * Fix code styles * Use `markdown-it` to render the description --- docs/blog.md | 18 +++++++++++++ lib/v2/apache/apisix/blog.js | 32 ++++++++++++++++++++++ lib/v2/apache/maintainer.js | 3 +++ lib/v2/apache/radar.js | 13 +++++++++ lib/v2/apache/router.js | 3 +++ lib/v2/apiseven/blog.js | 46 ++++++++++++++++++++++++++++++++ lib/v2/apiseven/maintainer.js | 3 +++ lib/v2/apiseven/radar.js | 13 +++++++++ lib/v2/apiseven/router.js | 3 +++ lib/v2/cloudnative/blog.js | 34 +++++++++++++++++++++++ lib/v2/cloudnative/maintainer.js | 3 +++ lib/v2/cloudnative/radar.js | 13 +++++++++ lib/v2/cloudnative/router.js | 3 +++ 13 files changed, 187 insertions(+) create mode 100644 lib/v2/apache/apisix/blog.js create mode 100644 lib/v2/apache/maintainer.js create mode 100644 lib/v2/apache/radar.js create mode 100644 lib/v2/apache/router.js create mode 100644 lib/v2/apiseven/blog.js create mode 100644 lib/v2/apiseven/maintainer.js create mode 100644 lib/v2/apiseven/radar.js create mode 100644 lib/v2/apiseven/router.js create mode 100644 lib/v2/cloudnative/blog.js create mode 100644 lib/v2/cloudnative/maintainer.js create mode 100644 lib/v2/cloudnative/radar.js create mode 100644 lib/v2/cloudnative/router.js diff --git a/docs/blog.md b/docs/blog.md index 1da927adb..f3e3cacc3 100644 --- a/docs/blog.md +++ b/docs/blog.md @@ -16,6 +16,12 @@ pageClass: routes +## Apache + +### APISIX 博客 + + + ## archdaily ### 首页 @@ -411,6 +417,18 @@ username 为博主用户名,而非`xxx.hashnode.dev`中`xxx`所代表的 blog +## 云原生社区 + +### 博客 + + + +## 支流科技 + +### 博客 + + + ## 竹白 ### 文章 diff --git a/lib/v2/apache/apisix/blog.js b/lib/v2/apache/apisix/blog.js new file mode 100644 index 000000000..3c2fe24e9 --- /dev/null +++ b/lib/v2/apache/apisix/blog.js @@ -0,0 +1,32 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const { parseDate } = require('@/utils/parse-date'); + +async function getArticles() { + const url = 'https://apisix.apache.org/zh/blog/'; + const { data: res } = await got(url); + const $ = cheerio.load(res); + const articles = $('section.sec_gjjg').eq(1).find('article'); + return articles.toArray().map((elem) => { + const a = $(elem).find('header > a'); + return { + title: a.find('h2').text(), + description: a.find('p').text(), + link: a.attr('href'), + pubDate: parseDate($(elem).find('footer').find('time').attr('datetime')), + category: $(elem) + .find('header div a') + .toArray() + .map((elem) => $(elem).text()), + }; + }); +} + +module.exports = async (ctx) => { + const articles = await getArticles(); + ctx.state.data = { + title: 'Blog | Apache APISIX', + link: 'https://apisix.apache.org/zh/blog/', + item: articles, + }; +}; diff --git a/lib/v2/apache/maintainer.js b/lib/v2/apache/maintainer.js new file mode 100644 index 000000000..1143d0485 --- /dev/null +++ b/lib/v2/apache/maintainer.js @@ -0,0 +1,3 @@ +module.exports = { + '/apisix/blog': ['aneasystone'], +}; diff --git a/lib/v2/apache/radar.js b/lib/v2/apache/radar.js new file mode 100644 index 000000000..2bd8550df --- /dev/null +++ b/lib/v2/apache/radar.js @@ -0,0 +1,13 @@ +module.exports = { + 'apache.org': { + _name: 'Apache', + apisix: [ + { + title: 'APISIX 博客', + docs: 'https://docs.rsshub.app/blog.html#apache', + source: ['/zh/blog'], + target: () => '/apache/apisix/blog', + }, + ], + }, +}; diff --git a/lib/v2/apache/router.js b/lib/v2/apache/router.js new file mode 100644 index 000000000..c9cdc4ec9 --- /dev/null +++ b/lib/v2/apache/router.js @@ -0,0 +1,3 @@ +module.exports = (router) => { + router.get('/apisix/blog', require('./apisix/blog')); +}; diff --git a/lib/v2/apiseven/blog.js b/lib/v2/apiseven/blog.js new file mode 100644 index 000000000..6abafb56f --- /dev/null +++ b/lib/v2/apiseven/blog.js @@ -0,0 +1,46 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const { parseDate } = require('@/utils/parse-date'); +const timezone = require('@/utils/timezone'); +const md = require('markdown-it')({ + html: true, +}); + +async function getArticles() { + const url = 'https://www.apiseven.com/blog'; + const { data: res } = await got(url); + const $ = cheerio.load(res); + const json = JSON.parse($('#__NEXT_DATA__').text()); + return json.props.pageProps.list.map((item) => ({ + title: item.title, + link: 'https://www.apiseven.com' + item.slug, + pubDate: timezone(parseDate(item.published_at), +8), + category: item.tags, + })); +} + +module.exports = async (ctx) => { + const articles = await getArticles(); + const items = await Promise.all( + articles.map((item) => + ctx.cache.tryGet(item.link, async () => { + const { data: res } = await got(item.link); + const $ = cheerio.load(res); + const json = JSON.parse($('#__NEXT_DATA__').text()); + return { + title: item.title, + description: md.render(json.props.pageProps.post.content), + link: item.link, + pubDate: item.pubDate, + author: json.props.pageProps.post.author_name, + }; + }) + ) + ); + + ctx.state.data = { + title: '博客 | 支流科技', + link: 'https://www.apiseven.com/blog', + item: items, + }; +}; diff --git a/lib/v2/apiseven/maintainer.js b/lib/v2/apiseven/maintainer.js new file mode 100644 index 000000000..23ff4629e --- /dev/null +++ b/lib/v2/apiseven/maintainer.js @@ -0,0 +1,3 @@ +module.exports = { + '/blog': ['aneasystone'], +}; diff --git a/lib/v2/apiseven/radar.js b/lib/v2/apiseven/radar.js new file mode 100644 index 000000000..839e4cfce --- /dev/null +++ b/lib/v2/apiseven/radar.js @@ -0,0 +1,13 @@ +module.exports = { + 'apiseven.com': { + _name: '支流科技', + '.': [ + { + title: '博客', + docs: 'https://docs.rsshub.app/blog.html#zhi-liu-ke-ji', + source: ['/blog'], + target: () => '/apiseven/blog', + }, + ], + }, +}; diff --git a/lib/v2/apiseven/router.js b/lib/v2/apiseven/router.js new file mode 100644 index 000000000..eadc22005 --- /dev/null +++ b/lib/v2/apiseven/router.js @@ -0,0 +1,3 @@ +module.exports = (router) => { + router.get('/blog', require('./blog')); +}; diff --git a/lib/v2/cloudnative/blog.js b/lib/v2/cloudnative/blog.js new file mode 100644 index 000000000..3eff0886d --- /dev/null +++ b/lib/v2/cloudnative/blog.js @@ -0,0 +1,34 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const { parseDate } = require('@/utils/parse-date'); +const timezone = require('@/utils/timezone'); + +async function getArticles() { + const url = 'https://cloudnative.to/blog/'; + const { data: res } = await got(url); + const $ = cheerio.load(res); + const articles = $('div.page-body .stream-item'); + return articles.toArray().map((elem) => { + const a = $(elem).find('.article-title > a'); + const summary = $(elem).find('.summary-link'); + const meta = $(elem).find('.stream-meta .article-metadata'); + const time = meta.find('.article-date').text().replace('发布于', ''); + return { + title: a.text(), + link: a.attr('href'), + description: summary.text(), + pubDate: timezone(parseDate(time, 'YYYY-MM-DD'), +8), + author: meta.find('span').eq(0).find('a').text(), + category: meta.find('.article-categories a').text(), + }; + }); +} + +module.exports = async (ctx) => { + const articles = await getArticles(); + ctx.state.data = { + title: '博客 | 云原生社区(中国)', + link: 'https://cloudnative.to/blog/', + item: articles, + }; +}; diff --git a/lib/v2/cloudnative/maintainer.js b/lib/v2/cloudnative/maintainer.js new file mode 100644 index 000000000..23ff4629e --- /dev/null +++ b/lib/v2/cloudnative/maintainer.js @@ -0,0 +1,3 @@ +module.exports = { + '/blog': ['aneasystone'], +}; diff --git a/lib/v2/cloudnative/radar.js b/lib/v2/cloudnative/radar.js new file mode 100644 index 000000000..b81315bf9 --- /dev/null +++ b/lib/v2/cloudnative/radar.js @@ -0,0 +1,13 @@ +module.exports = { + 'cloudnative.to': { + _name: '云原生社区', + '.': [ + { + title: '博客', + docs: 'https://docs.rsshub.app/blog.html#yun-yuan-sheng-she-qu', + source: ['/blog'], + target: () => '/cloudnative/blog', + }, + ], + }, +}; diff --git a/lib/v2/cloudnative/router.js b/lib/v2/cloudnative/router.js new file mode 100644 index 000000000..eadc22005 --- /dev/null +++ b/lib/v2/cloudnative/router.js @@ -0,0 +1,3 @@ +module.exports = (router) => { + router.get('/blog', require('./blog')); +};