Skip to content

gitflarePublicPartly agent-ready50

cf-workflows-pipeline

Durable content pipeline on Cloudflare Workflows: ingest, extract, summarise with Workers AI via AI Gateway, human approval, publish.

Fix pipeline runs failing at ingest (steps.attempt NOT NULL)629b2fa
TypeScript16 lines924 B
export interface Extracted { title: string; text: string } const ENT: Record<string, string> = { "&amp;": "&", "&lt;": "<", "&gt;": ">", "&quot;": '"', "&#39;": "'", "&nbsp;": " " };const decode = (s: string) => s.replace(/&(amp|lt|gt|quot|#39|nbsp);/g, (m) => ENT[m] ?? m); export function extract(html: string): Extracted {  const t = /<title[^>]*>([\s\S]*?)<\/title>/i.exec(html);  let body = html.replace(/<!--[\s\S]*?-->/g, " ");  body = body.replace(/<(script|style|nav|noscript|header|footer|aside)\b[\s\S]*?<\/\1\s*>/gi, " ");  const pick = /<article\b[^>]*>([\s\S]*?)<\/article>/i.exec(body) ?? /<main\b[^>]*>([\s\S]*?)<\/main>/i.exec(body);  const region = pick ? pick[1] : body.replace(/<title[^>]*>[\s\S]*?<\/title>/i, " ");  const text = decode(region.replace(/<[^>]+>/g, " ")).replace(/\s+/g, " ").trim();  const title = t ? decode(t[1]).replace(/\s+/g, " ").trim() : "";  return { title, text };}