feat(route): add Uber Engineering Blog (#11106)

* add Uber Engineering Blog

* use more readable fulltext

* use wp json api instead of original website scrapping,fix some mistakes according to the comments

* try to mistaken modification of removing a newline at the end

* Update docs/blog.md

* Update docs/en/blog.md

* Update lib/v2/uber/radar.js

Co-authored-by: hulb <hulb@RD-NeoHu.netis.com.cn>
This commit is contained in:
hulb
2022-11-06 23:20:29 +08:00
committed by GitHub
co-authored by hulb
parent 451f280ece
commit b8074985da
6 changed files with 89 additions and 0 deletions
+6
View File
@@ -332,6 +332,12 @@ username 为博主用户名,而非`xxx.hashnode.dev`中`xxx`所代表的 blog
<Route author="junbaor SkiTiSu" example="/blogs/wangyin" path="/blogs/wangyin"/>
## 优步
### 工程技术
<Route author="hulb" example="/uber/blog" path="/uber/blog/:maxPage?" :paramsDesc="['获取的最多页数,默认最多获取第一页']" />
## 雨苁博客
### 首页
+6
View File
@@ -90,6 +90,12 @@ Limit the number of entries to be retrieved by adding `?limit=x` to the end of t
<RouteEn author="chazeon" example="/stratechery" path="/stratechery" />
## Uber
### Engineering
<RouteEn author="hulb" example="/uber/blog" path="/uber/blog/:maxPage?" :paramsDesc="['max number of pages to retrieve, default to 1 page at most']" />
## WordPress
### Blog
+58
View File
@@ -0,0 +1,58 @@
const got = require('@/utils/got');
const { parseDate } = require('@/utils/parse-date');
const rootURL = 'https://www.uber.com';
const apiURL = 'https://blogapi.uber.com';
module.exports = async (ctx) => {
let maxPage = Number(ctx.params.maxPage);
if (Number.isNaN(maxPage)) {
maxPage = 1;
}
let pages = await Promise.all(
[...Array(maxPage).keys()].map((pageIdx) =>
got(`${apiURL}/wp-json/blog/v1/data`, {
searchParams: {
page: pageIdx + 1,
parent: 'pittsburgh',
slug: 'engineering',
},
})
)
);
pages = pages.map((page) => page.data);
const result = await Promise.all(
pages.map(
async (page) =>
await Promise.all(
page.posts.map((post) =>
ctx.cache.tryGet(`${rootURL}${post.link}`, async () => {
let { data: article } = await got(`${apiURL}/wp-json/blog/v1/data`, {
searchParams: {
slug: post.link.replace(/\//g, '').replace('blog', ''),
},
});
article = article.article;
return {
title: article.title,
description: article.content,
pubDate: parseDate(article.created),
author: article.author,
category: article.categories.map((category) => category.category_name),
};
})
)
)
)
);
ctx.state.data = {
title: `Uber Engineering Blog`,
link: rootURL + '/blog/engineering',
description: 'The technology behind Uber Engineering',
item: result.flat(),
};
};
+3
View File
@@ -0,0 +1,3 @@
module.exports = {
'/blog/:maxPage?': ['hulb'],
};
+13
View File
@@ -0,0 +1,13 @@
module.exports = {
'uber.com': {
_name: 'Uber Blog',
www: [
{
title: 'Engineering',
docs: 'https://docs.rsshub.app/blog.html#you-bu',
source: ['/blog/pittsburgh/engineering'],
target: '/uber/blog',
},
],
},
};
+3
View File
@@ -0,0 +1,3 @@
module.exports = function (router) {
router.get('/blog/:maxPage?', require('./blog'));
};