Skip to content

fix(content): import a page's own text, not its author box, icons or related posts - #1322

Merged
gkhngyk merged 2 commits into
ansvisor:mainfrom
cihan-gyk:fix/url-import-cleanup
Oct 22, 2026
Merged

gkhngyk merged 2 commits into
ansvisor:mainfrom
cihan-gyk:fix/url-import-cleanup

Conversation

@cihan-gyk

Copy link
Copy Markdown
Collaborator

Summary

From the user's review of a live draft: importing a page by URL (New content → Optimize content → Page URL) brought in more than the post. On prod draft cfcaee7f…, imported from www.ansvisor.com/blog/ai-search-monitoring-tool-track-chatgpt-gemini-google-aio, it brought:

  • the announcement bar;
  • the "← Explore All" breadcrumb and the category tag;
  • the author line ("8 min read · Last Updated") with its icons;
  • the author's portrait used as the cover image;
  • the "Explore with AI" icon links and the table of contents;
  • the author box and "Related Blog Posts";
  • Google's preferred-source card;
  • the CTA band and the whole site footer.

The page is Webflow: it has no <main> or <article>, so extractPageContent fell back to the whole <body> and removed only nav, header, footer and aside. Pages that do have <main> often keep author boxes and share rows inside it, too.

server/src/lib/page-content.js now:

  1. Finds where the text is. Paragraphs score their block, and half of that goes to the block above it, as reader modes do. The best block is widened until it holds most of the page's paragraph text. Paragraphs inside furniture (author bio, comments) don't count.
  2. Picks the root:
    • the page's main / article / [role=main] / #content when it holds that text;
    • otherwise the closest block holding both the H1 and the text, which leaves out the site's bars, promo cards and footer;
    • with no paragraphs to go by, it falls back to the old behavior.
  3. Takes the furniture out of the root:
    • Blocks named for it, in their class or id words. Anywhere: author, avatar, bio, byline, share, social, related, comments, newsletter, subscribe, breadcrumb, toc, ad, sponsor, cookie, popup. Outside the text only: cta, promo, menu, header, footer, meta, tag(s), sidebar, widget, pagination, announcement. So the article's own call to action stays.
    • Outside the text, small lists of links: breadcrumbs, icon rows and a few related posts. Tables of contents (mostly # links) go at any length.
    • A list going to 8 or more pages, or a long block mostly of links, is the page's own, such as a category's products. It is kept whole, pictures included.
    • Bylines ("8 min read", "Last updated", "Posted by"), outside the text.
    • Hidden elements: [hidden], display:none and Webflow's .w-condition-invisible.
  4. Images:
    • Dropped anywhere: avatars, logos, icons, badges, and images 64 px or smaller by their attributes.
    • Dropped outside the text: hero, featured and thumbnail images.
    • cover is deliberately not a sign, because Tailwind's object-cover is on any picture.

Links and images are still made absolute, the H1 still heads content whose H1 sits outside it, and the JSON-LD is unchanged.

Measured on real pages (old → new):

Page Text chars Images Links
ansvisor.com blog post (Webflow) 13,064 → 10,564 23 → 5 108 → 17
wordpress.org/news/2024/11/rollins 19,293 → 19,050 (share buttons gone) 5 → 5 888 → 882
allbirds.com/collections/mens (Shopify) 10,460 → 10,440 288 → 288 290 → 286
MDN <article> reference 3,858 → 3,824 0 → 0 53 → 51

On the blog post, every paragraph of the article, its 5 screenshots and its closing quote stay. On the Shopify page the products stay, and the category copy outside <main> now comes in too.

Related issue

None. Product feedback from the user.

Type of change

  • feat — New feature
  • fix — Bug fix
  • chore — Maintenance / dependencies
  • docs — Documentation only
  • refactor — Code change that neither fixes a bug nor adds a feature
  • test — Adding or updating tests

How to test

  1. Library → New content → Optimize content → Page URL: import a blog post from one of the brand's domains, e.g. a Webflow post like the one above.
  2. Open the editor. It starts with the H1 and the lead. There should be no breadcrumb, author line, cover portrait, icon links, table of contents, author box, related posts, promo cards or site footer, and the article's images and quotes stay.
  3. Import a category page. Its product list and pictures should still come in.

New tests in page-content.test.js cover:

  • a WordPress-style article;
  • a Webflow-style page with no <main>;
  • a category's product list;
  • hidden blocks, tiny icons, and a content block whose name looks like furniture ("menu").

Checklist

  • Branch follows the naming convention (feature/, fix/, chore/, docs/) — see CONTRIBUTING.md
  • Commits follow Conventional Commits
  • yarn lint passes (run from web/) — web not touched
  • yarn typecheck passes (run from web/) — web not touched
  • yarn format:check passes (run from web/) — web not touched
  • Changes are focused — one concern per PR

Server: npm run format, npm run lint and npm test (170 files, 2,010 tests) pass. Server only, no migration.

🤖 Generated with Claude Code

…related posts

Page URL import took the whole <body> when a page had no <main> or
<article> (Webflow), and kept author boxes and share rows found inside
<main>. It now finds the text area by its paragraphs, roots the content
at the page's main block holding it (or at the block holding it and the
H1), and takes out blocks named for furniture (author, share, related,
comments, cta…), small link lists outside the text (breadcrumbs, icon
rows, a few related posts, tables of contents), bylines, hidden
elements, and avatar, logo, icon and cover images. Long lists of links
such as a category's products stay whole.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@cihan-gyk

