mirror of
https://github.com/DIYgod/RSSHub.git
synced 2026-09-24 23:12:34 +08:00
@@ -0,0 +1,65 @@
|
||||
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 category = ctx.params.category ?? 'posts';
|
||||
|
||||
const rootUrl = 'https://allrecode.com';
|
||||
const currentUrl = `${rootUrl}/${category}`;
|
||||
|
||||
const response = await got({
|
||||
method: 'get',
|
||||
url: currentUrl,
|
||||
});
|
||||
|
||||
const $ = cheerio.load(response.data);
|
||||
|
||||
let items = $('h3 a')
|
||||
.toArray()
|
||||
.map((item) => {
|
||||
item = $(item);
|
||||
|
||||
return {
|
||||
title: item.text(),
|
||||
link: item.attr('href'),
|
||||
};
|
||||
});
|
||||
|
||||
items = await Promise.all(
|
||||
items.map((item) =>
|
||||
ctx.cache.tryGet(item.link, async () => {
|
||||
const detailResponse = await got({
|
||||
method: 'get',
|
||||
url: item.link,
|
||||
});
|
||||
|
||||
const content = cheerio.load(detailResponse.data);
|
||||
|
||||
item.author = content('.author').text();
|
||||
item.category = content('meta[name="keywords"]').attr('content').split(',');
|
||||
item.pubDate = timezone(
|
||||
parseDate(
|
||||
content('.edit')
|
||||
.text()
|
||||
.match(/\d{4}-\d{2}-\d{2} \d{2}:\d{2}/)
|
||||
),
|
||||
+8
|
||||
);
|
||||
|
||||
content('.edit, .shang').remove();
|
||||
|
||||
item.description = content('.article-content').html();
|
||||
|
||||
return item;
|
||||
})
|
||||
)
|
||||
);
|
||||
|
||||
ctx.state.data = {
|
||||
title: $('title').text(),
|
||||
link: currentUrl,
|
||||
item: items,
|
||||
};
|
||||
};
|
||||
@@ -0,0 +1,5 @@
|
||||
module.exports = {
|
||||
'/news': ['nczitzk'],
|
||||
'/recommends': ['nczitzk'],
|
||||
'/:category?': ['nczitzk'],
|
||||
};
|
||||
@@ -0,0 +1,35 @@
|
||||
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 rootUrl = 'https://allrecode.com';
|
||||
const currentUrl = `${rootUrl}/news`;
|
||||
|
||||
const response = await got({
|
||||
method: 'get',
|
||||
url: currentUrl,
|
||||
});
|
||||
|
||||
const $ = cheerio.load(response.data);
|
||||
|
||||
const items = $('.news-trigger')
|
||||
.toArray()
|
||||
.map((item) => {
|
||||
item = $(item);
|
||||
|
||||
return {
|
||||
title: item.text(),
|
||||
link: item.attr('href'),
|
||||
pubDate: timezone(parseDate(item.parent().prev().text(), 'HH:mm'), +8),
|
||||
description: item.parent().next().html(),
|
||||
};
|
||||
});
|
||||
|
||||
ctx.state.data = {
|
||||
title: $('title').text(),
|
||||
link: currentUrl,
|
||||
item: items,
|
||||
};
|
||||
};
|
||||
@@ -0,0 +1,25 @@
|
||||
module.exports = {
|
||||
'allrecode.com': {
|
||||
_name: '重构',
|
||||
'.': [
|
||||
{
|
||||
title: '推荐',
|
||||
docs: 'https://docs.rsshub.app/news-media.html#chong-gou-tui-jian',
|
||||
source: ['/recommends', '/'],
|
||||
target: '/allrecode/recommends',
|
||||
},
|
||||
{
|
||||
title: '快讯',
|
||||
docs: 'https://docs.rsshub.app/news-media.html#chong-gou-kuai-xun',
|
||||
source: ['/news', '/'],
|
||||
target: '/allrecode/news',
|
||||
},
|
||||
{
|
||||
title: '资讯',
|
||||
docs: 'https://docs.rsshub.app/news-media.html#chong-gou-zi-xun',
|
||||
source: ['/:category', '/'],
|
||||
target: '/allrecode/:category',
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
@@ -0,0 +1,4 @@
|
||||
module.exports = function (router) {
|
||||
router.get('/news', require('./news'));
|
||||
router.get('/:category?', require('./index'));
|
||||
};
|
||||
Reference in New Issue
Block a user