From 8faccdec06d1cad70401aa03a1c15e30e628d852 Mon Sep 17 00:00:00 2001 From: NeverBehave Date: Fri, 15 Jan 2021 15:53:21 -0500 Subject: [PATCH] Revert "feat: add top stories route for Associated Press News" (#6707) --- docs/en/traditional-media.md | 4 --- docs/traditional-media.md | 4 --- lib/router.js | 1 - lib/routes/apnews/index.js | 54 ------------------------------------ 4 files changed, 63 deletions(-) delete mode 100644 lib/routes/apnews/index.js diff --git a/docs/en/traditional-media.md b/docs/en/traditional-media.md index 7180f4bab0..4f942f500e 100644 --- a/docs/en/traditional-media.md +++ b/docs/en/traditional-media.md @@ -20,10 +20,6 @@ Site ## AP News -### Top Stories - - - ### Topics diff --git a/docs/traditional-media.md b/docs/traditional-media.md index 00404b478f..91f6184b9b 100644 --- a/docs/traditional-media.md +++ b/docs/traditional-media.md @@ -26,10 +26,6 @@ pageClass: routes ## AP News -### 首页头条 - - - ### 话题 diff --git a/lib/router.js b/lib/router.js index 3dcec4e129..ad736c3e69 100644 --- a/lib/router.js +++ b/lib/router.js @@ -2496,7 +2496,6 @@ router.get('/gbcc/trust', require('./routes/gbcc/trust')); // Associated Press router.get('/apnews/topics/:topic', require('./routes/apnews/topics')); -router.get('/apnews', require('./routes/apnews/index')); // CBC router.get('/cbc/topics/:topic?', require('./routes/cbc/topics')); diff --git a/lib/routes/apnews/index.js b/lib/routes/apnews/index.js deleted file mode 100644 index a59c24f1de..0000000000 --- a/lib/routes/apnews/index.js +++ /dev/null @@ -1,54 +0,0 @@ -const cheerio = require('cheerio'); -const got = require('@/utils/got'); - -module.exports = async (ctx) => { - const response = await got.get('https://apnews.com/'); - const $ = cheerio.load(response.data); - const list = []; - - // main story component - const main = $('div[data-key=main-story]').first(); - - // headline news - const headline = {}; - headline.title = $(main).find('a[data-key=card-headline] h1').first().text(); - headline.link = 'https://apnews.com' + $(main).find('a[data-key=card-headline]').first().attr('href'); - list.push(headline); - - // related stories - $(main) - .find('a[data-key=related-story-link]') - .each(function (_, e) { - const item = {}; - item.title = $(e).find('div[data-key=related-story-headline]').first().text(); - item.link = 'https://apnews.com' + $(e).attr('href'); - list.push(item); - }); - - const result = await Promise.all( - list.map( - async (item) => - await ctx.cache.tryGet(item.link, async () => { - const content = await got.get(item.link); - - const description = cheerio.load(content.data); - const metadata = JSON.parse(description('script[type="application/ld+json"]').html()); - const featureImageURL = metadata.image; - - item.description = ``; - item.description += description('div[class=Article]') - .html() - .replace(/ADVERTISEMENT/g, ''); - item.pubDate = new Date(metadata.datePublished).toISOString(); - item.author = metadata.author[0]; - return item; - }) - ) - ); - - ctx.state.data = { - title: 'Associated Press News', - link: 'https://apnews.com/', - item: result, - }; -};