diff --git a/docs/new-media.md b/docs/new-media.md index 5e0620e8c..ad8e0b700 100644 --- a/docs/new-media.md +++ b/docs/new-media.md @@ -2478,6 +2478,24 @@ column 为 third 时可选的 category: +## 卡卡洛普 + +### 宅宅新聞 - 分類 + + + +### 宅宅新聞 - 標籤 + + + +### 西斯新聞 - 分類 + + + +### 西斯新聞 - 標籤 + + + ## 科技島讀 ### 分類 diff --git a/lib/v2/gamme/category.js b/lib/v2/gamme/category.js new file mode 100644 index 000000000..097b954dd --- /dev/null +++ b/lib/v2/gamme/category.js @@ -0,0 +1,38 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const parser = require('@/utils/rss-parser'); + +module.exports = async (ctx) => { + const { domain = 'news', category } = ctx.params; + const baseUrl = `https://${domain}.gamme.com.tw`; + const feed = await parser.parseURL(`${baseUrl + (category ? `/category/${category}` : '')}/feed`); + + await Promise.all( + feed.items.map((item) => + ctx.cache.tryGet(item.link, async () => { + const { data } = await got(item.link); + const $ = cheerio.load(data); + + item.author = $('.author_name').text().trim(); + item.category = $('.tags a') + .toArray() + .map((tag) => $(tag).text()); + $('.social_block, .tags').remove(); + item.description = $('.entry').html(); + + delete item.content; + delete item.contentSnippet; + delete item.isoDate; + return item; + }) + ) + ); + + ctx.state.data = { + title: feed.title, + link: feed.link, + image: domain === 'news' ? `${baseUrl}/blogico.ico` : `${baseUrl}/favicon.ico`, + description: feed.description, + item: feed.items, + }; +}; diff --git a/lib/v2/gamme/maintainer.js b/lib/v2/gamme/maintainer.js new file mode 100644 index 000000000..3167641c6 --- /dev/null +++ b/lib/v2/gamme/maintainer.js @@ -0,0 +1,6 @@ +module.exports = { + '/news/:category?': ['TonyRL'], + '/news/tag/:tag': ['TonyRL'], + '/sexynews/:category?': ['TonyRL'], + '/sexynews/tag/:tag': ['TonyRL'], +}; diff --git a/lib/v2/gamme/radar.js b/lib/v2/gamme/radar.js new file mode 100644 index 000000000..760371a0a --- /dev/null +++ b/lib/v2/gamme/radar.js @@ -0,0 +1,33 @@ +module.exports = { + 'gamme.com.tw': { + _name: '卡卡洛普', + news: [ + { + title: '宅宅新聞 - 分類', + docs: 'https://docs.rsshub.app/new-media.html#ka-ka-luo-pu', + source: ['/category/:category', '/'], + target: (params) => `/gamme/news${params.category ? `/${params.category}` : ''}`, + }, + { + title: '宅宅新聞 - 標籤', + docs: 'https://docs.rsshub.app/new-media.html#ka-ka-luo-pu', + source: ['/tag/:tag'], + target: '/gamme/news/tag/:tag', + }, + ], + sexynews: [ + { + title: '西斯新聞 - 分類', + docs: 'https://docs.rsshub.app/new-media.html#ka-ka-luo-pu', + source: ['/category/:category', '/'], + target: (params) => `/gamme/sexynews${params.category ? `/${params.category}` : ''}`, + }, + { + title: '西斯新聞 - 標籤', + docs: 'https://docs.rsshub.app/new-media.html#ka-ka-luo-pu', + source: ['/tag/:tag'], + target: '/gamme/sexynews/tag/:tag', + }, + ], + }, +}; diff --git a/lib/v2/gamme/router.js b/lib/v2/gamme/router.js new file mode 100644 index 000000000..cf5702a4a --- /dev/null +++ b/lib/v2/gamme/router.js @@ -0,0 +1,4 @@ +module.exports = (router) => { + router.get('/:domain/:category?', require('./category')); + router.get('/:domain/tag/:tag', require('./tag')); +}; diff --git a/lib/v2/gamme/tag.js b/lib/v2/gamme/tag.js new file mode 100644 index 000000000..27088ddc7 --- /dev/null +++ b/lib/v2/gamme/tag.js @@ -0,0 +1,49 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const { parseDate } = require('@/utils/parse-date'); + +module.exports = async (ctx) => { + const { domain = 'news', tag } = ctx.params; + const baseUrl = `https://${domain}.gamme.com.tw`; + const pageUrl = `${baseUrl}/tag/${tag}`; + + const { data } = await got(pageUrl); + const $ = cheerio.load(data); + + const items = $('#category_new li a, .List-4 h3 a') + .toArray() + .map((item) => { + item = $(item); + return { + title: item.attr('title') || item.text(), + link: item.attr('href'), + }; + }); + + await Promise.all( + items.map((item) => + ctx.cache.tryGet(item.link, async () => { + const { data } = await got(item.link); + const $ = cheerio.load(data); + + item.author = $('.author_name').text().trim(); + item.category = $('.tags a') + .toArray() + .map((tag) => $(tag).text()); + $('.social_block, .tags').remove(); + item.pubDate = parseDate($('.postDate').attr('content')); + item.description = $('.entry').html(); + + return item; + }) + ) + ); + + ctx.state.data = { + title: `${tag} | ${domain === 'news' ? '宅宅新聞' : '西斯新聞'}`, + description: $('meta[name=description]').attr('content'), + link: pageUrl, + image: domain === 'news' ? `${baseUrl}/blogico.ico` : `${baseUrl}/favicon.ico`, + item: items, + }; +};