mirror of
https://github.com/DIYgod/RSSHub.git
synced 2026-10-24 23:42:40 +08:00
fix(route): verge parse error (#19930)
* feat(route): secretsanfrancisco.com * style: auto format * chore: use feed link to fetch list * refactor: use wp api to fetch content * chore: rename section to category * feat: caption * chore: cr * chore: cache first category * fix(route): verge parse error * style: auto format * chore: cr * fix: ImageSliderBlockType * style: auto format * fix: unsupport type * style: auto format * fix: unsupport type * Update lib/routes/theverge/index.ts Co-authored-by: Tony <TonyRL@users.noreply.github.com> * chore: cr --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: yifan.wang1004 <yifan.wang1004@bytedance.com>
This commit is contained in:
co-authored by
Tony
github-actions[bot]
yifan.wang1004
parent
69047f4fa2
commit
22200f2fc0
@@ -6,6 +6,10 @@ import { load } from 'cheerio';
|
||||
import path from 'node:path';
|
||||
import { art } from '@/utils/render';
|
||||
|
||||
const excludeTypes = new Set(['NewsletterBlockType', 'RelatedPostsBlockType', 'ProductBlockType', 'ProductsTableBlockType', 'TableOfContentsBlockType']);
|
||||
|
||||
const shouldKeep = (b: any) => !excludeTypes.has(String(b.__typename).trim());
|
||||
|
||||
export const route: Route = {
|
||||
path: '/:hub?',
|
||||
categories: ['new-media'],
|
||||
@@ -46,6 +50,9 @@ export const route: Route = {
|
||||
};
|
||||
|
||||
const renderBlock = (b) => {
|
||||
if (!shouldKeep(b)) {
|
||||
return '';
|
||||
}
|
||||
switch (b.__typename) {
|
||||
case 'CoreEmbedBlockType':
|
||||
return b.embedHtml;
|
||||
@@ -60,7 +67,7 @@ const renderBlock = (b) => {
|
||||
case 'CoreListBlockType':
|
||||
return `${b.ordered ? '<ol>' : '<ul>'}${b.items.map((i) => `<li>${i.contents.html}</li>`).join('')}${b.ordered ? '</ol>' : '</ul>'}`;
|
||||
case 'CoreParagraphBlockType':
|
||||
return b.contents.html;
|
||||
return (b.tempContents ?? []).map((c) => c?.html ?? '').join('');
|
||||
case 'CorePullquoteBlockType':
|
||||
return `<blockquote>${b.contents.html}</blockquote>`;
|
||||
case 'CoreQuoteBlockType':
|
||||
@@ -71,13 +78,23 @@ const renderBlock = (b) => {
|
||||
return b.children.map((c) => renderBlock(c)).join('');
|
||||
case 'MethodologyAccordionBlockType':
|
||||
return `<h2>${b.heading.html}</h2>${b.sections.map((s) => `<h3>${s.heading.html}</h3>${s.content.html}`).join('')}`;
|
||||
case 'ImageSliderBlockType':
|
||||
return `
|
||||
${b.images
|
||||
.map(
|
||||
(img) => `<figure>
|
||||
<img src="${img.image.originalUrl}" alt="${img.alt}">
|
||||
<figcaption>${img.caption.html}</figcaption>
|
||||
</figure>`
|
||||
)
|
||||
.join('')}`;
|
||||
default:
|
||||
throw new Error(`Unsupported block type: ${b.__typename}`);
|
||||
}
|
||||
};
|
||||
|
||||
async function handler(ctx) {
|
||||
const link = ctx.req.param('hub') ? `https://www.theverge.com/${ctx.req.param('hub')}/rss/index.xml` : 'https://www.theverge.com/rss/index.xml';
|
||||
const link = ctx.req.param('hub') ? `https://www.theverge.com/rss/${ctx.req.param('hub')}/index.xml` : 'https://www.theverge.com/rss/index.xml';
|
||||
|
||||
const feed = await parser.parseURL(link);
|
||||
|
||||
@@ -97,7 +114,7 @@ async function handler(ctx) {
|
||||
});
|
||||
|
||||
description += node.blocks
|
||||
.filter((b) => b.__typename !== 'NewsletterBlockType' && b.__typename !== 'RelatedPostsBlockType' && b.__typename !== 'ProductBlockType' && b.__typename !== 'TableOfContentsBlockType')
|
||||
.filter((b) => shouldKeep(b))
|
||||
.map((b) => renderBlock(b))
|
||||
.join('<br><br>');
|
||||
|
||||
|
||||
Reference in New Issue
Block a user