Copy link
Copy Markdown
Collaborator Author

@gkhngyk Item D of the Plan feedback: Page URL import now brings only the page's own text. It drops author boxes, bylines, cover portraits, icon rows, tables of contents, related posts, promo cards and site footers.

  • Server only: page-content.js plus its tests. No migration and no new dependency (still cheerio).
  • Heuristics worth a look:
    • the text area comes from paragraph scoring, as reader modes do;
    • furniture is found from class/id words, split into "anywhere" and "outside the text only";
    • link lists of 8+ targets are kept, so a category's products survive;
    • cover is ignored because of Tailwind's object-cover.
  • Measured: the old → new table in the description covers four real pages (Webflow, WordPress, Shopify, MDN). On the Shopify page, products and pictures are unchanged.
  • Existing drafts: already-imported drafts aren't touched. The prod example cfcaee7f… would need a re-import.

Checks: server format, lint and 170 files / 2,010 tests pass.

@gkhngyk gkhngyk left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few fixes before merge:

  1. server/src/lib/page-content.js:31: [hidden] and inline display:none are now removed everywhere, including inside the text. Collapsed accordion panels often ship with hidden (or hidden="until-found"), and FAQ answers are exactly the text an AEO page needs. Move these three selectors out of FRAME into a separate list. Apply that list after findTextArea, only to elements outside the text area, and keep hidden="until-found". Add an FAQ accordion case to page-content.test.js.
  2. server/src/lib/page-content.js:349-351: when the root is the text area itself, parentsUntil(root) stops below it. This happens when an <article> or <main> holds the paragraphs directly, or when there is no <main> and the H1 sits inside the text. Then above.includes(textArea) is false, so images inside the text are judged by the page list (hero, featured, thumb, thumbnail), and an in-text image with size-thumbnail is dropped. Use textArea && (root[0] === textArea || above.includes(textArea)), as strip does at :339, and add a test.

The fetch path is unchanged. The brand-domain check still runs before and after redirects, and safe-fetch still refuses private addresses. The imported HTML still goes through cleanHtml on import and sanitizeDraftHtml on server-side draft writes.

…ge in-text images when the text is the root

- [hidden] and inline display:none move out of FRAME: they're taken out
  after the text area is found, outside it only, and never
  hidden="until-found". The text area is found from visible paragraphs, so
  a hidden note beside the text doesn't widen it.
- An image in the text area is judged by the in-text words when the root is
  the text area itself (an <article> holding the paragraphs directly), as
  strip does, so a size-thumbnail image in the text stays.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@cihan-gyk

Copy link
Copy Markdown
Collaborator Author

@gkhngyk Thanks, both are in 8dd89303:

  1. Hidden content. [hidden] and the two display:none selectors moved out of FRAME into HIDDEN ([hidden]:not([hidden="until-found"]), …). They're removed after findTextArea, and only outside the text area: not inside it, and not an ancestor of it. One more change was needed. With them no longer removed first, a hidden paragraph beside the text counted toward the text area and widened it, so the existing "drops what the page hides" test kept a hidden note. findTextArea now scores visible paragraphs only (closest(HIDDEN)), so the area is where the visible text is, and a hidden answer inside it stays. New test: an FAQ accordion with hidden, hidden="until-found" and display: none answers kept, and a hidden menu outside dropped.
  2. Root is the text area. The image check uses textArea && (root[0] === textArea || above.includes(textArea)), as strip does. New test: an <article> holding the paragraphs directly keeps its in-text size-thumbnail image and still drops an avatar.

Server: 2,012 tests, lint and Prettier pass. As a real-page check, www.ansvisor.com/pricing extracts identically before and after (its 10 FAQ answers aren't hidden-marked, and all stay).

@gkhngyk gkhngyk left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Both earlier findings are fixed in 8dd89303:

  • Hidden blocks are no longer part of FRAME. HIDDEN is applied after findTextArea, only outside the text area, and it keeps hidden="until-found". Paragraphs inside hidden blocks no longer count toward finding the text area. The FAQ accordion test covers hidden, until-found and inline display: none.
  • When the root is the text area itself, in-text images are judged by the in-text words (root[0] === textArea || above.includes(textArea)), and there's a test for it.

Follow-up (low, can be a separate PR):

  1. server/src/lib/page-content.js:276-282: an FAQ section that sits next to the text block, not inside it, still loses its hidden answers. A common layout is <main> with the post body, then an FAQ section whose questions are headings and whose answers are hidden. The text area is the post body because it holds all the visible paragraphs. So the FAQ's answers are outside it and get removed, but the root (<main>) keeps the questions. The import then has questions with no answers. Keep a hidden block when it is inside the root and follows a heading (h2–h6), which is the accordion's shape. Add a test with the FAQ after the text block.

Merges cleanly on current main. It contains no other open PR and adds no migration.

Tested on top of the current main: server tests (2,017), lint and Prettier pass. The URL import runs on the server, so it takes effect with the next AWS deploy.

@gkhngyk
gkhngyk merged commit f10d200 into ansvisor:main Oct 22, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants