feat(route): add agirls (#8782)

This commit is contained in:
Tony
2022-01-22 20:17:29 +00:00
committed by GitHub
parent 49827f24f1
commit d65075ac2f
8 changed files with 242 additions and 0 deletions
+20
View File
@@ -1406,6 +1406,26 @@ area 分区选项
<Route author="LogicJake" example="/imaijia/category/xls" path="/imaijia/category/:category" :paramsDesc="['类别id,可在 URL 中找到']" />
## 电獭少女
### 分类
<Route author="TonyRL" example="/agirls/app" path="/agirls/:category?" :paramsDesc="['分类,默认为最新文章,可在对应主题页的 URL 中找到,下表仅列出部分']" radar="1" rssbud="1">
| App 评测 | 手机开箱 | 笔电开箱 | 3C 周边 | 教学小技巧 | 科技情报 |
| -------- | -------- | -------- | ----------- | ---------- | -------- |
| app | phone | computer | accessories | tutorial | techlife |
</Route>
### 精选主题
<Route author="TonyRL" example="/agirls/topic/iphone13" path="/agirls/topic/:topic" :paramsDesc="['精选主题,可通过下方精选主题列表获得']" radar="1" rssbud="1"/>
### 当前精选主题列表
<Route author="TonyRL" example="/agirls/topic_list" path="/agirls/topic_list" radar="1" rssbud="1"/>
## 丁香园
### 新冠疫苗实时动态
+71
View File
@@ -0,0 +1,71 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const { parseDate } = require('@/utils/parse-date');
const timezone = require('@/utils/timezone');
const path = require('path');
const { art } = require('@/utils/render');
module.exports = async (ctx) => {
const baseUrl = 'https://agirls.aotter.net';
const category = ctx.params.category ?? '';
const response = await got({
url: baseUrl + '/posts' + (category ? `/${category}` : ''),
header: {
Referer: baseUrl,
},
});
const $ = cheerio.load(response.data);
let items = $('div a.flex.flex-col')
.map((_, item) => {
item = $(item);
return {
title: item.find('h2').text().trim(),
link: baseUrl + item.attr('href'),
};
})
.get();
items = await Promise.all(
items.map((item) =>
ctx.cache.tryGet(item.link, async () => {
const detailResponse = await got({
url: item.link,
header: {
Referer: baseUrl + '/posts/' + (category ? `/${category}` : ''),
},
});
const content = cheerio.load(detailResponse.data);
item.category = content('a.mr-2.bg-neutral-lightest.px-2.py-1.text-sm.text-neutral-light')
.toArray()
.map((e) => content(e).text().trim().replace('#', ''));
item.description = art(path.join(__dirname, 'templates/description.art'), {
desc: content('div.post-content').html(),
});
item.pubDate = timezone(parseDate(content('time').text().trim()), +8);
item.author = content('a.mr-1.text-primary').text().trim();
return item;
})
)
);
ctx.state.data = {
title: $('head title').text().trim(),
link: baseUrl + '/' + category,
description: $('head meta[name=description]').attr('content'),
item: items,
language: $('html').attr('lang'),
};
ctx.state.json = {
title: $('head title').text().trim(),
link: baseUrl + '/' + category,
description: $('head meta[name=description]').attr('content'),
item: items,
language: $('html').attr('lang'),
};
};
+5
View File
@@ -0,0 +1,5 @@
module.exports = {
'/topic/:topic': ['TonyRL'],
'/topic_list': ['TonyRL'],
'/:category?': ['TonyRL'],
};
+25
View File
@@ -0,0 +1,25 @@
module.exports = {
'aotter.net': {
_name: '電獺少女',
agirls: [
{
title: '分類',
docs: 'https://docs.rsshub.app/new-media.html##dian-ta-shao-nu',
source: ['/posts/:category'],
target: '/agirls/:category',
},
{
title: '精選主題列表',
docs: 'https://docs.rsshub.app/new-media.html##dian-ta-shao-nu',
source: ['/', '/topic'],
target: '/agirls/topic_list',
},
{
title: '精选主题',
docs: 'https://docs.rsshub.app/new-media.html##dian-ta-shao-nu',
source: ['/topic/:topic'],
target: '/agirls/topic/:topic',
},
],
},
};
+5
View File
@@ -0,0 +1,5 @@
module.exports = function (router) {
router.get('/topic/:topic', require('./topic'));
router.get('/topic_list', require('./topic_list'));
router.get('/:category?', require('./index'));
};
+1
View File
@@ -0,0 +1 @@
{{@ desc }}
+71
View File
@@ -0,0 +1,71 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const { parseDate } = require('@/utils/parse-date');
const timezone = require('@/utils/timezone');
const path = require('path');
const { art } = require('@/utils/render');
module.exports = async (ctx) => {
const baseUrl = 'https://agirls.aotter.net';
const topic = ctx.params.topic;
const response = await got({
url: baseUrl + '/topic/' + topic,
header: {
Referer: baseUrl,
},
});
const $ = cheerio.load(response.data);
let items = $('div.col-12 div.row a')
.map((_, item) => {
item = $(item);
return {
title: item.find('h3').text().trim(),
link: baseUrl + item.attr('href'),
};
})
.get();
items = await Promise.all(
items.map((item) =>
ctx.cache.tryGet(item.link, async () => {
const detailResponse = await got({
url: item.link,
header: {
Referer: baseUrl + '/topic/' + topic,
},
});
const content = cheerio.load(detailResponse.data);
item.category = content('a.mr-2.bg-neutral-lightest.px-2.py-1.text-sm.text-neutral-light')
.toArray()
.map((e) => content(e).text().trim().replace('#', ''));
item.description = art(path.join(__dirname, 'templates/description.art'), {
desc: content('div.post-content').html(),
});
item.pubDate = timezone(parseDate(content('time').text().trim()), +8);
item.author = content('a.mr-1.text-primary').text().trim();
return item;
})
)
);
ctx.state.data = {
title: $('head title').text().trim(),
link: baseUrl + '/' + topic,
description: $('head meta[name=description]').attr('content'),
item: items,
language: $('html').attr('lang'),
};
ctx.state.json = {
title: $('head title').text().trim(),
link: baseUrl + '/' + topic,
description: $('head meta[name=description]').attr('content'),
item: items,
language: $('html').attr('lang'),
};
};
+44
View File
@@ -0,0 +1,44 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
module.exports = async (ctx) => {
const baseUrl = 'https://agirls.aotter.net';
const category = 'topic';
const response = await got({
url: baseUrl + '/' + category,
header: {
Referer: baseUrl,
},
});
const $ = cheerio.load(response.data);
const items = $('div div.border-b.border-neutral-lighter')
.map((_, item) => {
item = $(item);
const link = baseUrl + item.find('a').attr('href');
return ctx.cache.tryGet(link, () => ({
title: item.find('h2').text().trim(),
description: item.find('a').attr('href').replace('/topic/', ''),
link,
}));
})
.get();
ctx.state.data = {
title: $('head title').text().trim(),
link: baseUrl + '/' + category,
description: $('head meta[name=description]').attr('content'),
item: items,
language: $('html').attr('lang'),
};
ctx.state.json = {
title: $('head title').text().trim(),
link: baseUrl + '/' + category,
description: $('head meta[name=description]').attr('content'),
item: items,
language: $('html').attr('lang'),
};
};