Files
RSSHub/lib/routes/leetcode/articles.ts
T
dependabot[bot]andTony 07834413f5 chore(deps-dev): bump eslint-plugin-unicorn from 64.0.0 to 65.0.0 (#22219)
* chore(deps-dev): bump eslint-plugin-unicorn from 64.0.0 to 65.0.0

Bumps [eslint-plugin-unicorn](https://github.com/sindresorhus/eslint-plugin-unicorn) from 64.0.0 to 65.0.0.
- [Release notes](https://github.com/sindresorhus/eslint-plugin-unicorn/releases)
- [Commits](https://github.com/sindresorhus/eslint-plugin-unicorn/compare/v64.0.0...v65.0.0)

---
updated-dependencies:
- dependency-name: eslint-plugin-unicorn
  dependency-version: 65.0.0
  dependency-type: direct:development
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>

* fix: no-array-from-fill

* fix: unicorn-js/no-duplicate-set-values

* fix: no-this-outside-of-class

* fix: no-unnecessary-nested-ternary

* fix: prefer-array-last-methods

* fix: prefer-queue-microtask

* fix: prefer-split-limit

* fix: no-array-from-fill

* fix: no-unused-array-method-return

* fix: prefer-single-call

* fix: prefer-includes-over-repeated-comparisons

* fix: consistent-compound-words

* fix: prefer-includes-over-repeated-comparisons

* chore: add eslint-plugin-unicorn v65 recommended preset

* fix: correct duration parsing logic in parseDuration function

* fix: update oxlint-disable

---------

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>
2026-06-09 00:08:15 +08:00

116 lines
3.7 KiB
TypeScript

import { load } from 'cheerio';
import MarkdownIt from 'markdown-it';
import type { Route } from '@/types';
import cache from '@/utils/cache';
import ofetch from '@/utils/ofetch';
import { parseDate } from '@/utils/parse-date';
const md = MarkdownIt({
html: true,
breaks: true,
});
const host = 'https://leetcode.com';
const gqlEndpoint = `${host}/graphql`;
export const route: Route = {
path: '/articles',
categories: ['programming'],
example: '/leetcode/articles',
parameters: {},
features: {
requireConfig: false,
requirePuppeteer: false,
antiCrawler: false,
supportBT: false,
supportPodcast: false,
supportScihub: false,
},
radar: [
{
source: ['leetcode.com/articles'],
},
],
name: 'Articles',
maintainers: ['LogicJake'],
handler,
url: 'leetcode.com/articles',
};
async function handler() {
const link = new URL('/articles/', host).href;
const response = await ofetch(link, { parseResponse: (txt) => txt });
const $ = load(response);
const list = $('a.list-group-item')
.toArray()
.filter((e) => $(e).find('h4.media-heading i').length === 0)
.map((item) => {
const info = {
title: $(item).find('h4.media-heading').text().trim(),
author: $(item).find('.text-500').text(),
link: new URL($(item).attr('href'), host).href,
pubDate: $(item).find('p.pull-right.media-date strong').text().trim(),
};
return info;
});
const out = await Promise.all(
list.map((info) =>
cache.tryGet(info.link, async () => {
const titleSlug = info.link.split('/', 5)[4];
const questionContent = await ofetch(gqlEndpoint, {
method: 'POST',
body: {
operationName: 'questionContent',
variables: { titleSlug },
query: /* GraphQL */ `
query questionContent($titleSlug: String!) {
question(titleSlug: $titleSlug) {
content
mysqlSchemas
dataSchemas
}
}
`,
},
});
const officialSolution = await ofetch(gqlEndpoint, {
method: 'POST',
body: {
operationName: 'officialSolution',
variables: { titleSlug },
query: /* GraphQL */ `
query officialSolution($titleSlug: String!) {
question(titleSlug: $titleSlug) {
solution {
content
}
}
}
`,
},
});
const solution = md.render(officialSolution.data.question.solution.content);
info.description = (questionContent.data.question.content?.trim() ?? '') + solution;
info.pubDate = parseDate(info.pubDate);
return info;
})
)
);
return {
title: $('head title').text(),
description: $('meta[property="og:description"]').attr('content'),
image: 'https://assets.leetcode.com/static_assets/public/icons/favicon-192x192.png',
link,
item: out,
};
}