From 5f299e9270ae55c67933dd804ce252a78231387b Mon Sep 17 00:00:00 2001 From: GitHub Action Date: Mon, 24 Aug 2020 11:28:29 +0000 Subject: [PATCH] style: auto format --- docs/traditional-media.md | 3 ++ lib/router.js | 1 - lib/routes/fjnews/fznews.js | 82 ++++++++++++++++++------------------- lib/routes/fjnews/jjnews.js | 63 ++++++++++++++-------------- 4 files changed, 74 insertions(+), 75 deletions(-) diff --git a/docs/traditional-media.md b/docs/traditional-media.md index 210a92200..f352820de 100644 --- a/docs/traditional-media.md +++ b/docs/traditional-media.md @@ -748,10 +748,13 @@ category 对应的关键词有 ### 福建新闻 + ### 福州新闻 + ### 九江新闻 + diff --git a/lib/router.js b/lib/router.js index 4a6eed93a..8384e717f 100644 --- a/lib/router.js +++ b/lib/router.js @@ -3110,5 +3110,4 @@ router.get('/fjnews/fz/30', require('./routes/fjnews/fznews')); // 九江新闻jjnews router.get('/fjnews/jjnews', require('./routes/fjnews/jjnews')); - module.exports = router; diff --git a/lib/routes/fjnews/fznews.js b/lib/routes/fjnews/fznews.js index 5f41c9bcf..68f60ca04 100644 --- a/lib/routes/fjnews/fznews.js +++ b/lib/routes/fjnews/fznews.js @@ -6,52 +6,50 @@ let host = 'http://news.fznews.com.cn/fzxw/'; let citytitle = '福州新闻'; module.exports = async (ctx) => { - if (ctx.params.city === 'fj') { - host = 'http://news.fznews.com.cn/dsxw/'; - citytitle = '福建新闻'; - } else { - host = 'http://news.fznews.com.cn/fzxw/'; - citytitle = '福州新闻'; - } + if (ctx.params.city === 'fj') { + host = 'http://news.fznews.com.cn/dsxw/'; + citytitle = '福建新闻'; + } else { + host = 'http://news.fznews.com.cn/fzxw/'; + citytitle = '福州新闻'; + } - const response = await got.get(host); - const $ = cheerio.load(response.data); - const list = $('.li-h32f14 li:not(.clearfix)').slice(0, ctx.params.limit).get(); - const out = await Promise.all( + const response = await got.get(host); + const $ = cheerio.load(response.data); + const list = $('.li-h32f14 li:not(.clearfix)').slice(0, ctx.params.limit).get(); + const out = await Promise.all( + list.map(async (item) => { + const $ = cheerio.load(item); + const title = $('a').text(); + const itemUrl = url.resolve(host, $('a').attr('href')); - list.map(async (item) => { - const $ = cheerio.load(item); - const title = $('a').text(); - const itemUrl = url.resolve(host, $('a').attr('href')); + const cache = await ctx.cache.get(itemUrl); + if (cache) { + return Promise.resolve(JSON.parse(cache)); + } - const cache = await ctx.cache.get(itemUrl); - if (cache) { - return Promise.resolve(JSON.parse(cache)); - } + const res = await got.get(itemUrl); + const capture = cheerio.load(res.data); + const contents = capture('.zhengwen').html(); + const time = capture('div.laiyuan div.left').text().substring(0, 19); + const author = capture('.laiyuan').text().replace('分享到:', ''); - const res = await got.get(itemUrl); - const capture = cheerio.load(res.data); - const contents = capture('.zhengwen').html(); - const time = capture('div.laiyuan div.left').text().substring(0, 19); - const author = capture('.laiyuan').text().replace('分享到:', ''); + const single = { + title, + link: itemUrl, + guid: itemUrl, + author: author, + description: contents, + pubDate: new Date(time).toUTCString(), + }; - const single = { - title, - link: itemUrl, - guid: itemUrl, - author: author, - description: contents, - pubDate: new Date(time).toUTCString(), + return Promise.resolve(single); + }) + ); - }; - - return Promise.resolve(single); - }) - ); - - ctx.state.data = { - title: citytitle, - link: host, - item: out, - }; + ctx.state.data = { + title: citytitle, + link: host, + item: out, + }; }; diff --git a/lib/routes/fjnews/jjnews.js b/lib/routes/fjnews/jjnews.js index 67e0f5a51..89c72e302 100644 --- a/lib/routes/fjnews/jjnews.js +++ b/lib/routes/fjnews/jjnews.js @@ -4,41 +4,40 @@ const url = require('url'); const host = 'http://tt.m.jxnews.com.cn/jjtop/'; module.exports = async (ctx) => { - const response = await got.get(host); - const $ = cheerio.load(response.data); - const list = $('li.col-xs-12').get(); - const out = await Promise.all( + const response = await got.get(host); + const $ = cheerio.load(response.data); + const list = $('li.col-xs-12').get(); + const out = await Promise.all( + list.map(async (item) => { + const $ = cheerio.load(item); + const title = $('.list-text-style').text(); + const itemUrl = url.resolve(host, $('a').attr('href')); - list.map(async (item) => { - const $ = cheerio.load(item); - const title = $('.list-text-style').text(); - const itemUrl = url.resolve(host, $('a').attr('href')); + const cache = await ctx.cache.get(itemUrl); + if (cache) { + return Promise.resolve(JSON.parse(cache)); + } - const cache = await ctx.cache.get(itemUrl); - if (cache) { - return Promise.resolve(JSON.parse(cache)); - } + const res = await got.get(itemUrl); + const capture = cheerio.load(res.data); + const contents = capture('content').html(); + const time = capture('div.col-xs-8').text().substring(0, 19); - const res = await got.get(itemUrl); - const capture = cheerio.load(res.data); - const contents = capture('content').html(); - const time = capture('div.col-xs-8').text().substring(0, 19); + const single = { + title, + link: itemUrl, + guid: itemUrl, + description: contents, + pubDate: new Date(time).toUTCString(), + }; - const single = { - title, - link: itemUrl, - guid: itemUrl, - description : contents, - pubDate : new Date(time).toUTCString(), - }; + return Promise.resolve(single); + }) + ); - return Promise.resolve(single); - }) - ); - - ctx.state.data = { - title : '九江新闻', - link : host, - item : out, - }; + ctx.state.data = { + title: '九江新闻', + link: host, + item: out, + }; };