From 5431f175062363920443d1822344c69cdf00a780 Mon Sep 17 00:00:00 2001 From: OrangeEd1t Date: Thu, 6 May 2021 15:10:06 +0800 Subject: [PATCH 01/16] =?UTF-8?q?=E5=AE=8C=E6=88=90issues#7485,=E5=9C=A8?= =?UTF-8?q?=E6=AF=8F=E6=97=A5=E4=B8=80=E5=9B=BE-=E5=9B=BD=E5=AE=B6?= =?UTF-8?q?=E5=9C=B0=E7=90=86=E4=B8=AD=E5=A2=9E=E5=8A=A0=E6=AF=8F=E6=97=A5?= =?UTF-8?q?=E7=B2=BE=E9=80=89=E8=8A=82=E7=82=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/picture.md | 4 ++++ lib/router.js | 1 + lib/routes/natgeo/dailyselection.js | 32 +++++++++++++++++++++++++++++ 3 files changed, 37 insertions(+) create mode 100644 lib/routes/natgeo/dailyselection.js diff --git a/docs/picture.md b/docs/picture.md index 0a1b04379064aa..69357b1523f137 100644 --- a/docs/picture.md +++ b/docs/picture.md @@ -368,6 +368,10 @@ R18 显示 +### 每日精选 + + + ## 煎蛋 ### 无聊图 diff --git a/lib/router.js b/lib/router.js index bb40705959f751..949f4ea258608a 100644 --- a/lib/router.js +++ b/lib/router.js @@ -407,6 +407,7 @@ router.get('/gcores/category/:category', require('./routes/gcores/category')); // 国家地理 router.get('/natgeo/dailyphoto', require('./routes/natgeo/dailyphoto')); +router.get('/natgeo/dailyselection', require('./routes/natgeo/dailyselection')); router.get('/natgeo/:cat/:type?', require('./routes/natgeo/natgeo')); // 一个 diff --git a/lib/routes/natgeo/dailyselection.js b/lib/routes/natgeo/dailyselection.js new file mode 100644 index 00000000000000..37e9def88a702b --- /dev/null +++ b/lib/routes/natgeo/dailyselection.js @@ -0,0 +1,32 @@ +const got = require('@/utils/got'); + +module.exports = async (ctx) => { + const host = 'http://dili.bdatu.com/jiekou/mains/p1.html'; + const data = await got.get(host); + + const sort = data.data.album[1].sort; + + const api = 'http://dili.bdatu.com/jiekou/albums/a' + sort + '.html'; + const response = await got.get(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: item.addtime, + guid: item.id, + }; + out.push(info); + return info; + }); + + ctx.state.data = { + title: 'Photo of the Daily Selection', + link: api, + item: out, + }; +}; \ No newline at end of file From c3ce5e75aa8d07dded9f8056dec8c73d7045400f Mon Sep 17 00:00:00 2001 From: OrangeEd1t Date: Thu, 6 May 2021 15:57:33 +0800 Subject: [PATCH 02/16] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=96=87=E6=A1=A3?= =?UTF-8?q?=E5=92=8Crouter=E4=BD=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/picture.md | 8 ++++---- lib/router.js | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/docs/picture.md b/docs/picture.md index 69357b1523f137..a6aba6fcf13898 100644 --- a/docs/picture.md +++ b/docs/picture.md @@ -364,14 +364,14 @@ R18 显示 ## 国家地理 -### 每日一图 - - - ### 每日精选 +### 每日一图 + + + ## 煎蛋 ### 无聊图 diff --git a/lib/router.js b/lib/router.js index 949f4ea258608a..de94a82c86752b 100644 --- a/lib/router.js +++ b/lib/router.js @@ -406,8 +406,8 @@ router.get('/sexinsex/:id/:type?', require('./routes/sexinsex/index')); router.get('/gcores/category/:category', require('./routes/gcores/category')); // 国家地理 -router.get('/natgeo/dailyphoto', require('./routes/natgeo/dailyphoto')); router.get('/natgeo/dailyselection', require('./routes/natgeo/dailyselection')); +router.get('/natgeo/dailyphoto', require('./routes/natgeo/dailyphoto')); router.get('/natgeo/:cat/:type?', require('./routes/natgeo/natgeo')); // 一个 From 3255f6376ac1a99b0e65a74fe8dfdfbd574c65a1 Mon Sep 17 00:00:00 2001 From: OrangeEd1t Date: Wed, 12 May 2021 16:42:10 +0800 Subject: [PATCH 03/16] =?UTF-8?q?=E5=AF=B9=E6=97=A5=E6=9C=9FpubDate?= =?UTF-8?q?=E8=A7=84=E8=8C=83=E8=BF=9B=E8=A1=8C=E4=BA=86=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/routes/natgeo/dailyselection.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/routes/natgeo/dailyselection.js b/lib/routes/natgeo/dailyselection.js index 37e9def88a702b..c01e350a3b384f 100644 --- a/lib/routes/natgeo/dailyselection.js +++ b/lib/routes/natgeo/dailyselection.js @@ -1,4 +1,5 @@ const got = require('@/utils/got'); +const parseDate = require('@/utils/parse-date'); module.exports = async (ctx) => { const host = 'http://dili.bdatu.com/jiekou/mains/p1.html'; @@ -17,7 +18,7 @@ module.exports = async (ctx) => { title: item.title, link: item.url, description: `
` + item.content, - pubDate: item.addtime, + pubDate: parseDate(item.addtime,'YYYY/MM/DD'), guid: item.id, }; out.push(info); From 7fd967bcfda8d4c8b1e7ce2519753105646fad77 Mon Sep 17 00:00:00 2001 From: OrangeEd1t Date: Thu, 13 May 2021 14:42:44 +0800 Subject: [PATCH 04/16] =?UTF-8?q?=E4=BC=98=E5=8C=96=E8=B0=83=E6=95=B4?= =?UTF-8?q?=E8=8E=B7=E5=8F=96=E5=86=85=E5=AE=B9=E9=80=BB=E8=BE=91=EF=BC=8C?= =?UTF-8?q?=E4=BF=AE=E6=94=B9pubDate=E5=AD=97=E6=AE=B5=E7=9A=84=E8=8E=B7?= =?UTF-8?q?=E5=8F=96=E6=96=B9=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/routes/natgeo/dailyselection.js | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/lib/routes/natgeo/dailyselection.js b/lib/routes/natgeo/dailyselection.js index c01e350a3b384f..6bcf30902137a7 100644 --- a/lib/routes/natgeo/dailyselection.js +++ b/lib/routes/natgeo/dailyselection.js @@ -1,24 +1,34 @@ const got = require('@/utils/got'); const parseDate = require('@/utils/parse-date'); +const timezone = require('@/utils/timezone'); module.exports = async (ctx) => { const host = 'http://dili.bdatu.com/jiekou/mains/p1.html'; const data = await got.get(host); - const sort = data.data.album[1].sort; + let sort = 0; + let addtime = ''; + + for (let i = 0; i < data.data.album.length; i++) { + if(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.get(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: parseDate(item.addtime,'YYYY/MM/DD'), + pubDate: timezone(parseDate(addtime), +0), guid: item.id, }; out.push(info); From 703ccaa7ebf864b99cb2b3d5fce03de2dd987858 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BF=A7=E9=83=81=E7=9A=84=E7=B4=AB=E8=89=B2=E6=AF=9B?= =?UTF-8?q?=E8=A1=A3=E7=94=B7=E5=AD=A9?= Date: Sat, 15 May 2021 16:54:59 +0800 Subject: [PATCH 05/16] =?UTF-8?q?=E8=B0=83=E6=95=B4pubDate=E5=8F=82?= =?UTF-8?q?=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/routes/natgeo/dailyselection.js | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/lib/routes/natgeo/dailyselection.js b/lib/routes/natgeo/dailyselection.js index 6bcf30902137a7..386e8196483eeb 100644 --- a/lib/routes/natgeo/dailyselection.js +++ b/lib/routes/natgeo/dailyselection.js @@ -8,27 +8,26 @@ module.exports = async (ctx) => { let sort = 0; let addtime = ''; - + console.log(data.data.album); for (let i = 0; i < data.data.album.length; i++) { - if(data.data.album[i].ds == 1){ + if (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.get(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), + pubDate: timezone(parseDate(addtime), +8), guid: item.id, }; out.push(info); @@ -40,4 +39,4 @@ module.exports = async (ctx) => { link: api, item: out, }; -}; \ No newline at end of file +}; From 556db62f70a31df996ad61c0b6e6ff47794da9a1 Mon Sep 17 00:00:00 2001 From: OrangeEd1t Date: Mon, 17 May 2021 18:17:15 +0800 Subject: [PATCH 06/16] =?UTF-8?q?=E5=88=A0=E9=99=A4=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E4=B8=AD=E5=A4=9A=E4=BD=99=E7=9A=84console?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/routes/natgeo/dailyselection.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/routes/natgeo/dailyselection.js b/lib/routes/natgeo/dailyselection.js index 386e8196483eeb..11f977a0ae00c4 100644 --- a/lib/routes/natgeo/dailyselection.js +++ b/lib/routes/natgeo/dailyselection.js @@ -8,7 +8,7 @@ module.exports = async (ctx) => { let sort = 0; let addtime = ''; - console.log(data.data.album); + for (let i = 0; i < data.data.album.length; i++) { if (data.data.album[i].ds == 1) { sort = data.data.album[i].sort; @@ -21,7 +21,6 @@ module.exports = async (ctx) => { const items = response.data.picture; const out = new Array; - items.map((item) => { const info = { title: item.title, From 20bf6ffa2ca01dcb15d30215c39bddba5bb63364 Mon Sep 17 00:00:00 2001 From: OrangeEd1t Date: Mon, 17 May 2021 18:35:08 +0800 Subject: [PATCH 07/16] =?UTF-8?q?=E8=B0=83=E6=95=B4parse-date=E5=BC=95?= =?UTF-8?q?=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/routes/natgeo/dailyselection.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/routes/natgeo/dailyselection.js b/lib/routes/natgeo/dailyselection.js index 11f977a0ae00c4..5df12acbbf24f0 100644 --- a/lib/routes/natgeo/dailyselection.js +++ b/lib/routes/natgeo/dailyselection.js @@ -1,6 +1,8 @@ const got = require('@/utils/got'); -const parseDate = require('@/utils/parse-date'); 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'; From e378a4bd7a4f944c31951d4796b450155cdd45e8 Mon Sep 17 00:00:00 2001 From: OrangeEd1t Date: Wed, 19 May 2021 14:52:50 +0800 Subject: [PATCH 08/16] =?UTF-8?q?=E8=B0=83=E6=95=B4=E6=97=B6=E5=8C=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/routes/natgeo/dailyselection.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/routes/natgeo/dailyselection.js b/lib/routes/natgeo/dailyselection.js index 5df12acbbf24f0..ce5c5d3aaf96e4 100644 --- a/lib/routes/natgeo/dailyselection.js +++ b/lib/routes/natgeo/dailyselection.js @@ -12,7 +12,7 @@ module.exports = async (ctx) => { let addtime = ''; for (let i = 0; i < data.data.album.length; i++) { - if (data.data.album[i].ds == 1) { + if (parseInt(data.data.album[i].ds) === 1) { sort = data.data.album[i].sort; addtime = data.data.album[i].addtime; break; @@ -28,7 +28,7 @@ module.exports = async (ctx) => { title: item.title, link: item.url, description: `
` + item.content, - pubDate: timezone(parseDate(addtime), +8), + pubDate: timezone(parseDate(addtime), +0), guid: item.id, }; out.push(info); From 09cd83505887a64ccf67558f0f41cbf3086d645c Mon Sep 17 00:00:00 2001 From: OrangeEd1t Date: Thu, 20 May 2021 13:57:45 +0800 Subject: [PATCH 09/16] =?UTF-8?q?issues-#7471=EF=BC=8C=E8=A7=A3=E5=86=B3?= =?UTF-8?q?=E5=9B=BD=E5=AE=B6=E5=9C=B0=E7=90=86=E6=AF=8F=E6=97=A5=E4=B8=80?= =?UTF-8?q?=E5=9B=BE=E8=8E=B7=E5=8F=96=E5=A4=B1=E8=B4=A5=E9=97=AE=E9=A2=98?= =?UTF-8?q?=EF=BC=8C=E5=9B=A0=E4=B8=BA=E7=BD=91=E7=AB=99=E6=9B=B4=E6=94=B9?= =?UTF-8?q?=EF=BC=8C=E5=B9=B6=E4=B8=94=E7=BD=91=E7=AB=99=E5=AF=B9=E5=9B=BE?= =?UTF-8?q?=E7=89=87=E8=BF=9B=E8=A1=8C=E4=BA=86=E5=A4=84=E7=90=86=EF=BC=8C?= =?UTF-8?q?=E6=89=80=E4=BB=A5=E8=B0=83=E6=95=B4=E8=8E=B7=E5=8F=96=E6=96=B9?= =?UTF-8?q?=E5=BC=8F=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/picture.md | 2 +- lib/routes/natgeo/dailyphoto.js | 43 ++++++++++++++++++++------------- 2 files changed, 27 insertions(+), 18 deletions(-) diff --git a/docs/picture.md b/docs/picture.md index d42855ab81dab2..1c4965ec81a1c6 100644 --- a/docs/picture.md +++ b/docs/picture.md @@ -370,7 +370,7 @@ R18 显示 ### 每日一图 - + ## 煎蛋 diff --git a/lib/routes/natgeo/dailyphoto.js b/lib/routes/natgeo/dailyphoto.js index 8e6c1695d931c2..94275008c8c9d4 100644 --- a/lib/routes/natgeo/dailyphoto.js +++ b/lib/routes/natgeo/dailyphoto.js @@ -1,27 +1,36 @@ const got = require('@/utils/got'); +const cheerio = require('cheerio'); module.exports = async (ctx) => { - const today = new Date(); - const year = today.getFullYear(); - const month = today.getMonth() + 1; + const browser = await require('@/utils/puppeteer')(); + const page = await browser.newPage(); + const link = 'https://www.nationalgeographic.com/photo-of-the-day/media-spotlight/'; + await page.goto(link); + const html = await page.evaluate( + () => + document.querySelector('div.InlineGallery').innerHTML + ); + browser.close(); - const api = `https://www.nationalgeographic.com/content/photography/en_US/photo-of-the-day/_jcr_content/.gallery.${year}-${month}.json`; - const response = await got.get(api); - const items = response.data.items; + const $ = cheerio.load(html); - const out = items.slice(0, 10).map((item) => { - const info = { - title: item.image.title, - author: item.image.credit && item.image.credit.replace('Photograph by ', ''), - link: item.pageUrl, - description: `` + item.image.caption, - }; - return info; - }); + const imgUrl = $('img').attr('src'); + const title = $('p.Caption__Title').text(); + const description = $('span.RichText').text(); + const author = $('span.Caption__Credit').text(); + + const out = new Array; + + const info = { + title: title, + link: link, + description: `
` + 'Photography by: ' + author + '
' + description, + }; + out.push(info); ctx.state.data = { - title: 'Photo of the Day', - link: 'https://www.nationalgeographic.com/photography/photo-of-the-day/', + title: 'Photo Of The Day', + link: link, item: out, }; }; From 1db9ab4a984376cce74fb9f6847b9b538cd826ac Mon Sep 17 00:00:00 2001 From: OrangeEd1t Date: Thu, 20 May 2021 18:19:53 +0800 Subject: [PATCH 10/16] =?UTF-8?q?=E5=88=A0=E9=99=A4=E6=97=A0=E7=94=A8?= =?UTF-8?q?=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/routes/natgeo/dailyselection.js | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/routes/natgeo/dailyselection.js b/lib/routes/natgeo/dailyselection.js index ce5c5d3aaf96e4..7f51a179a38deb 100644 --- a/lib/routes/natgeo/dailyselection.js +++ b/lib/routes/natgeo/dailyselection.js @@ -1,4 +1,3 @@ -const got = require('@/utils/got'); const timezone = require('@/utils/timezone'); const { parseDate From 4fdd89d3f0e18570b796a00c7218f0e04b34c8dc Mon Sep 17 00:00:00 2001 From: OrangeEd1t Date: Thu, 20 May 2021 18:22:08 +0800 Subject: [PATCH 11/16] =?UTF-8?q?=E8=B0=83=E6=95=B4=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=EF=BC=8C=E9=94=99=E5=88=A0=E4=BA=86=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/routes/natgeo/dailyphoto.js | 1 - lib/routes/natgeo/dailyselection.js | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/routes/natgeo/dailyphoto.js b/lib/routes/natgeo/dailyphoto.js index 94275008c8c9d4..2b49675e36b948 100644 --- a/lib/routes/natgeo/dailyphoto.js +++ b/lib/routes/natgeo/dailyphoto.js @@ -1,4 +1,3 @@ -const got = require('@/utils/got'); const cheerio = require('cheerio'); module.exports = async (ctx) => { diff --git a/lib/routes/natgeo/dailyselection.js b/lib/routes/natgeo/dailyselection.js index 7f51a179a38deb..ce5c5d3aaf96e4 100644 --- a/lib/routes/natgeo/dailyselection.js +++ b/lib/routes/natgeo/dailyselection.js @@ -1,3 +1,4 @@ +const got = require('@/utils/got'); const timezone = require('@/utils/timezone'); const { parseDate From cb4badd566fae3455c15230c27c296ecb1039874 Mon Sep 17 00:00:00 2001 From: TonyRL Date: Sat, 26 Mar 2022 13:05:43 +0000 Subject: [PATCH 12/16] refactor: migrate to v2 --- lib/router.js | 8 ++++---- lib/{routes => v2}/natgeo/dailyphoto.js | 13 +++++-------- lib/{routes => v2}/natgeo/dailyselection.js | 0 lib/{routes => v2}/natgeo/natgeo.js | 0 lib/v2/natgeo/router.js | 5 +++++ 5 files changed, 14 insertions(+), 12 deletions(-) rename lib/{routes => v2}/natgeo/dailyphoto.js (78%) rename lib/{routes => v2}/natgeo/dailyselection.js (100%) rename lib/{routes => v2}/natgeo/natgeo.js (100%) create mode 100644 lib/v2/natgeo/router.js diff --git a/lib/router.js b/lib/router.js index cd4b40ee2de5b2..5b7b4469a7d715 100644 --- a/lib/router.js +++ b/lib/router.js @@ -301,10 +301,10 @@ router.get('/t66y/:id/:type?', lazyloadRouteHandler('./routes/t66y/index')); // 色中色 router.get('/sexinsex/:id/:type?', lazyloadRouteHandler('./routes/sexinsex/index')); -// 国家地理 -router.get('/natgeo/dailyselection', lazyloadRouteHandler('./routes/natgeo/dailyselection')); -router.get('/natgeo/dailyphoto', lazyloadRouteHandler('./routes/natgeo/dailyphoto')); -router.get('/natgeo/:cat/:type?', lazyloadRouteHandler('./routes/natgeo/natgeo')); +// 国家地理 migrated to v2 +// router.get('/natgeo/dailyselection', lazyloadRouteHandler('./routes/natgeo/dailyselection')); +// router.get('/natgeo/dailyphoto', lazyloadRouteHandler('./routes/natgeo/dailyphoto')); +// router.get('/natgeo/:cat/:type?', lazyloadRouteHandler('./routes/natgeo/natgeo')); // 一个 router.get('/one', lazyloadRouteHandler('./routes/one/index')); diff --git a/lib/routes/natgeo/dailyphoto.js b/lib/v2/natgeo/dailyphoto.js similarity index 78% rename from lib/routes/natgeo/dailyphoto.js rename to lib/v2/natgeo/dailyphoto.js index 2b49675e36b948..c87837fb84f068 100644 --- a/lib/routes/natgeo/dailyphoto.js +++ b/lib/v2/natgeo/dailyphoto.js @@ -5,10 +5,7 @@ module.exports = async (ctx) => { const page = await browser.newPage(); const link = 'https://www.nationalgeographic.com/photo-of-the-day/media-spotlight/'; await page.goto(link); - const html = await page.evaluate( - () => - document.querySelector('div.InlineGallery').innerHTML - ); + const html = await page.evaluate(() => document.querySelector('div.InlineGallery').innerHTML); browser.close(); const $ = cheerio.load(html); @@ -18,18 +15,18 @@ module.exports = async (ctx) => { const description = $('span.RichText').text(); const author = $('span.Caption__Credit').text(); - const out = new Array; + const out = new Array(); const info = { - title: title, - link: link, + title, + link, description: `
` + 'Photography by: ' + author + '
' + description, }; out.push(info); ctx.state.data = { title: 'Photo Of The Day', - link: link, + link, item: out, }; }; diff --git a/lib/routes/natgeo/dailyselection.js b/lib/v2/natgeo/dailyselection.js similarity index 100% rename from lib/routes/natgeo/dailyselection.js rename to lib/v2/natgeo/dailyselection.js diff --git a/lib/routes/natgeo/natgeo.js b/lib/v2/natgeo/natgeo.js similarity index 100% rename from lib/routes/natgeo/natgeo.js rename to lib/v2/natgeo/natgeo.js diff --git a/lib/v2/natgeo/router.js b/lib/v2/natgeo/router.js new file mode 100644 index 00000000000000..b83da31edeacfd --- /dev/null +++ b/lib/v2/natgeo/router.js @@ -0,0 +1,5 @@ +module.exports = (router) => { + router.get('/dailyselection', require('./dailyselection')); + router.get('/dailyphoto', require('./dailyphoto')); + router.get('/:cat/:type?', require('./natgeo')); +}; From cf52fea63bb1994a7676273397c6954bf6200e8c Mon Sep 17 00:00:00 2001 From: TonyRL Date: Sat, 26 Mar 2022 14:17:28 +0000 Subject: [PATCH 13/16] fix: nat geo photo of the day --- docs/en/picture.md | 6 ++++ docs/picture.md | 2 +- lib/v2/natgeo/dailyphoto.js | 46 +++++++++++++------------- lib/v2/natgeo/maintainer.js | 5 +++ lib/v2/natgeo/radar.js | 13 ++++++++ lib/v2/natgeo/templates/dailyPhoto.art | 5 +++ 6 files changed, 53 insertions(+), 24 deletions(-) create mode 100644 lib/v2/natgeo/maintainer.js create mode 100644 lib/v2/natgeo/radar.js create mode 100644 lib/v2/natgeo/templates/dailyPhoto.art 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: +## National Geographic + +### Photo of the Day + + + ## nHentai ### Filter diff --git a/docs/picture.md b/docs/picture.md index a5a3bcb666a2a7..892533bdef3285 100644 --- a/docs/picture.md +++ b/docs/picture.md @@ -481,7 +481,7 @@ R18 显示 ### 每日一图 - + ## 煎蛋 diff --git a/lib/v2/natgeo/dailyphoto.js b/lib/v2/natgeo/dailyphoto.js index c87837fb84f068..a63d19bbdd19b9 100644 --- a/lib/v2/natgeo/dailyphoto.js +++ b/lib/v2/natgeo/dailyphoto.js @@ -1,32 +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 browser = await require('@/utils/puppeteer')(); - const page = await browser.newPage(); - const link = 'https://www.nationalgeographic.com/photo-of-the-day/media-spotlight/'; - await page.goto(link); - const html = await page.evaluate(() => document.querySelector('div.InlineGallery').innerHTML); - browser.close(); + 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 $ = cheerio.load(html); + const natgeo = JSON.parse($.html().match(/window\['__natgeo__'\]=(.*);/)[1]); + const media = natgeo.page.content.mediaspotlight.frms[0].mods[0].edgs[1].media; - const imgUrl = $('img').attr('src'); - const title = $('p.Caption__Title').text(); - const description = $('span.RichText').text(); - const author = $('span.Caption__Credit').text(); - - const out = new Array(); - - const info = { - title, - link, - description: `
` + 'Photography by: ' + author + '
' + description, - }; - out.push(info); + 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: 'Photo Of The Day', - link, - item: out, + title: 'Nat Geo Photo of the Day', + link: apiUrl, + item: items, }; }; 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/v2/natgeo/radar.js b/lib/v2/natgeo/radar.js new file mode 100644 index 00000000000000..4de55da37c1c54 --- /dev/null +++ b/lib/v2/natgeo/radar.js @@ -0,0 +1,13 @@ +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', + }, + ], + }, +}; 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.altText }} +
+

{{@ img.ttl }}

+

{{@ img.dsc }}

+

{{@ img.crdt }}

From 145a589918d1db7c63013493ffed4df3dcdd860e Mon Sep 17 00:00:00 2001 From: TonyRL Date: Sat, 26 Mar 2022 15:18:55 +0000 Subject: [PATCH 14/16] fix: natgeo parseDate --- docs/travel.md | 2 +- lib/v2/natgeo/natgeo.js | 50 +++++++++++++++-------------------------- lib/v2/natgeo/router.js | 2 +- 3 files changed, 20 insertions(+), 34 deletions(-) diff --git a/docs/travel.md b/docs/travel.md index 971acca47c5d9e..5753924d7fd3c5 100644 --- a/docs/travel.md +++ b/docs/travel.md @@ -92,7 +92,7 @@ IATA 国际航空运输协会机场代码,参见[维基百科 国际航空运 ### 分类 - + ## 活动行 diff --git a/lib/v2/natgeo/natgeo.js b/lib/v2/natgeo/natgeo.js index 42458cb16b99e9..14133197a8dae5 100644 --- a/lib/v2/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/router.js b/lib/v2/natgeo/router.js index b83da31edeacfd..d85de81184d0a0 100644 --- a/lib/v2/natgeo/router.js +++ b/lib/v2/natgeo/router.js @@ -1,5 +1,5 @@ module.exports = (router) => { - router.get('/dailyselection', require('./dailyselection')); router.get('/dailyphoto', require('./dailyphoto')); + router.get('/dailyselection', require('./dailyselection')); router.get('/:cat/:type?', require('./natgeo')); }; From 5e7f9d1147353dd59446f1408dc675fe6277aede Mon Sep 17 00:00:00 2001 From: TonyRL Date: Sat, 26 Mar 2022 15:55:18 +0000 Subject: [PATCH 15/16] style: lint --- lib/v2/natgeo/dailyselection.js | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/lib/v2/natgeo/dailyselection.js b/lib/v2/natgeo/dailyselection.js index ce5c5d3aaf96e4..843c92f13fd9ec 100644 --- a/lib/v2/natgeo/dailyselection.js +++ b/lib/v2/natgeo/dailyselection.js @@ -1,27 +1,25 @@ const got = require('@/utils/got'); const timezone = require('@/utils/timezone'); -const { - parseDate -} = require('@/utils/parse-date'); +const { parseDate } = require('@/utils/parse-date'); module.exports = async (ctx) => { const host = 'http://dili.bdatu.com/jiekou/mains/p1.html'; - const data = await got.get(host); + 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) { + 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.get(api); + const response = await got(api); const items = response.data.picture; - const out = new Array; + const out = new Array(); items.map((item) => { const info = { From 641a3cf14b40b508ea0dddade91cdd101d6011ac Mon Sep 17 00:00:00 2001 From: TonyRL Date: Sat, 26 Mar 2022 16:04:50 +0000 Subject: [PATCH 16/16] feat: radar for natgeomedia.com --- lib/v2/natgeo/radar.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/lib/v2/natgeo/radar.js b/lib/v2/natgeo/radar.js index 4de55da37c1c54..efe95bcdc7d6a2 100644 --- a/lib/v2/natgeo/radar.js +++ b/lib/v2/natgeo/radar.js @@ -10,4 +10,15 @@ module.exports = { }, ], }, + 'natgeomedia.com': { + _name: '国家地理', + '.': [ + { + title: '分类', + docs: 'https://docs.rsshub.app/travel.html#guo-jia-di-li', + source: ['/:cat/:type', '/'], + target: '/natgeo/:cat/:type', + }, + ], + }, };