diff --git a/docs/en/picture.md b/docs/en/picture.md
index 651408c0a92297..cc070b3addc216 100644
--- a/docs/en/picture.md
+++ b/docs/en/picture.md
@@ -197,6 +197,12 @@ For example:
` + item.image.caption,
- };
- return info;
- });
-
- ctx.state.data = {
- title: 'Photo of the Day',
- link: 'https://www.nationalgeographic.com/photography/photo-of-the-day/',
- item: out,
- };
-};
diff --git a/lib/v2/natgeo/dailyphoto.js b/lib/v2/natgeo/dailyphoto.js
new file mode 100644
index 00000000000000..a63d19bbdd19b9
--- /dev/null
+++ b/lib/v2/natgeo/dailyphoto.js
@@ -0,0 +1,32 @@
+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,
+ };
+};
diff --git a/lib/v2/natgeo/dailyselection.js b/lib/v2/natgeo/dailyselection.js
new file mode 100644
index 00000000000000..843c92f13fd9ec
--- /dev/null
+++ b/lib/v2/natgeo/dailyselection.js
@@ -0,0 +1,41 @@
+const got = require('@/utils/got');
+const timezone = require('@/utils/timezone');
+const { parseDate } = require('@/utils/parse-date');
+
+module.exports = async (ctx) => {
+ const host = 'http://dili.bdatu.com/jiekou/mains/p1.html';
+ const data = await got(host);
+
+ let sort = 0;
+ let addtime = '';
+
+ for (let i = 0; i < data.data.album.length; i++) {
+ if (parseInt(data.data.album[i].ds) === 1) {
+ sort = data.data.album[i].sort;
+ addtime = data.data.album[i].addtime;
+ break;
+ }
+ }
+ const api = 'http://dili.bdatu.com/jiekou/albums/a' + sort + '.html';
+ const response = await got(api);
+ const items = response.data.picture;
+ const out = new Array();
+
+ items.map((item) => {
+ const info = {
+ title: item.title,
+ link: item.url,
+ description: `
` + item.content,
+ pubDate: timezone(parseDate(addtime), +0),
+ guid: item.id,
+ };
+ out.push(info);
+ return info;
+ });
+
+ ctx.state.data = {
+ title: 'Photo of the Daily Selection',
+ link: api,
+ item: out,
+ };
+};
diff --git a/lib/v2/natgeo/maintainer.js b/lib/v2/natgeo/maintainer.js
new file mode 100644
index 00000000000000..a8d19f4cf41b54
--- /dev/null
+++ b/lib/v2/natgeo/maintainer.js
@@ -0,0 +1,5 @@
+module.exports = {
+ '/dailyselection': ['OrangeEd1t'],
+ '/dailyphoto': ['LogicJake', 'OrangeEd1t', 'TonyRL'],
+ '/:cat/:type?': ['fengkx'],
+};
diff --git a/lib/routes/natgeo/natgeo.js b/lib/v2/natgeo/natgeo.js
similarity index 53%
rename from lib/routes/natgeo/natgeo.js
rename to lib/v2/natgeo/natgeo.js
index 42458cb16b99e9..14133197a8dae5 100644
--- a/lib/routes/natgeo/natgeo.js
+++ b/lib/v2/natgeo/natgeo.js
@@ -1,65 +1,51 @@
const cheerio = require('cheerio');
const got = require('@/utils/got');
+const { parseDate } = require('@/utils/parse-date');
// https://www.natgeomedia.com//article/
-const MonthMap = {
- JAN: 0,
- FEB: 1,
- MAR: 2,
- APR: 3,
- MAY: 4,
- JUN: 5,
- JUL: 6,
- AUG: 7,
- SEP: 8,
- OCT: 9,
- NOV: 10,
- DEC: 11,
-};
-
async function load(link) {
- const { data } = await got.get(link);
+ const { data } = await got(link);
const $ = cheerio.load(data);
const dtStr = $('.content-title-area')
.find('h6')
.first()
- .text()
- .split(/[\s.]+/);
- const dt = new Date();
- dt.setMonth(MonthMap[dtStr[0].toUpperCase()]);
- dt.setDate(dtStr[1]);
+ .html()
+ .replace(/ /gi, ' ')
+ .trim();
+
let description = $('article').first().html() + $('article').eq(1).html();
if (/photo/.test(link)) {
description = $('#content-album').html() + description;
}
return {
title: $('title').text(),
- pubDate: dt.toUTCString(),
+ pubDate: parseDate(dtStr, 'MMM. DD YYYY'),
description,
};
}
module.exports = async (ctx) => {
- const type = ctx.params.type || '';
+ const type = ctx.params.type ?? '';
const url = `https://www.natgeomedia.com/${ctx.params.cat}/${type}`;
- const res = await got.get(url);
+ const res = await got(url);
const $ = cheerio.load(res.data);
- const urlList = Array.prototype.map.call($('.article-link-w100').find('.read-btn'), (i) => $(i).find('a[href]').first().attr('href'));
+ const urlList = $('.article-link-w100')
+ .find('.read-btn')
+ .toArray()
+ .map((i) => ({
+ link: $(i).find('a[href]').first().attr('href'),
+ }));
- const count = [];
- for (let i = 0; i < Math.min(urlList.length, 10); i++) {
- count.push(i);
- }
const out = await Promise.all(
- count.map(async (i) => {
- const link = urlList[i];
+ urlList.map(async (i) => {
+ const link = i.link;
const single = {
link,
};
const other = await ctx.cache.tryGet(link, () => load(link));
- return Object.assign({}, single, other);
+ return { ...single, ...other };
})
);
ctx.state.data = {
diff --git a/lib/v2/natgeo/radar.js b/lib/v2/natgeo/radar.js
new file mode 100644
index 00000000000000..efe95bcdc7d6a2
--- /dev/null
+++ b/lib/v2/natgeo/radar.js
@@ -0,0 +1,24 @@
+module.exports = {
+ 'nationalgeographic.com': {
+ _name: '国家地理',
+ '.': [
+ {
+ title: '每日一图',
+ docs: 'https://docs-rsshub.pages.dev/picture.html#guo-jia-di-li',
+ source: ['/photo-of-the-day/*', '/'],
+ target: '/natgeo/dailyphoto',
+ },
+ ],
+ },
+ 'natgeomedia.com': {
+ _name: '国家地理',
+ '.': [
+ {
+ title: '分类',
+ docs: 'https://docs.rsshub.app/travel.html#guo-jia-di-li',
+ source: ['/:cat/:type', '/'],
+ target: '/natgeo/:cat/:type',
+ },
+ ],
+ },
+};
diff --git a/lib/v2/natgeo/router.js b/lib/v2/natgeo/router.js
new file mode 100644
index 00000000000000..d85de81184d0a0
--- /dev/null
+++ b/lib/v2/natgeo/router.js
@@ -0,0 +1,5 @@
+module.exports = (router) => {
+ router.get('/dailyphoto', require('./dailyphoto'));
+ router.get('/dailyselection', require('./dailyselection'));
+ router.get('/:cat/:type?', require('./natgeo'));
+};
diff --git a/lib/v2/natgeo/templates/dailyPhoto.art b/lib/v2/natgeo/templates/dailyPhoto.art
new file mode 100644
index 00000000000000..004525a04fd460
--- /dev/null
+++ b/lib/v2/natgeo/templates/dailyPhoto.art
@@ -0,0 +1,5 @@
+
+
+
{{@ img.dsc }}
+{{@ img.crdt }}