Files
RSSHub/lib/v2/dhu/yjs/zs.js
T
fox2049andYuexin Sun 9d13d768cd feat(router): add link content of dhu/yjs/zs (#12627)
* add yjszs info of dhu

* change order and add zs make

* 4 spaces for indentation, camelCase, del utf-8 decoder, link to string

* code proofreading
* delete got params
* update link code
* delete link body in ctx.state.data

* Update lib/v2/dhu/maintainer.js

* code proofreading
* example update
* html parse update

* add content

* delete comments

* delete comments

* update code from remote

* add link content

* link update

---------

Co-authored-by: Yuexin Sun <m090120303@outlook.com>
2023-06-07 20:16:00 +08:00

47 lines
1.3 KiB
JavaScript

const got = require('@/utils/got');
const cheerio = require('cheerio');
const { parseDate } = require('@/utils/parse-date');
const baseUrl = 'https://yjszs.dhu.edu.cn';
const map = {
doctor: '/7126/list.htm',
master: '/7128/list.htm',
};
module.exports = async (ctx) => {
const type = ctx.params.type || 'master';
const link = `${baseUrl}${map[type]}`;
const { data: response } = await got(link);
const $ = cheerio.load(response);
const list = $('.list_item')
.toArray()
.map((item) => {
item = $(item);
const a = item.find('a').first();
return {
title: a.attr('title'),
link: `${baseUrl}${a.attr('href')}`,
pubDate: parseDate(item.find('.Article_PublishDate').text()),
};
});
// item content
const items = await Promise.all(
list.map((item) =>
ctx.cache.tryGet(item.link, async () => {
const { data: response } = await got(item.link);
const $ = cheerio.load(response);
item.description = $('.wp_articlecontent').first().html();
return item;
})
)
);
ctx.state.data = {
title: '东华大学研究生-' + $('.col_title').text(),
link,
item: items,
};
};