增加:Google Doodles (#1034)

This commit is contained in:
凉凉
2018-11-02 10:31:37 +08:00
committed by DIYgod
parent daf9dadf6d
commit e9e76dc8cd
3 changed files with 40 additions and 0 deletions
+2
View File
@@ -2059,6 +2059,8 @@ IATA 国际航空运输协会机场代码, 参见[维基百科 国际航空运
</route>
<route name="Google Doodles" author="xyqfer" example="/google/doodles/zh-CN" path="/google/doodles/:language?" :paramsDesc="['语言,默认为`zh-CN`简体中文,如需其他语言值可从[Google Doodles 官网](https://www.google.com/doodles)获取']" />
### 果壳网
<route name="科学人" author="alphardex" example="/guokr/scientific" path="/guokr/scientific"/>
+1
View File
@@ -466,6 +466,7 @@ router.get('/nvidia/webdriverupdate', require('./routes/nvidia/webdriverupdate')
// Google
router.get('/google/scholar/:query', require('./routes/google/scholar'));
router.get('/google/doodles/:language?', require('./routes/google/doodles'));
// Awesome Pigtals
router.get('/pigtails', require('./routes/pigtails'));
+37
View File
@@ -0,0 +1,37 @@
const axios = require('../../utils/axios');
module.exports = async (ctx) => {
const { language = 'zh-CN' } = ctx.params;
const current = new Date();
const year = current.getFullYear();
const month = current.getMonth() + 1;
const link = `https://www.google.com/doodles?hl=${language}`;
const {
data: { data },
} = await axios({
method: 'get',
url: `https://www.google.com/doodles/json/${year}/${month}?hl=${language}`,
headers: {
Referer: link,
},
});
ctx.state.data = {
title: 'Google Doodles',
link,
item:
data &&
data.map((item) => {
const date = `${item.run_date_array[0]}-${item.run_date_array[1]}-${item.run_date_array[2]}`;
return {
title: item.title,
description: `<img src="https:${item.url}" referrerpolicy="no-referrer" /><br>${item.share_text}`,
pubDate: new Date(date).toUTCString(),
guid: item.url,
link: `https://www.google.com/search?q=${encodeURIComponent(item.query)}`,
};
}),
};
};