Files
RSSHub/lib/routes/deeplearning/the-batch.ts
T
dependabot[bot]andTony 873618e99d chore(deps-dev): bump eslint-plugin-unicorn from 65.0.1 to 66.0.0 (#22274)
* 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>
2026-06-16 14:43:42 +08:00

295 lines
13 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { load } from 'cheerio';
import type { Route } from '@/types';
import cache from '@/utils/cache';
import ofetch from '@/utils/ofetch';
import { parseDate } from '@/utils/parse-date';
import { renderDescription } from './templates/description';
export const handler = async (ctx) => {
const { tag } = ctx.req.param();
const limit = ctx.req.query('limit') ? Number(ctx.req.query('limit')) : 1;
const rootUrl = 'https://www.deeplearning.ai';
const currentUrl = new URL(`the-batch${tag ? `/tag/${tag.replace(/^tag\//, '').replace(/\/$/, '')}` : ''}/`, rootUrl).href;
const response = await ofetch(currentUrl);
const $ = load(response);
const language = $('html').prop('lang');
const data = JSON.parse($('script#__NEXT_DATA__').text());
const nextBuildId = data.buildId;
const posts = data.props?.pageProps?.posts ?? [];
let items = posts.slice(0, limit).map((item) => {
const title = item.title;
const description = renderDescription({
images: item.feature_image
? [
{
src: item.feature_image,
alt: item.feature_image_alt,
},
]
: undefined,
intro: item.excerpt ?? item.custom_excerpt,
});
const image = item.feature_image;
const guid = `the-batch-${item.slug}`;
return {
title,
description,
pubDate: parseDate(item.published_at),
link: new URL(`_next/data/${nextBuildId}/the-batch/${item.slug}.json`, rootUrl).href,
category: item.tags.map((t) => t.name),
guid,
id: guid,
content: {
html: description,
text: item.excerpt ?? item.custom_excerpt,
},
image,
banner: image,
language,
};
});
items = await Promise.all(
items.map((item) =>
cache.tryGet(item.link, async () => {
const detailResponse = await ofetch(item.link);
const post = detailResponse.pageProps?.post ?? undefined;
if (!post) {
return item;
}
const $$ = load(post.html);
$$('a').each((_, ele) => {
if (!ele.attribs.href?.includes('utm_campaign')) {
return;
}
const url = new URL(ele.attribs.href);
url.searchParams.delete('utm_campaign');
url.searchParams.delete('utm_source');
url.searchParams.delete('utm_medium');
url.searchParams.delete('_hsenc');
ele.attribs.href = url.href;
});
const title = post.title;
const description = renderDescription({
images: post.feature_image
? [
{
src: post.feature_image,
alt: post.feature_image_alt,
},
]
: undefined,
intro: post.excerpt ?? post.custom_excerpt,
description: $$.html(),
});
const guid = `the-batch-${post.slug}`;
const image = post.feature_image;
item.title = title;
item.description = description;
item.pubDate = parseDate(post.published_at);
item.link = new URL(`the-batch/${post.slug}`, rootUrl).href;
item.category = post.tags.map((t) => t.name);
item.author = post.authors.map((a) => a.name).join('/');
item.guid = guid;
item.id = guid;
item.content = {
html: description,
text: post.excerpt ?? post.custom_excerpt,
};
item.image = image;
item.banner = image;
item.updated = parseDate(post.updated_at);
item.language = language;
return item;
})
)
);
const image = new URL($('meta[property="og:image"]').prop('content'), rootUrl).href;
return {
title: $('title').text(),
description: $('meta[property="og:description"]').prop('content'),
link: currentUrl,
item: items,
allowEmpty: true,
image,
author: $('meta[property="og:site_name"]').prop('content'),
language,
};
};
export const route: Route = {
path: '/the-batch/:tag{.+}?',
name: 'The Batch',
url: 'www.deeplearning.ai',
maintainers: ['nczitzk', 'juvenn', 'TonyRL'],
handler,
example: '/deeplearning/the-batch',
parameters: { tag: 'Tag, Weekly Issues by default' },
description: `::: tip
If you subscribe to [Data Points](https://www.deeplearning.ai/the-batch/tag/data-points/),where the URL is \`https://www.deeplearning.ai/the-batch/tag/data-points/\`, extract the part \`https://www.deeplearning.ai/the-batch/tag\` to the end, which is \`data-points\`, and use it as the parameter to fill in. Therefore, the route will be [\`/deeplearning/the-batch/data-points\`](https://rsshub.app/deeplearning/the-batch/data-points).
:::
| Tag | ID |
| ---------------------------------------------------------------------- | -------------------------------------------------------------------- |
| [Weekly Issues](https://www.deeplearning.ai/the-batch/) | [*null*](https://rsshub.app/deeplearning/the-batch) |
| [Andrew's Letters](https://www.deeplearning.ai/the-batch/tag/letters/) | [letters](https://rsshub.app/deeplearning/the-batch/letters) |
| [Data Points](https://www.deeplearning.ai/the-batch/tag/data-points/) | [data-points](https://rsshub.app/deeplearning/the-batch/data-points) |
| [ML Research](https://www.deeplearning.ai/the-batch/tag/research/) | [research](https://rsshub.app/deeplearning/the-batch/research) |
| [Business](https://www.deeplearning.ai/the-batch/tag/business/) | [business](https://rsshub.app/deeplearning/the-batch/business) |
| [Science](https://www.deeplearning.ai/the-batch/tag/science/) | [science](https://rsshub.app/deeplearning/the-batch/science) |
| [AI & Society](https://www.deeplearning.ai/the-batch/tag/ai-society/) | [ai-society](https://rsshub.app/deeplearning/the-batch/ai-society) |
| [Culture](https://www.deeplearning.ai/the-batch/tag/culture/) | [culture](https://rsshub.app/deeplearning/the-batch/culture) |
| [Hardware](https://www.deeplearning.ai/the-batch/tag/hardware/) | [hardware](https://rsshub.app/deeplearning/the-batch/hardware) |
| [AI Careers](https://www.deeplearning.ai/the-batch/tag/ai-careers/) | [ai-careers](https://rsshub.app/deeplearning/the-batch/ai-careers) |
#### [Letters from Andrew Ng](https://www.deeplearning.ai/the-batch/tag/letters/)
| Tag | ID |
| --------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------- |
| [All](https://www.deeplearning.ai/the-batch/tag/letters/) | [letters](https://rsshub.app/deeplearning/the-batch/letters) |
| [Personal Insights](https://www.deeplearning.ai/the-batch/tag/personal-insights/) | [personal-insights](https://rsshub.app/deeplearning/the-batch/personal-insights) |
| [Technical Insights](https://www.deeplearning.ai/the-batch/tag/technical-insights/) | [technical-insights](https://rsshub.app/deeplearning/the-batch/technical-insights) |
| [Business Insights](https://www.deeplearning.ai/the-batch/tag/business-insights/) | [business-insights](https://rsshub.app/deeplearning/the-batch/business-insights) |
| [Tech & Society](https://www.deeplearning.ai/the-batch/tag/tech-society/) | [tech-society](https://rsshub.app/deeplearning/the-batch/tech-society) |
| [DeepLearning.AI News](https://www.deeplearning.ai/the-batch/tag/deeplearning-ai-news/) | [deeplearning-ai-news](https://rsshub.app/deeplearning/the-batch/deeplearning-ai-news) |
| [AI Careers](https://www.deeplearning.ai/the-batch/tag/ai-careers/) | [ai-careers](https://rsshub.app/deeplearning/the-batch/ai-careers) |
| [Just For Fun](https://www.deeplearning.ai/the-batch/tag/just-for-fun/) | [just-for-fun](https://rsshub.app/deeplearning/the-batch/just-for-fun) |
| [Learning & Education](https://www.deeplearning.ai/the-batch/tag/learning-education/) | [learning-education](https://rsshub.app/deeplearning/the-batch/learning-education) |`,
categories: ['programming'],
features: {
requireConfig: false,
requirePuppeteer: false,
antiCrawler: false,
supportRadar: true,
supportBT: false,
supportPodcast: false,
supportScihub: false,
},
radar: [
{
source: ['www.deeplearning.ai/the-batch', 'www.deeplearning.ai/the-batch/tag/:tag/'],
target: (params) => {
const tag = params.tag;
return `/the-batch${tag ? `/${tag}` : ''}`;
},
},
{
title: 'Weekly Issues',
source: ['www.deeplearning.ai/the-batch/'],
target: '/the-batch',
},
{
title: "Andrew's Letters",
source: ['www.deeplearning.ai/the-batch/tag/letters/'],
target: '/the-batch/letters',
},
{
title: 'Data Points',
source: ['www.deeplearning.ai/the-batch/tag/data-points/'],
target: '/the-batch/data-points',
},
{
title: 'ML Research',
source: ['www.deeplearning.ai/the-batch/tag/research/'],
target: '/the-batch/research',
},
{
title: 'Business',
source: ['www.deeplearning.ai/the-batch/tag/business/'],
target: '/the-batch/business',
},
{
title: 'Science',
source: ['www.deeplearning.ai/the-batch/tag/science/'],
target: '/the-batch/science',
},
{
title: 'AI & Society',
source: ['www.deeplearning.ai/the-batch/tag/ai-society/'],
target: '/the-batch/ai-society',
},
{
title: 'Culture',
source: ['www.deeplearning.ai/the-batch/tag/culture/'],
target: '/the-batch/culture',
},
{
title: 'Hardware',
source: ['www.deeplearning.ai/the-batch/tag/hardware/'],
target: '/the-batch/hardware',
},
{
title: 'AI Careers',
source: ['www.deeplearning.ai/the-batch/tag/ai-careers/'],
target: '/the-batch/ai-careers',
},
{
title: 'Letters from Andrew Ng - All',
source: ['www.deeplearning.ai/the-batch/tag/letters/'],
target: '/the-batch/letters',
},
{
title: 'Letters from Andrew Ng - Personal Insights',
source: ['www.deeplearning.ai/the-batch/tag/personal-insights/'],
target: '/the-batch/personal-insights',
},
{
title: 'Letters from Andrew Ng - Technical Insights',
source: ['www.deeplearning.ai/the-batch/tag/technical-insights/'],
target: '/the-batch/technical-insights',
},
{
title: 'Letters from Andrew Ng - Business Insights',
source: ['www.deeplearning.ai/the-batch/tag/business-insights/'],
target: '/the-batch/business-insights',
},
{
title: 'Letters from Andrew Ng - Tech & Society',
source: ['www.deeplearning.ai/the-batch/tag/tech-society/'],
target: '/the-batch/tech-society',
},
{
title: 'Letters from Andrew Ng - DeepLearning.AI News',
source: ['www.deeplearning.ai/the-batch/tag/deeplearning-ai-news/'],
target: '/the-batch/deeplearning-ai-news',
},
{
title: 'Letters from Andrew Ng - AI Careers',
source: ['www.deeplearning.ai/the-batch/tag/ai-careers/'],
target: '/the-batch/ai-careers',
},
{
title: 'Letters from Andrew Ng - Just For Fun',
source: ['www.deeplearning.ai/the-batch/tag/just-for-fun/'],
target: '/the-batch/just-for-fun',
},
{
title: 'Letters from Andrew Ng - Learning & Education',
source: ['www.deeplearning.ai/the-batch/tag/learning-education/'],
target: '/the-batch/learning-education',
},
],
};