* 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
77 lines
2.4 KiB
JavaScript
77 lines
2.4 KiB
JavaScript
const got = require('@/utils/got');
|
|
const cheerio = require('cheerio');
|
|
const { parseDate } = require('@/utils/parse-date');
|
|
|
|
const titles = {
|
|
'5dd92265e4b0bf88dd8c1175': '热点',
|
|
'5dd921a7e4b0bf88dd8c116f': '订阅',
|
|
'604f1cbbe4b0cf5c2234d470': '学党史',
|
|
'5dd92242e4b0bf88dd8c1174': '政经',
|
|
'61259fd6e4b0d294f7f9786d': '合作区',
|
|
'61dfe511e4b0248b60d1c568': '名记名播',
|
|
'5dd9222ce4b0bf88dd8c1173': '大湾区',
|
|
'617805e4e4b037abacfd4820': '网评',
|
|
'5dd9220de4b0bf88dd8c1172': 'TV新闻',
|
|
'5e6edd50e4b02ebde0ab061e': '音频',
|
|
'600e8ad4e4b02c3a6af6aaa8': '澳门',
|
|
'600f760fe4b0e33cf6f8e68e': '政务',
|
|
'5ff7c0fde4b0e2f210d05e20': '教育',
|
|
'5fc88615e4b0e3055e693e0a': '深圳',
|
|
'600e8a93e4b02c3a6af6aa80': '中山',
|
|
'5dd921ece4b0bf88dd8c1170': '民生',
|
|
'61148184e4b08d3215364396': '社区',
|
|
'5dd9215fe4b0bf88dd8c116b': '专题',
|
|
'5e2e5107e4b0c14b5d0e3d04': '战疫',
|
|
'5f88eaf2e4b0a27cd404e09e': '横琴',
|
|
'5f86a3f5e4b09d75f99dde7d': '香洲',
|
|
'5e8c42b4e4b0347c7e5836e0': '金湾',
|
|
'5ee70534e4b07b8a779a1ad6': '斗门',
|
|
'607d37ade4b05c59ac2f3d40': '高新',
|
|
};
|
|
|
|
module.exports = async (ctx) => {
|
|
const column = ctx.params.column ?? '5dd92265e4b0bf88dd8c1175';
|
|
|
|
const rootUrl = 'https://www.hizh.cn';
|
|
const currentUrl = `${rootUrl}/channels/zjyapp/columns/${column}/stories.json`;
|
|
|
|
const response = await got({
|
|
method: 'get',
|
|
url: currentUrl,
|
|
});
|
|
|
|
let items = response.data.stories.slice(0, ctx.query.limit ? Number.parseInt(ctx.query.limit) : 50).map((item) => ({
|
|
title: item.title,
|
|
author: item.author,
|
|
link: item.jsonUrl,
|
|
category: item.columnName,
|
|
pubDate: parseDate(item.published),
|
|
}));
|
|
|
|
items = await Promise.all(
|
|
items.map((item) =>
|
|
ctx.cache.tryGet(item.link, async () => {
|
|
const detailResponse = await got({
|
|
method: 'get',
|
|
url: item.link,
|
|
});
|
|
|
|
const content = cheerio.load(detailResponse.data.content);
|
|
|
|
content('figure').last().remove();
|
|
|
|
item.description = content.html();
|
|
item.link = `${rootUrl}/content.html?jsonUrl=${item.link}`;
|
|
|
|
return item;
|
|
})
|
|
)
|
|
);
|
|
|
|
ctx.state.data = {
|
|
title: `${titles[column]} - 珠海网`,
|
|
link: rootUrl,
|
|
item: items,
|
|
};
|
|
};
|