From 3c6d288330ba98dd27b5953b05e4088f230b7e95 Mon Sep 17 00:00:00 2001 From: Tony Date: Fri, 26 Aug 2022 13:04:02 -0300 Subject: [PATCH] feat(route): vom (#10624) --- docs/en/traditional-media.md | 12 +++++++++ docs/traditional-media.md | 12 +++++++++ lib/v2/vom/featured.js | 50 ++++++++++++++++++++++++++++++++++++ lib/v2/vom/maintainer.js | 3 +++ lib/v2/vom/radar.js | 13 ++++++++++ lib/v2/vom/router.js | 3 +++ 6 files changed, 93 insertions(+) create mode 100644 lib/v2/vom/featured.js create mode 100644 lib/v2/vom/maintainer.js create mode 100644 lib/v2/vom/radar.js create mode 100644 lib/v2/vom/router.js diff --git a/docs/en/traditional-media.md b/docs/en/traditional-media.md index 4e0e79a00..f6f7b6738 100644 --- a/docs/en/traditional-media.md +++ b/docs/en/traditional-media.md @@ -554,6 +554,18 @@ Provide full article RSS for WSJ topics. +## Voice of Mongolia + +### News + + + +| English | 日本語 | Монгол | Русский | 简体中文 | +| ------- | --- | ------ | ------- | ---- | +| en | ja | mn | ru | zh | + + + ## Yahoo ### News diff --git a/docs/traditional-media.md b/docs/traditional-media.md index d46299d8b..128c4a775 100644 --- a/docs/traditional-media.md +++ b/docs/traditional-media.md @@ -1414,6 +1414,18 @@ category 对应的关键词有 +## 蒙古之声 + +### 新闻 + + + +| English | 日本語 | Монгол | Русский | 简体中文 | +| ------- | --- | ------ | ------- | ---- | +| en | ja | mn | ru | zh | + + + ## 明报 ### 即时新闻 diff --git a/lib/v2/vom/featured.js b/lib/v2/vom/featured.js new file mode 100644 index 000000000..c1853dbe6 --- /dev/null +++ b/lib/v2/vom/featured.js @@ -0,0 +1,50 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const { parseDate } = require('@/utils/parse-date'); +const baseUrl = 'http://www.vom.mn'; + +module.exports = async (ctx) => { + const { lang = 'mn' } = ctx.params; + const { data: response } = await got(`${baseUrl}/${lang}`); + + const $ = cheerio.load(response); + + const items = [ + ...new Set( + $('#bigNewsSlide .item, #news_3 .item') + .toArray() + .map((item) => { + item = $(item); + return { + link: item.find('a').eq(0).attr('href'), + }; + }) + ), + ]; + + await Promise.all( + items.map((item) => + ctx.cache.tryGet(item.link, async () => { + const { data: response } = await got(item.link); + const $ = cheerio.load(response); + + item.title = $('h2').text(); + item.author = $('.uk-border-circle').next().text(); + item.pubDate = parseDate($('.vom-news-show-meta .right').prev().text()); + item.category = $('.vom-news-show-meta .uk-button-text').text(); + + $('.uk-article-title, .uk-text-meta, article .uk-grid-small').remove(); + + item.description = $('article').html(); + + return item; + }) + ) + ); + + ctx.state.data = { + title: $('meta[name=description]').attr('content'), + image: 'http://www.vom.mn/dist/images/vom-logo.png', + item: items, + }; +}; diff --git a/lib/v2/vom/maintainer.js b/lib/v2/vom/maintainer.js new file mode 100644 index 000000000..c4b7f5a83 --- /dev/null +++ b/lib/v2/vom/maintainer.js @@ -0,0 +1,3 @@ +module.exports = { + '/featured/:lang?': ['TonyRL'], +}; diff --git a/lib/v2/vom/radar.js b/lib/v2/vom/radar.js new file mode 100644 index 000000000..8bf8af811 --- /dev/null +++ b/lib/v2/vom/radar.js @@ -0,0 +1,13 @@ +module.exports = { + 'vom.mn': { + _name: '蒙古之声', + '.': [ + { + title: '新闻', + docs: 'https://docs.rsshub.app/traditional-media.html#meng-gu-zhi-sheng', + source: ['/:lang', '/'], + target: '/vom/featured/:lang', + }, + ], + }, +}; diff --git a/lib/v2/vom/router.js b/lib/v2/vom/router.js new file mode 100644 index 000000000..11186108b --- /dev/null +++ b/lib/v2/vom/router.js @@ -0,0 +1,3 @@ +module.exports = (router) => { + router.get('/featured/:lang?', require('./featured.js')); +};