diff --git a/docs/en/traditional-media.md b/docs/en/traditional-media.md index b8bf38347b..b4edd549bc 100644 --- a/docs/en/traditional-media.md +++ b/docs/en/traditional-media.md @@ -4,6 +4,20 @@ pageClass: routes # News +## ABC News + +### Site + + + +Site + +| Just In | Politics | World | Business | Analysis | Sport | Science | Health | Arts | Fact Check | 中文新闻 | Berita Bahasa Indonesia | Tok Pisin | +| - | - | - | - | - | - | - | - | - | - | - | - | - | - | +| justin | politics | world | business | analysis-and-opinion | sport | science | health | arts-culture | factcheck | chinese | indonesian | tok-pisin | + + + ## AP News ### Topics diff --git a/docs/traditional-media.md b/docs/traditional-media.md index 071f371ca6..9bac16da18 100644 --- a/docs/traditional-media.md +++ b/docs/traditional-media.md @@ -10,6 +10,20 @@ pageClass: routes +## ABC News + +### 子站 + + + +子站 + +| Just In | Politics | World | Business | Analysis | Sport | Science | Health | Arts | Fact Check | 中文新闻 | Berita Bahasa Indonesia | Tok Pisin | +| ------- | -------- | ----- | -------- | -------------------- | ----- | ------- | ------ | ------------ | ---------- | -------- | ----------------------- | --------- | +| justin | politics | world | business | analysis-and-opinion | sport | science | health | arts-culture | factcheck | chinese | indonesian | tok-pisin | + + + ## AP News ### 话题 diff --git a/lib/router.js b/lib/router.js index 7f4a630cdc..cc4d681f31 100644 --- a/lib/router.js +++ b/lib/router.js @@ -3260,6 +3260,9 @@ router.get('/appsales/:caty?/:time?', require('./routes/appsales/index')); // CGTN router.get('/cgtn/top', require('./routes/cgtn/top')); +// ABC News +router.get('/abc/:site?', require('./routes/abc/index.js')); + // 台湾中央通讯社 router.get('/cna/:id?', require('./routes/cna/index')); diff --git a/lib/routes/abc/index.js b/lib/routes/abc/index.js new file mode 100644 index 0000000000..727dbd839c --- /dev/null +++ b/lib/routes/abc/index.js @@ -0,0 +1,86 @@ +const url = require('url'); +const got = require('@/utils/got'); +const cheerio = require('cheerio'); + +module.exports = async (ctx) => { + ctx.params.site = ctx.params.site || ''; + + const rootUrl = 'https://mobile.abc.net.au'; + const currentUrl = `${rootUrl}/news/${ctx.params.site}`; + const response = await got({ + method: 'get', + url: currentUrl, + }); + const $ = cheerio.load(response.data); + + $('._3zQMR, .ticker').remove(); + + const list = $('h3') + .slice(0, 10) + .map((_, item) => { + item = $(item); + return { + title: item.text(), + link: url.resolve(rootUrl, item.parents('a').attr('href') || item.find('a').attr('href')), + }; + }) + .get(); + + const items = await Promise.all( + list.map( + async (item) => + await ctx.cache.tryGet(item.link, async () => { + const detailResponse = await got({ + method: 'get', + url: item.link, + }); + const content = cheerio.load(detailResponse.data); + + content('.modal-content').remove(); + + content('img').each(function () { + content(this).attr('src', content(this).attr('data-src')); + }); + + let coverImage, contentBody; + if (content('div[data-component="FeatureMedia"]').html() !== null) { + coverImage = content('div[data-component="FeatureMedia"]').html(); + } else { + coverImage = content('.view-hero-media').html(); + } + if (content('#body').html() !== null) { + contentBody = content('#body').html(); + } else { + contentBody = content('.article-text').html(); + } + + const authorsArray = []; + const authorsMatch = detailResponse.data.match(/author":(.*),"dateModified/); + if (authorsMatch === null) { + authorsArray.push(content('meta[name="DCTERMS.contributor"]').attr('content')); + } else { + const authors = JSON.parse(authorsMatch[1]); + try { + for (const author of authors) { + authorsArray.push(author.name); + } + } catch (e) { + authorsArray.push(authors.name); + } + } + + item.description = coverImage + contentBody; + item.pubDate = new Date(content('meta[property="article:published_time"]').attr('content')).toUTCString(); + item.author = authorsArray.join(', '); + + return item; + }) + ) + ); + + ctx.state.data = { + title: $('title').text(), + link: currentUrl, + item: items, + }; +};