* chore(deps-dev): bump eslint-plugin-unicorn from 66.0.0 to 68.0.0 Bumps [eslint-plugin-unicorn](https://github.com/sindresorhus/eslint-plugin-unicorn) from 66.0.0 to 68.0.0. - [Release notes](https://github.com/sindresorhus/eslint-plugin-unicorn/releases) - [Commits](https://github.com/sindresorhus/eslint-plugin-unicorn/compare/v66.0.0...v68.0.0) --- updated-dependencies: - dependency-name: eslint-plugin-unicorn dependency-version: 68.0.0 dependency-type: direct:development update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] <support@github.com> * style: fix no-useless-coercion * style: fix prefer-boolean-return * style: fix no-useless-logical-operand * style: fix prefer-single-replace * style: fix consistent-conditional-object-spread * style: fix no-useless-else * style: fix prefer-unicode-code-point-escapes * style: fix operator-assignment * style: fix prefer-continue * style: fix prefer-math-constants * style: fix prefer-hoisting-branch-code * style: fix prefer-array-slice * style: fix consistent-class-member-order * style: fix no-return-array-push * style: fix prefer-promise-with-resolvers * style: fix no-array-concat-in-loop * style: fix no-loop-iterable-mutation * style: fix no-invalid-argument-count * style: fix no-duplicate-if-branches * style: fix prefer-else-if * style: fix no-unreadable-for-of-expression * style: fix logical-assignment-operators * style: fix default-export-style * style: revert false positve in prefer-type-literal-last in #22274 * style: fix arrow-body-style * style: add v68 recommended preset * style: refactor GraphQL queries to use template literals for better readability --------- Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Tony <TonyRL@users.noreply.github.com>
78 lines
3.0 KiB
TypeScript
78 lines
3.0 KiB
TypeScript
import { load } from 'cheerio';
|
|
import iconv from 'iconv-lite';
|
|
|
|
import cache from '@/utils/cache';
|
|
import got from '@/utils/got';
|
|
import { parseDate } from '@/utils/parse-date';
|
|
import timezone from '@/utils/timezone';
|
|
|
|
export default {
|
|
parseFeed: async ({ subjectid }) => {
|
|
const url = `https://www.dapenti.com/blog/blog.asp?name=xilei&subjectid=${subjectid}`;
|
|
const listRes = await got({
|
|
method: 'get',
|
|
url,
|
|
headers: {
|
|
Referer: url,
|
|
},
|
|
// 喷嚏网编码为GBK,需要转码
|
|
// 转码需要设定返回数据的格式,其可选项是arraybuffer,blob,document,json,text,stream
|
|
// 默认为json
|
|
responseType: 'buffer',
|
|
});
|
|
// 转码
|
|
const data = iconv.decode(listRes.data, 'gb2312');
|
|
const $ = load(data);
|
|
// 只取最近的三个,取全文rss
|
|
const list = $('li', 'ul').slice(0, 3).toArray();
|
|
|
|
const result_item = await Promise.all(
|
|
list.map((item) =>
|
|
cache.tryGet(`https://www.dapenti.com/blog/${$(item).find('a').attr('href')}`, async () => {
|
|
const el = $(item);
|
|
const url = `https://www.dapenti.com/blog/${el.find('a').attr('href')}`;
|
|
const original_data = await got({
|
|
method: 'get',
|
|
url,
|
|
headers: {
|
|
Referer: url,
|
|
},
|
|
responseType: 'buffer',
|
|
});
|
|
const convert_data = iconv.decode(original_data.data, 'gbk');
|
|
const description = load(convert_data, {
|
|
decodeEntities: false,
|
|
})('body > table > tbody > tr > td.oblog_t_2 > div > table > tbody > tr:nth-child(2) > td');
|
|
const pubInfo = description.find('span span.oblog_text').text().split('发布于');
|
|
description.find('table, .adsbygoogle').remove();
|
|
|
|
// remove header
|
|
const count = subjectid.toString() === '70' ? 7 : 3;
|
|
for (let index = 0; index < count; index++) {
|
|
description.children().first().remove();
|
|
}
|
|
|
|
// remove footer
|
|
for (let index = 0; index < 8; index++) {
|
|
description.children().last().remove();
|
|
}
|
|
const single = {
|
|
title: el.text(),
|
|
author: pubInfo[0].trim(),
|
|
description: description.html(),
|
|
pubDate: timezone(parseDate(pubInfo[1]?.trim()), 8),
|
|
link: url,
|
|
};
|
|
return single;
|
|
})
|
|
)
|
|
);
|
|
|
|
return {
|
|
title: `喷嚏-${subjectid}`,
|
|
link: url,
|
|
item: result_item,
|
|
};
|
|
},
|
|
};
|