diff --git a/docs/blog.md b/docs/blog.md index 93b7976df9..058476e218 100644 --- a/docs/blog.md +++ b/docs/blog.md @@ -332,6 +332,12 @@ username 为博主用户名,而非`xxx.hashnode.dev`中`xxx`所代表的 blog +## 优步 + +### 工程技术 + + + ## 雨苁博客 ### 首页 diff --git a/docs/en/blog.md b/docs/en/blog.md index 063b8b8350..d525db7aa4 100644 --- a/docs/en/blog.md +++ b/docs/en/blog.md @@ -90,6 +90,12 @@ Limit the number of entries to be retrieved by adding `?limit=x` to the end of t +## Uber + +### Engineering + + + ## WordPress ### Blog diff --git a/lib/v2/uber/blog.js b/lib/v2/uber/blog.js new file mode 100644 index 0000000000..7033216442 --- /dev/null +++ b/lib/v2/uber/blog.js @@ -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(), + }; +}; diff --git a/lib/v2/uber/maintainer.js b/lib/v2/uber/maintainer.js new file mode 100644 index 0000000000..9aacfd72c0 --- /dev/null +++ b/lib/v2/uber/maintainer.js @@ -0,0 +1,3 @@ +module.exports = { + '/blog/:maxPage?': ['hulb'], +}; diff --git a/lib/v2/uber/radar.js b/lib/v2/uber/radar.js new file mode 100644 index 0000000000..e787837f80 --- /dev/null +++ b/lib/v2/uber/radar.js @@ -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', + }, + ], + }, +}; diff --git a/lib/v2/uber/router.js b/lib/v2/uber/router.js new file mode 100644 index 0000000000..43d2c458a6 --- /dev/null +++ b/lib/v2/uber/router.js @@ -0,0 +1,3 @@ +module.exports = function (router) { + router.get('/blog/:maxPage?', require('./blog')); +};