diff --git a/docs/en/new-media.md b/docs/en/new-media.md index 40b591c33..6d55f5a5c 100644 --- a/docs/en/new-media.md +++ b/docs/en/new-media.md @@ -375,6 +375,18 @@ Provides a better reading experience (full text articles) over the official one. +## KBS + +### Today + + + +| 한국어 | عربي | 中国语 | English | Français | Deutsch | Bahasa Indonesia | 日本語 | Русский | Español | Tiếng Việt | +| ------ | ---- | ------ | ------- | -------- | ------- | ---------------- | ------ | ------- | ------- | ---------- | +| k | a | c | e | f | g | i | j | r | s | v | + + + ## Letterboxd ### User diary diff --git a/docs/new-media.md b/docs/new-media.md index cf9e968b8..79f72808b 100644 --- a/docs/new-media.md +++ b/docs/new-media.md @@ -597,6 +597,18 @@ Tag +## KBS + +### Today + + + +| 한국어 | عربي | 中国语 | English | Français | Deutsch | Bahasa Indonesia | 日本語 | Русский | Español | Tiếng Việt | +| ------ | ---- | ------ | ------- | -------- | ------- | ---------------- | ------ | ------- | ------- | ---------- | +| k | a | c | e | f | g | i | j | r | s | v | + + + ## Kotaku ### Story diff --git a/lib/router.js b/lib/router.js index 4bd248abf..32a68b554 100644 --- a/lib/router.js +++ b/lib/router.js @@ -4254,4 +4254,7 @@ router.get('/fashionnetwork/headline/:country?', lazyloadRouteHandler('./routes/ // Deprecated: DO NOT ADD ROUTE HERE +// KBS +router.get('/kbs/today/:language?', lazyloadRouteHandler('./routes/kbs/today')); + module.exports = router; diff --git a/lib/routes/kbs/today.js b/lib/routes/kbs/today.js new file mode 100644 index 000000000..e511fb854 --- /dev/null +++ b/lib/routes/kbs/today.js @@ -0,0 +1,56 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const timezone = require('@/utils/timezone'); +const { parseDate } = require('@/utils/parse-date'); + +module.exports = async (ctx) => { + const language = ctx.params.language || 'e'; + + const rootUrl = 'http://world.kbs.co.kr'; + const currentUrl = `${rootUrl}/service/news_today.htm?lang=${language}`; + + const response = await got({ + method: 'get', + url: currentUrl, + }); + + const $ = cheerio.load(response.data); + + const list = $('.comp_text_1x article') + .map((_, item) => { + item = $(item); + + const a = item.find('h2 a'); + + return { + title: a.text(), + category: item.find('.cate').text(), + link: `${rootUrl}/service${a.attr('href').replace('./', '/')}`, + pubDate: timezone(parseDate(item.find('.date').text()), +9), + }; + }) + .get(); + + const items = await Promise.all( + list.map((item) => + ctx.cache.tryGet(item.link, async () => { + const detailResponse = await got({ + method: 'get', + url: item.link, + }); + + const content = cheerio.load(detailResponse.data); + + item.description = content('.body_txt').html(); + + return item; + }) + ) + ); + + ctx.state.data = { + title: `Latest News | KBS WORLD`, + link: currentUrl, + item: items, + }; +};