Files
RSSHub/lib/routes/dbaplus/activity.js
2021-11-27 07:18:37 +00:00

36 lines
1.0 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
const got = require('@/utils/got');
const cheerio = require('cheerio');
const timezone = require('@/utils/timezone');
module.exports = async (ctx) => {
const type = ctx.params.type || 'online';
const rootUrl = 'https://dbaplus.cn';
const currentUrl = `${rootUrl}/activity-${type === 'online' ? '12' : '48'}-1.html`;
const response = await got({
method: 'get',
url: currentUrl,
});
const $ = cheerio.load(response.data);
const items = $('.media')
.map((_, item) => {
item = $(item);
return {
title: item.find('.media-heading').text(),
link: item.find('.pull-left').attr('href'),
description: `<img src="${item.find('.media-object').attr('src')}">`,
pubDate: timezone(new Date(item.find('.time').text().replace('时间:', '')), +8),
};
})
.get();
ctx.state.data = {
title: $('title').text().split('')[0],
link: currentUrl,
item: items,
};
};