feat(route): gamme (#10728)
This commit is contained in:
parent
9329a44c80
commit
5ac511199d
|
|
@ -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"/>
|
||||
|
||||
## 科技島讀
|
||||
|
||||
### 分類
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
};
|
||||
};
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
module.exports = {
|
||||
'/news/:category?': ['TonyRL'],
|
||||
'/news/tag/:tag': ['TonyRL'],
|
||||
'/sexynews/:category?': ['TonyRL'],
|
||||
'/sexynews/tag/:tag': ['TonyRL'],
|
||||
};
|
||||
|
|
@ -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',
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
module.exports = (router) => {
|
||||
router.get('/:domain/:category?', require('./category'));
|
||||
router.get('/:domain/tag/:tag', require('./tag'));
|
||||
};
|
||||
|
|
@ -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,
|
||||
};
|
||||
};
|
||||
Loading…
Reference in New Issue