feat: add deepl blog (#6293)
This commit is contained in:
parent
6c5198f728
commit
227e4289a7
|
|
@ -118,6 +118,12 @@ pageClass: routes
|
|||
|
||||
<Route author="kt286" example="/cnbeta" path="/cnbeta"/>
|
||||
|
||||
## DeepL
|
||||
|
||||
### Blog
|
||||
|
||||
<Route author="nczitzk" example="/deepl/blog" path="/deepl/blog/:lang?" :paramsDesc="['语言,可选 `en` 指 英语 和 `zh` 指 汉语,默认为 en']"/>
|
||||
|
||||
## Deutsche Welle 德国之声
|
||||
|
||||
<Route author="nczitzk" example="/dw/zh" path="/dw/:lang?/:caty?" :paramsDesc="['语言,可在对应语言版本页的 URL 中找到,默认为德语', '分类,见下表,默认为全部']">
|
||||
|
|
|
|||
|
|
@ -3516,6 +3516,9 @@ router.get('/uisdc/news', require('./routes/uisdc/news'));
|
|||
router.get('/uisdc/zt/:title?', require('./routes/uisdc/zt'));
|
||||
router.get('/uisdc/topic/:title?/:sort?', require('./routes/uisdc/topic'));
|
||||
|
||||
// DeepL
|
||||
router.get('/deepl/blog/:lang?', require('./routes/deepl/blog'));
|
||||
|
||||
// OpenAI
|
||||
router.get('/openai/blog/:tag?', require('./routes/openai/blog'));
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,34 @@
|
|||
const got = require('@/utils/got');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const lang = ctx.params.lang || 'en';
|
||||
|
||||
const rootUrl = 'https://www.deepl.com';
|
||||
const currentUrl = `${rootUrl}/zh/blog`;
|
||||
const blogUrl = `${rootUrl}/gatsby/locales/${lang}/blog.json`;
|
||||
const response = await got({
|
||||
method: 'get',
|
||||
url: blogUrl,
|
||||
});
|
||||
|
||||
const items = [];
|
||||
const data = response.data;
|
||||
for (const key in data) {
|
||||
const matches = key.match(/post_content_(\d{8})/);
|
||||
if (matches) {
|
||||
const date = matches[1];
|
||||
items.push({
|
||||
description: data[key],
|
||||
link: `${currentUrl}/${date}`,
|
||||
title: data['post_title_' + date],
|
||||
pubDate: new Date(`${date.substr(0, 4)}-${date.substr(4, 2)}-${date.substr(6, 2)}`).toUTCString(),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
ctx.state.data = {
|
||||
title: response.data.title,
|
||||
link: currentUrl,
|
||||
item: items,
|
||||
};
|
||||
};
|
||||
Loading…
Reference in New Issue