From 081953f9f92467ca27ebbed41be6018efa81cc76 Mon Sep 17 00:00:00 2001 From: Ethan Shen Date: Sun, 23 Jan 2022 00:10:17 +0800 Subject: [PATCH] =?UTF-8?q?feat(route):=20add=20=E6=B7=B1=E7=84=A6=20(#862?= =?UTF-8?q?7)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/new-media.md | 12 +++++++ lib/v2/filmdeepfocus/index.js | 58 ++++++++++++++++++++++++++++++ lib/v2/filmdeepfocus/maintainer.js | 3 ++ lib/v2/filmdeepfocus/radar.js | 13 +++++++ lib/v2/filmdeepfocus/router.js | 3 ++ 5 files changed, 89 insertions(+) create mode 100644 lib/v2/filmdeepfocus/index.js create mode 100644 lib/v2/filmdeepfocus/maintainer.js create mode 100644 lib/v2/filmdeepfocus/radar.js create mode 100644 lib/v2/filmdeepfocus/router.js diff --git a/docs/new-media.md b/docs/new-media.md index 79f72808b..75f4718e1 100644 --- a/docs/new-media.md +++ b/docs/new-media.md @@ -2498,6 +2498,18 @@ column 为 third 时可选的 category: +## 深焦 + +### 分类 + + + +| 影评 | 影人 | 特别策划 | 专访 | 书评 | +| ---- | ---------- | ---------- | ---------- | ---------- | +| page | new-page-3 | new-page-2 | new-page-4 | new-page-1 | + + + ## 深圳新闻网 ### 深圳市政府新闻发布厅 diff --git a/lib/v2/filmdeepfocus/index.js b/lib/v2/filmdeepfocus/index.js new file mode 100644 index 000000000..6647f9cd8 --- /dev/null +++ b/lib/v2/filmdeepfocus/index.js @@ -0,0 +1,58 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const { parseDate } = require('@/utils/parse-date'); + +module.exports = async (ctx) => { + const category = ctx.params.category ?? 'page'; + + const rootUrl = 'https://www.filmdeepfocus.com'; + const currentUrl = `${rootUrl}/${category}`; + + const response = await got({ + method: 'get', + url: currentUrl, + }); + + const $ = cheerio.load(response.data); + + let items = $('.summary-title-link') + .slice(0, ctx.query.limit ? parseInt(ctx.query.limit) : 20) + .toArray() + .map((item) => { + item = $(item); + + return { + title: item.text(), + link: `${rootUrl}${item.attr('href')}`, + }; + }); + + items = await Promise.all( + items.map((item) => + ctx.cache.tryGet(item.link, async () => { + const detailResponse = await got({ + method: 'get', + url: item.link, + }); + + const content = cheerio.load(detailResponse.data); + + content('.image-block').each(function () { + content(this).html(``); + }); + + item.description = content('.entry-content').html(); + item.author = content('meta[itemprop="publisher"]').attr('content'); + item.pubDate = parseDate(content('meta[itemprop="datePublished"]').attr('content')); + + return item; + }) + ) + ); + + ctx.state.data = { + title: $('title').text(), + link: currentUrl, + item: items, + }; +}; diff --git a/lib/v2/filmdeepfocus/maintainer.js b/lib/v2/filmdeepfocus/maintainer.js new file mode 100644 index 000000000..81eb78d73 --- /dev/null +++ b/lib/v2/filmdeepfocus/maintainer.js @@ -0,0 +1,3 @@ +module.exports = { + '/:category?': ['nczitzk'], +}; diff --git a/lib/v2/filmdeepfocus/radar.js b/lib/v2/filmdeepfocus/radar.js new file mode 100644 index 000000000..4e2917f8d --- /dev/null +++ b/lib/v2/filmdeepfocus/radar.js @@ -0,0 +1,13 @@ +module.exports = { + 'filmdeepfocus.com': { + _name: '深焦', + '.': [ + { + title: '分类', + docs: 'https://docs.rsshub.app/new-media.html#shen-jiao-fen-lei', + source: ['/:category', '/'], + target: '/filmdeepfocus/:category?', + }, + ], + }, +}; diff --git a/lib/v2/filmdeepfocus/router.js b/lib/v2/filmdeepfocus/router.js new file mode 100644 index 000000000..cf781366f --- /dev/null +++ b/lib/v2/filmdeepfocus/router.js @@ -0,0 +1,3 @@ +module.exports = function (router) { + router.get('/:category?', require('./index')); +};