* style: add eslint-unicorn * style: fix unicorn/no-useless-spread * style: fix unicorn/no-useless-promise-resolve-reject * style: fix unicorn/no-for-loop * fix: codeql bad HTML filtering regexp * fix: codeql incomplete replace * fix: unicorn/no-abusive-eslint-disable * style: fix unicorn/no-new-array * style: fix unicorn/no-typeof-undefined * style: fix unicorn/no-zero-fractions * style: fix unicorn/no-empty-file * style: fix unicorn/prefer-date-now * revert: auto fix unicorn/prefer-switch on lib/v2/kuaidi100/utils.js * style: fix unicorn/prefer-array-find * style: fix unicorn/prefer-array-flat * style: fix unicorn/prefer-array-flat-map * style: fix unicorn/prefer-at * style: fix unicorn/prefer-string-starts-ends-with * style: fix unicorn/prefer-includes * fix: codeql URL substring sanitization * style: fix unicorn/prefer-optional-catch-binding * style: fix unicorn/catch-error-name * style: fix unicorn/escape-case * style: fix unicorn/prefer-native-coercion-functions * style: fix unicorn/prefer-regexp-test * style: fix unicorn/require-array-join-separator * style: fix unicorn/prefer-math-trunc * style: fix unicorn/prefer-negative-index * style: fix unicorn/prefer-dom-node-dataset * style: fix unicorn/prefer-dom-node-text-content * style: fix unicorn/prefer-query-selector * style: fix unicorn/no-array-for-each * style: fix unicorn/no-negated-condition * style: fix unicorn/prefer-add-event-listener * style: fix unicorn/import-style * style: fix prefer-regex-literals * style: disable unicorn/no-useless-switch-case * style: disable unicorn/text-encoding-identifier-case * style: fix unicorn/prefer-set-has * style: fix unicorn/prefer-spread * revert: auto fix on lib/routes/universities/ynnu/edu/base64.js * style: fix unicorn/no-useless-undefined * style: fix unicorn/no-array-push-push * style: fix unicorn/no-useless-undefined again * style: fix unicorn/no-lonely-if * style: fix unicorn/prefer-reflect-apply * style: fix unicorn/switch-case-braces * style: fix unicorn/prefer-switch * style: fix unicorn/prefer-array-some * fix: deepscan UNUSED_VAR_ASSIGN * style: fix unicorn/prefer-ternary * fix: follow-up of unicorn/prefer-ternary * revert: auto fix of unicorn/prefer-string-slice for substring() * style: disable unicorn/prefer-string-slice fix: auto fix slice over deprecated substr * style: fix unicorn/throw-new-error * style: fix unicorn/filename-case * test: fix dateParser renaming * style: fix unicorn/better-regex * style: fix unicorn/prefer-string-replace-all * fix(deps): add sanitize-html * style: fix no-prototype-builtins * style: fix unicorn/consistent-destructuring * style: fix unicorn/consistent-function-scoping * style: fix unicorn/prefer-regexp-test * style: fix unicorn/prefer-logical-operator-over-ternary * style: fix unicorn/no-array-callback-reference * style: add prefer-object-has-own * style: warn unicorn/no-empty-file * style: fix unicorn/prefer-number-properties * style: fix no-useless-undefined again * style: fix unicorn/numeric-separators-style * style: disable unicorn/no-array-callback-reference false postive with cheerio
68 lines
2.7 KiB
JavaScript
68 lines
2.7 KiB
JavaScript
const got = require('@/utils/got');
|
|
const { parseDate } = require('@/utils/parse-date');
|
|
const cheerio = require('cheerio');
|
|
|
|
module.exports = async (ctx) => {
|
|
let category = ctx.params.category;
|
|
// 这里的category是个形参
|
|
const dic_html = { tzgg: 'tzgg.htm', gzdt: 'gzdt.htm' };
|
|
const dic_title = { tzgg: '通知公告', gzdt: '工作动态' };
|
|
|
|
// 设置默认值
|
|
if (dic_title[category] === undefined) {
|
|
category = 'tzgg';
|
|
}
|
|
|
|
const response = await got({
|
|
method: 'get',
|
|
url: 'http://renshichu.xaut.edu.cn/' + dic_html[category],
|
|
});
|
|
const data = response.body;
|
|
const $ = cheerio.load(data);
|
|
|
|
// 这个列表指通知公告详情列表
|
|
const list = $('.vsb-space.n_right .list .cleafix')
|
|
.map((_, item) => {
|
|
item = $(item);
|
|
// 工作动态栏目里有一些是外链,这里做个判断
|
|
const a = item.find('.list_wen a').eq(0).attr('href');
|
|
const link = a.slice(0, 4) === 'http' ? a : 'http://renshichu.xaut.edu.cn/' + a;
|
|
// 这里jquery比较长,引几个中间变量倒是方便阅读,但是我还是觉得不需要
|
|
const title = item.find('.list_wen a.tit').text();
|
|
return {
|
|
title,
|
|
link,
|
|
};
|
|
})
|
|
.get();
|
|
ctx.state.data = {
|
|
// 源标题
|
|
title: '西安理工大学人事处-' + dic_title[category],
|
|
// 源链接
|
|
link: 'http://renshichu.xaut.edu.cn',
|
|
// 源说明
|
|
description: `西安理工大学人事处-` + dic_title[category],
|
|
// 遍历此前获取的数据
|
|
item: await Promise.all(
|
|
list.map((item) =>
|
|
ctx.cache.tryGet(item.link, async () => {
|
|
// 下面的if判断是否属于外链,使用切片的方式来判断,并不优雅,先用着吧
|
|
if (item.link.slice(0, 16) === 'http://renshichu') {
|
|
// 不属于外链
|
|
const res = await got({
|
|
method: 'get',
|
|
url: item.link,
|
|
});
|
|
const content = cheerio.load(res.body);
|
|
item.description = content('.vsb-space form[name]').html();
|
|
item.pubDate = parseDate(content('.vsb-space form[name] h3 span:contains(时间)').text().slice(3));
|
|
} else {
|
|
item.description = '这是一个外链("▔□▔)/("▔□▔)/所以你没法直接看到内容' + item.link;
|
|
}
|
|
return item;
|
|
})
|
|
)
|
|
),
|
|
};
|
|
};
|