feat(route): gamme (#10728)

This commit is contained in:
Tony 2022-09-06 11:11:48 -08:00 committed by GitHub
parent 9329a44c80
commit 5ac511199d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 148 additions and 0 deletions

View File

@ -2478,6 +2478,24 @@ column 为 third 时可选的 category:
<Route author="WenryXu" example="/juesheng" path="/juesheng"/>
## 卡卡洛普
### 宅宅新聞 - 分類
<Route author="TonyRL" example="/gamme/news" path="/gamme/news/:category?" :paramsDesc="['分類名,可在 URL 找到,預設為 `all`']" radar="1" rssbud="1"/>
### 宅宅新聞 - 標籤
<Route author="TonyRL" example="/gamme/news/tag/歐派" path="/gamme/news/tag/:tag" :paramsDesc="['標籤,可在 URL 找到']" radar="1" rssbud="1"/>
### 西斯新聞 - 分類
<Route author="TonyRL" example="/gamme/sexynews" path="/gamme/sexynews/:category?" :paramsDesc="['分類名,可在 URL 找到,預設為 `all`']" radar="1" rssbud="1"/>
### 西斯新聞 - 標籤
<Route author="TonyRL" example="/gamme/sexynews/tag/歐派" path="/gamme/sexynews/tag/:tag" :paramsDesc="['標籤,可在 URL 找到']" radar="1" rssbud="1"/>
## 科技島讀
### 分類

38
lib/v2/gamme/category.js Normal file
View File

@ -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,
};
};

View File

@ -0,0 +1,6 @@
module.exports = {
'/news/:category?': ['TonyRL'],
'/news/tag/:tag': ['TonyRL'],
'/sexynews/:category?': ['TonyRL'],
'/sexynews/tag/:tag': ['TonyRL'],
};

33
lib/v2/gamme/radar.js Normal file
View File

@ -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',
},
],
},
};

4
lib/v2/gamme/router.js Normal file
View File

@ -0,0 +1,4 @@
module.exports = (router) => {
router.get('/:domain/:category?', require('./category'));
router.get('/:domain/tag/:tag', require('./tag'));
};

49
lib/v2/gamme/tag.js Normal file
View File

@ -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,
};
};