Open-source agentic AI Search Execution Platform. Track AI visibility, find opportunities, and let agents turn signals into prioritized actions and drafted fixes across ChatGPT, Claude, Gemini, Google AI Overviews, Google AI Mode, Perplexity, Grok, and Microsoft Copilot.
TypeScript aeoai-agentai-searchanswer-engine-optimizationbrand-monitoringchatgptclaudecopilotdockergeminigeogoogle-ai-overviewsgrokmcpnextjsopen-sourceperplexityseosupabasetypescript
fix(content): keep a collapsed FAQ's answers when URL import finds it next to the post body (#1405)
Gökhan Geyikb709c38148e4
diff --git a/server/src/lib/page-content.js b/server/src/lib/page-content.jsindex c32f04a38..21dd9a0b2 100644--- a/server/src/lib/page-content.js+++ b/server/src/lib/page-content.js@@ -38,6 +38,12 @@ const FRAME =const HIDDEN ='[hidden]:not([hidden="until-found"]), [style*="display:none"], [style*="display: none"]';+/**+ * A question an accordion's hidden answer follows: an FAQ beside the text+ * (after the post, in the page's main block) keeps its answers too.+ */+const QUESTION = 'h2, h3, h4, h5, h6';+/*** Words in a block's class or id that name furniture: anywhere, even in the* text (an author box or share buttons in the article)…@@ -280,13 +286,19 @@ export function extractPageContent(html, pageUrl) {// The root: the page's main block when it holds the text; else the part// of the page holding the text and its H1; else the text area alone.const textArea = findTextArea($, body);+ // What the page hides goes, outside the text. An answer right after its+ // question waits for the root: in it, it's an FAQ's (QUESTION).+ const answers = [];body.find(HIDDEN).filter((_, el) =>!textArea || ($(el).closest(textArea).length === 0 && !$(el).find(textArea).length),)- .remove();+ .each((_, el) => {+ if ($(el).prev().is(QUESTION)) answers.push(el);+ else $(el).remove();+ });// The title's H1, picked once: the last one with words before the text's// first paragraph (not a logo's or a site name's above it), else the first.// A byline, date or breadcrumb line above the title is no paragraph of it.@@ -318,6 +330,9 @@ export function extractPageContent(html, pageUrl) {: textArea? $(heading ? commonAncestor($, heading, textArea) : textArea): body;+ for (const el of answers) {+ if ($(el).closest(root[0]).length === 0) $(el).remove();+ }// What stays whatever its name: the text area, the blocks around it and// the H1's.diff --git a/server/src/lib/page-content.test.js b/server/src/lib/page-content.test.jsindex 01edf9b1f..63b4a3128 100644--- a/server/src/lib/page-content.test.js+++ b/server/src/lib/page-content.test.js@@ -284,6 +284,39 @@ describe('extractPageContent', () => {expect(html).not.toContain('Shop all our coffee');});+ it('keeps a collapsed FAQ’s answers after the post body, and drops other hidden blocks beside it', () => {+ const { html } = extractPageContent(+ `<body><div hidden class="cookie-banner"><h2>Cookies</h2><p>We use cookies to improve your visit to our coffee shop.</p></div>+ <main><h1>How to brew pour-over coffee</h1>+ <div class="post-body">+ <p>Pour-over coffee tastes cleaner than a French press, with brighter notes.</p>+ <p>Start with a medium-fine grind and water just off the boil, around 94 °C.</p>+ <p>Pour in slow circles, and aim for a total brew time of about three minutes.</p>+ </div>+ <section class="faq">+ <h2>Frequently asked questions</h2>+ <h3>Do I need a gooseneck kettle?</h3>+ <div hidden><p>It helps you pour slowly, but any kettle works with a little practice.</p></div>+ <h3>Which filter should I use?</h3>+ <div style="display:none"><p>Paper filters give the cleanest cup; metal ones let more oils through.</p></div>+ <div hidden class="newsletter"><p>Sign up for our newsletter to get brewing tips every week.</p></div>+ </section>+ </main></body>`,+ 'https://acme-coffee.example/pour-over',+ );+ for (const kept of [+ 'Do I need a gooseneck kettle?',+ 'any kettle works',+ 'Which filter should I use?',+ 'Paper filters give the cleanest cup',+ ]) {+ expect(html).toContain(kept);+ }+ for (const gone of ['We use cookies', 'Sign up for our newsletter']) {+ expect(html).not.toContain(gone);+ }+ });+it('judges images in the text as the text’s when the text area is the root', () => {const { html } = extractPageContent(`<body><article>