* chore(deps-dev): bump eslint-plugin-unicorn from 65.0.1 to 66.0.0 Bumps [eslint-plugin-unicorn](https://github.com/sindresorhus/eslint-plugin-unicorn) from 65.0.1 to 66.0.0. - [Release notes](https://github.com/sindresorhus/eslint-plugin-unicorn/releases) - [Commits](https://github.com/sindresorhus/eslint-plugin-unicorn/compare/v65.0.1...v66.0.0) --- updated-dependencies: - dependency-name: eslint-plugin-unicorn dependency-version: 66.0.0 dependency-type: direct:development update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] <support@github.com> * style: fix unicorn-js/prefer-url-href * style: oxlint disable * style: fix unicorn-js/no-useless-else * style: no-unsafe-string-replacement * style: fix no-duplicate-loops * style: fix prefer-number-is-safe-integer * style: fix prefer-single-array-predicate * style: fix no-object-methods-with-collections * style: fix no-useless-boolean-cast * style: fix no-useless-template-literals * style: fix no-negated-array-predicate * style: fix prefer-direct-iteration * style: fix consistent-optional-chaining * style: fix prefer-simple-sort-comparator * style: fix prefer-global-number-constants * style: fix prefer-type-literal-last * style: fix require-array-sort-compare. * style: fix prefer-early-return * style: fix prefer-short-arrow-method * style: fix prefer-array-from-map * style: fix prefer-scoped-selector * style: fix no-global-object-property-assignment * style: fix no-unnecessary-global-this * style: fix no-unreadable-object-destructuring * style: fix no-invalid-argument-count * style: fix prefer-smaller-scope * style: fix prefer-iterator-to-array. * style: fix prefer-object-iterable-methods * style: fix typo * style: fix max-nested-calls * style: fix no-incorrect-template-string-interpolation * style: fix no-break-in-nested-loop * style: fix prefer-await * style: fix no-computed-property-existence-check * style: fix prefer-number-coercion * style: fix no-empty-file * style: update eslint unicorn v66 recommended preset * style: add unicorn/prefer-spread to oxlint-disable comments * style: fix no-array-reduce * style: delete github/no-then as it's covered by unicorn/prefer-await --------- 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>
93 lines
3.2 KiB
TypeScript
93 lines
3.2 KiB
TypeScript
import { load } from 'cheerio';
|
|
|
|
import type { Route } from '@/types';
|
|
import cache from '@/utils/cache';
|
|
import got from '@/utils/got';
|
|
import { parseDate } from '@/utils/parse-date';
|
|
import parser from '@/utils/rss-parser';
|
|
import { fixArticleContent } from '@/utils/wechat-mp';
|
|
|
|
// any UA containing "RSS" can pass the check
|
|
// mark the UA as a desktop UA with "(X11; Linux x86_64)"
|
|
const UA = 'Mozilla/5.0 (X11; Linux x86_64) RSS Reader';
|
|
|
|
export const route: Route = {
|
|
path: '/ce/:id',
|
|
categories: ['new-media'],
|
|
example: '/wechat/ce/595a5b14d7164e53908f1606',
|
|
parameters: { id: '公众号 id,在 [CareerEngine](https://search.careerengine.us/) 搜索公众号,通过 URL 中找到对应的公众号 id' },
|
|
features: {
|
|
requireConfig: false,
|
|
requirePuppeteer: false,
|
|
antiCrawler: true,
|
|
supportBT: false,
|
|
supportPodcast: false,
|
|
supportScihub: false,
|
|
},
|
|
radar: [
|
|
{
|
|
source: ['cimidata.com/a/:id'],
|
|
},
|
|
],
|
|
name: '公众号(CareerEngine 来源)',
|
|
maintainers: ['HenryQW'],
|
|
handler,
|
|
};
|
|
|
|
async function handler(ctx) {
|
|
const id = ctx.req.param('id');
|
|
|
|
const response = await got.get(`https://posts.careerengine.us/author/${id}/rss`, {
|
|
headers: {
|
|
'User-Agent': UA,
|
|
},
|
|
});
|
|
const feed = await parser.parseString(response.data);
|
|
|
|
const items = await Promise.all(
|
|
feed.items.splice(0, 10).map((item) => {
|
|
// generally speaking, changing `item.link` of an existing route could potentially break `item.guid`
|
|
// but since the route has been down for at least 8 months, it's probably safe
|
|
item.link = item.link.replace(/^http:\/\//, 'https://');
|
|
return cache.tryGet(item.link, async () => {
|
|
const response = await got.get(item.link, {
|
|
headers: {
|
|
'User-Agent': UA,
|
|
},
|
|
});
|
|
|
|
const $ = load(response.data);
|
|
|
|
const description = fixArticleContent($('.post'));
|
|
|
|
let pubDate = item.pubDate;
|
|
if (!pubDate || pubDate === 'Invalid Date') {
|
|
// sometimes the pubDate is not available in the official feed
|
|
const postDate = $('.post-date')
|
|
.text()
|
|
.replaceAll(/\s+|发表/g, '');
|
|
// the date format is "发表 YYYY年MM月DD日 "
|
|
// following the official feed behavior: imprecise date is in UTC
|
|
// `<pubDate>Mon, 04 Apr 2022 00:00:00 GMT</pubDate>`
|
|
pubDate = parseDate(postDate, 'YYYY年MM月DD日');
|
|
pubDate = new Date(pubDate.getTime() - pubDate.getTimezoneOffset() * 60 * 1000);
|
|
}
|
|
|
|
return {
|
|
title: item.title,
|
|
description,
|
|
pubDate,
|
|
link: item.link,
|
|
};
|
|
});
|
|
})
|
|
);
|
|
|
|
return {
|
|
title: `微信公众号 - ${feed.title}`,
|
|
link: `https://posts.careerengine.us/author/${id}/posts`,
|
|
description: feed.description,
|
|
item: items,
|
|
};
|
|
}
|