feat(route): Latest Stories from National Geographic (#12621)
This commit is contained in:
parent
ad9027d29e
commit
44f21219a3
|
|
@ -56,6 +56,14 @@ For airport IATA code please refer to [Wikipedia List of airports by IATA code](
|
|||
|
||||
<RouteEn author="chazeon" example="/mcachicago/exhibitions" path="/mcachicago/exhibitions" />
|
||||
|
||||
## National Geographic
|
||||
|
||||
### Latest Stories
|
||||
|
||||
<RouteEn author="miles170"
|
||||
example="/nationalgeographic/latest-stories"
|
||||
path="/nationalgeographic/latest-stories" />
|
||||
|
||||
## New Museum
|
||||
|
||||
<RouteEn author="chazeon" example="/newmuseum/exhibitions" path="/newmuseum/exhibitions" />
|
||||
|
|
|
|||
|
|
@ -0,0 +1,53 @@
|
|||
const got = require('@/utils/got');
|
||||
const cheerio = require('cheerio');
|
||||
const { parseDate } = require('@/utils/parse-date');
|
||||
const { art } = require('@/utils/render');
|
||||
const { join } = require('path');
|
||||
|
||||
const findNatgeo = ($) =>
|
||||
JSON.parse(
|
||||
$('script')
|
||||
.text()
|
||||
.match(/\['__natgeo__'\]=({.*?});/)[1]
|
||||
);
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const currentUrl = 'https://www.nationalgeographic.com/pages/topic/latest-stories';
|
||||
const response = await got(currentUrl);
|
||||
const $ = cheerio.load(response.data);
|
||||
const items = await Promise.all(
|
||||
findNatgeo($)
|
||||
.page.content.hub.frms.flatMap((e) => e.mods)
|
||||
.flatMap((m) => m.tiles?.filter((t) => t.ctas[0]?.text === 'natgeo.ctaText.read'))
|
||||
.filter((i) => i)
|
||||
.map((i) => ({
|
||||
title: i.title,
|
||||
link: i.ctas[0].url,
|
||||
category: i.tags.map((t) => t.name),
|
||||
}))
|
||||
.map((item) =>
|
||||
ctx.cache.tryGet(item.link, async () => {
|
||||
const response = await got(item.link);
|
||||
const $ = cheerio.load(response.data);
|
||||
const mods = findNatgeo($).page.content.article.frms.find((f) => f.cmsType === 'ArticleBodyFrame').mods;
|
||||
const bodyTile = mods.find((m) => m.edgs[0].cmsType === 'ArticleBodyTile').edgs[0];
|
||||
|
||||
item.author = bodyTile.schma.athrs.map((a) => a.name).join(', ');
|
||||
item.description = art(join(__dirname, 'templates/stories.art'), {
|
||||
ldMda: bodyTile.ldMda,
|
||||
description: bodyTile.dscrptn,
|
||||
body: bodyTile.bdy,
|
||||
});
|
||||
item.pubDate = parseDate(bodyTile.pbDt);
|
||||
|
||||
return item;
|
||||
})
|
||||
)
|
||||
);
|
||||
|
||||
ctx.state.data = {
|
||||
title: $('meta[property="og:title"]').attr('content'),
|
||||
link: currentUrl,
|
||||
item: items.filter((item) => item !== null),
|
||||
};
|
||||
};
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
module.exports = {
|
||||
'/latest-stories': ['miles170'],
|
||||
};
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
module.exports = {
|
||||
'nationalgeographic.com': {
|
||||
_name: 'National Geographic',
|
||||
www: [
|
||||
{
|
||||
title: 'Latest Stories',
|
||||
docs: 'https://docs.rsshub.app/traditional-media.html#hua-shi-xin-wen',
|
||||
source: '/pages/topic/latest-stories',
|
||||
target: '/nationalgeographic/latest-stories',
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
module.exports = function (router) {
|
||||
router.get('/latest-stories', require('./latest-stories'));
|
||||
};
|
||||
|
|
@ -0,0 +1,44 @@
|
|||
{{ if ldMda }}
|
||||
<figure>
|
||||
<img src="{{ ldMda.image.src }}" alt="{{ ldMda.image.altText }}">
|
||||
<figcaption>{{ ldMda.caption }}</figcaption>
|
||||
</figure>
|
||||
{{ /if }}
|
||||
|
||||
{{ if description }}
|
||||
<p><b>{{ description }}</b></p>
|
||||
{{ /if }}
|
||||
|
||||
{{ each body b }}
|
||||
{{ if b.type === 'p' }}
|
||||
<p>{{@ b.cntnt.mrkup }}</p>
|
||||
{{ else if b.type === 'inline' }}
|
||||
{{ if b.cntnt.cmsType === 'image' }}
|
||||
<figure>
|
||||
<img src="{{ b.cntnt.image.src }}" alt="{{ b.cntnt.image.altText }}">
|
||||
<figcaption>{{@ b.cntnt.caption }}</figcaption>
|
||||
</figure>
|
||||
{{ else if b.cntnt.cmsType === 'imagegroup' }}
|
||||
{{ each b.cntnt.images img }}
|
||||
<figure>
|
||||
<img src="{{ img.image.src }}" alt="{{ img.image.altText }}">
|
||||
<figcaption>{{@ img.caption }}</figcaption>
|
||||
</figure>
|
||||
{{ /each }}
|
||||
{{ else if b.cntnt.cmsType === 'editorsNote' }}
|
||||
<p>{{@ b.cntnt.note }}</p>
|
||||
{{ else if b.cntnt.cmsType === 'listicle' }}
|
||||
<p>{{@ b.cntnt.text }}</p>
|
||||
{{ else if b.cntnt.cmsType === 'pullquote' }}
|
||||
<backquote>{{@ b.cntnt.quote }}</backquote>
|
||||
{{ else if b.cntnt.cmsType === 'source' }}
|
||||
<a href="{{ b.cntnt.src }}">{{ b.cntnt.src }}</a>
|
||||
{{ else if b.cntnt.cmsType === 'video' }}
|
||||
<figure>
|
||||
<img src="{{ b.cntnt.image.src }}" alt="{{ b.cntnt.image.altText }}">
|
||||
<figcaption>{{@ b.cntnt.title }}</figcaption>
|
||||
<figcaption>{{@ b.cntnt.description }}</figcaption>
|
||||
</figure>
|
||||
{{ /if }}
|
||||
{{ /if }}
|
||||
{{ /each }}
|
||||
Loading…
Reference in New Issue