Files
RSSHub/lib/v2/natgeo/dailyphoto.js
忧郁的紫色毛衣男孩 e61a90db77 fix(route): geo daily photo (#7555)
* 完成issues#7485,在每日一图-国家地理中增加每日精选节点

* 修改文档和router位置

* 对日期pubDate规范进行了调整

* 优化调整获取内容逻辑,修改pubDate字段的获取方式

* 调整pubDate参数

* 删除代码中多余的console

* 调整parse-date引用

* 调整时区

* issues-#7471,解决国家地理每日一图获取失败问题,因为网站更改,并且网站对图片进行了处理,所以调整获取方式。

* 删除无用代码

* 调整代码,错删了代码

* refactor: migrate to v2

* fix: nat geo photo of the day

* fix: natgeo parseDate

* style: lint

* feat: radar for natgeomedia.com

Co-authored-by: TonyRL <TonyRL@users.noreply.github.com>
2022-03-27 00:09:34 +08:00

33 lines
1.1 KiB
JavaScript

const got = require('@/utils/got');
const cheerio = require('cheerio');
const { parseDate } = require('@/utils/parse-date');
const { art } = require('@/utils/render');
const path = require('path');
const config = require('@/config').value;
module.exports = async (ctx) => {
const rootUrl = 'https://www.nationalgeographic.com';
const apiUrl = `${rootUrl}/photo-of-the-day`;
const response = await ctx.cache.tryGet(apiUrl, async () => (await got(apiUrl)).data, config.cache.contentExpire, false);
const $ = cheerio.load(response);
const natgeo = JSON.parse($.html().match(/window\['__natgeo__'\]=(.*);/)[1]);
const media = natgeo.page.content.mediaspotlight.frms[0].mods[0].edgs[1].media;
const items = media.map((item) => ({
title: item.meta.title,
description: art(path.join(__dirname, 'templates/dailyPhoto.art'), {
img: item.img,
}),
link: rootUrl + item.locator,
pubDate: parseDate(item.caption.preHeading),
author: item.img.crdt,
}));
ctx.state.data = {
title: 'Nat Geo Photo of the Day',
link: apiUrl,
item: items,
};
};