diff --git a/lib/routes/theverge/index.ts b/lib/routes/theverge/index.ts index 4c46ade04..abaeb21ef 100644 --- a/lib/routes/theverge/index.ts +++ b/lib/routes/theverge/index.ts @@ -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 ? '
    ' : '
' : ''}`; case 'CoreParagraphBlockType': - return b.contents.html; + return (b.tempContents ?? []).map((c) => c?.html ?? '').join(''); case 'CorePullquoteBlockType': return `
${b.contents.html}
`; case 'CoreQuoteBlockType': @@ -71,13 +78,23 @@ const renderBlock = (b) => { return b.children.map((c) => renderBlock(c)).join(''); case 'MethodologyAccordionBlockType': return `

${b.heading.html}

${b.sections.map((s) => `

${s.heading.html}

${s.content.html}`).join('')}`; + case 'ImageSliderBlockType': + return ` + ${b.images + .map( + (img) => `
+ ${img.alt} +
${img.caption.html}
+
` + ) + .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('

');