Skip to content

feat(content): detect a draft's page type and set the brand's site type - #1262

Merged
gkhngyk merged 38 commits into
ansvisor:mainfrom
cihan-gyk:feature/content-page-types
Oct 21, 2026
Merged

gkhngyk merged 38 commits into
ansvisor:mainfrom
cihan-gyk:feature/content-page-types

Conversation

@cihan-gyk

@cihan-gyk cihan-gyk commented Oct 20, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Content Editor, PR 5 of the plan: page type detection per page, with a user override, and the brand's site type (CE-023, spec §4).

Stacked on #1261 → #1260 → #1259 → #1258 → #1256. Please merge them in order. This PR's own change is 966c4f9.

Site type (brand settings › General)

  • A new Site type select: B2B SaaS, E-commerce or B2C. It sets the page types the editor offers, as the v2 mockup's site switch does:
    • B2B: Feature, Solution, Comparison, Integration, Pricing, Guide, Blog post, Docs / FAQ;
    • E-commerce: Product, Category, Buying guide, Best-of, Policy, Blog post;
    • B2C: Destination, Itinerary, Guide, Best-of, Help & FAQ, Blog post.
  • Until someone picks one, it's guessed, with a note saying so. Only a picked value is saved, so the guess keeps following the industry.
    • Shopping mode on, or E-commerce & Retail, Fashion, Consumer Goods, Food & Beverage, Automotive → E-commerce.
    • Travel & Hospitality → B2C. B2C's types are a travel site's (destinations, itineraries), so no other industry guesses it.
    • Everything else → B2B.
  • Stored in brands.site_type (null = guessed) and saved through updateBrand, under the existing brands policies (admins and managers), like the industry.

Page type detection (lib/content/page-types.ts, detectPageType)

  • Order of signs:
    1. the URL path (/pricing, /vs/, -alternatives, /integrations/, /products/…, /collections/, /destinations/, /blog/…, most specific first);
    2. the JSON-LD schema (Product, FAQPage, BlogPosting, TouristDestination…, including @graph and mainEntity);
    3. the title ("X vs Y", "How to…", "The 7 best…", "3-day…").
  • Site-aware: only types the site writes come back. A /vs/ page is a Comparison on a B2B site and a Best-of on a shop.
  • URLs: drafts don't have a URL yet, so today the editor reads the schema and the title. The URL signs are there for the Start screen (PR 6), which opens a draft from an existing page.

User override

  • The page type tag in the editor header is now a menu of the site's types, with a link to the site type setting.
  • While detected, the type follows the page as it is written:
    • The editor re-detects on each change.
    • saveContentDraft re-detects from the saved HTML and writes it only where page_type_source = 'detected', so a pick made meanwhile wins.
  • Once picked, it's kept (setContentDraftPageType, page_type_source = 'user'). A failed pick puts the old type back with a toast.
  • The length target follows the type shown.

Migration 00205_content_page_types.sql

Also: html-allowlist.ts exports its existing JSON_LD_SCRIPT pattern for the detector. No new dependencies.

Related issue

Content Editor CE-023. Stacked on #1261 → #1260 → #1259 → #1258 → #1256.

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

Apply 00205 first.

  1. Open a brand's Settings › General: Site type shows the guess (Food & Beverage → E-commerce) with "Guessed from the industry and Shopping mode until you pick one."
  2. Create a draft from the Library and paste (or set in </> HTML) <h1>Ethiopia Yirgacheffe</h1><script type="application/ld+json">{"@type":"Product"}</script>.
    • The header tag reads Product page.
    • The target is 1,200 characters.
  3. Open the tag's menu: the six e-commerce types, "Detected from the page as you write…". Pick Category page.
    • The target drops to 800.
    • Typing doesn't change the type.
  4. In another new draft, write the H1 "How to choose a coffee grinder" (Buying guide), then change it to "The 5 best coffee grinders" (Best-of list).
    • After the autosave, the Library lists the type.
  5. Set the brand's site type to B2B SaaS and save: the second draft reads Comparison, and the menu lists the B2B types.

Tests:

  • page-types.test.ts: per-site type lists; site type guess; URL, schema and title signs per site; precedence; nothing found.
  • content-drafts.test.ts:
    • the brand's site type on open;
    • re-detection only while detected, written with the page_type_source guard;
    • the picked type and its validation.
  • brand.test.ts: the site type is saved, and unknown values are refused.
  • settings/page.test.tsx: the guess and its note; a guess isn't saved; a chosen type shows without the note.
  • editor/page.test.tsx: follows the page while detected; keeps a pick; the shop list keeps a type from another site; a failed pick reverts; "Set page type".

Checked in light and dark, and at 1024 px.

Checklist

  • Branch follows the naming convention (feature/, fix/, chore/, docs/) — see CONTRIBUTING.md
  • Commits follow Conventional Commits
  • yarn lint passes (run from web/) (0 errors; the 6 warnings are in untouched files, as on main)
  • yarn typecheck passes (run from web/)
  • yarn format:check passes (run from web/)
  • Changes are focused — one concern per PR

yarn test (2,041 tests) and yarn build pass. bash supabase/build-schema.sh was run.

🤖 Generated with Claude Code

cihan-gyk and others added 11 commits October 20, 2026 17:09
Content Editor CE-001 and CE-002. Content becomes a group in the sidebar,
like Prompts: Opportunities keeps /dashboard/content, and the new Library
(/dashboard/content/library) lists every page a person or the Content Agent
writes or changes in Ansvisor, by status (Drafts, In review, Ready,
Published), with its page type, method, author and AEO score.

- Migration 00203: content_drafts with member RLS (select, insert, update;
  no delete yet). A guard trigger keeps author, created_by, brand and the
  scores server-side, so a member can't pass a draft off as the agent's.
- Sidebar: each submenu remembers its own open state (Prompts keeps its
  key), and only the longest matching entry is current, so Opportunities
  isn't marked on the Library.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Content Editor CE-004, stacked on the Library (ansvisor#1256). A draft opens at
/dashboard/content/editor/{id}: a header with its title, page type,
method and status, whether it's saved, and Mark ready; the toolbar (H1 H2
H3, bold, italic, link, lists, quote, table with add row / add column /
delete, image by address) with the length counter against the page
type's target; and the page as rich text (TipTap 3.31.4, pinned).

- Autosave after a pause in typing; saves never overlap, a failed one
  keeps the text and offers Retry, and leaving with unsaved text asks.
  The draft's title is its first H1.
- saveContentDraft validates the body (500k chars) and title and says
  when RLS matched no row; markContentDraftReady moves draft or in review
  to ready only.
- Links: http(s), mailto or a path on the brand's site; javascript:,
  //host and /\host are refused, in the dialog and when content loads.
- The Library gets New content (a blank draft, until the Start screen),
  and its entry stays current while a draft is open in the editor.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Content Editor CE-005 and CE-020, stacked on the editor core (ansvisor#1258).

- Paste: from Word, Google Docs, Notion or a web page, headings (H4-H6
  as H3), paragraphs, bold, italic, lists, links, tables and quotes stay;
  fonts, colors, classes, inline styles, scripts, iframes and utm_*,
  gclid, fbclid on links go. Google Docs' styled bold and italic become
  strong and em first. Pasted images wait for attachments. Cmd/Ctrl +
  Shift + V pastes plain text.
- </> HTML shows the page's HTML as a draft stores it, one block per
  line; Back to visual cleans it with the same allow-list and says how
  many unsafe tags it removed. Schema JSON-LD is kept: a block in the
  editor, written again from its JSON so it can't carry markup.
- The server checks every save against the allow-list again
  (sanitize-html), so a request made without the editor can't store a
  script, a handler or a javascript: link.
- dompurify 3.4.16 and sanitize-html 2.18.0, pinned.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
sanitize-html 2.18.0 needs Node 22.12 or later, and CI and the web
Docker image run Node 20, so yarn install refused it. 2.17.0 has no
engine limit and the same API; @types/sanitize-html 2.16.0 matches it
(both on htmlparser2 8).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Links in a draft looked like the text around them (dark, barely
underlined), so a link just added seemed not to be there. They're blue
and underlined now. With the cursor in a link, the toolbar shows its
address, which opens it in a new tab; Cmd/Ctrl + click on it in the page
does too. A click alone still puts the cursor in it to edit. A path on
the brand's own site is shown, not opened: it has no address here.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…-html

# Conflicts:
#	web/messages/en.json
#	web/src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/_draft-editor.tsx
#	web/src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/_toolbar.tsx
#	web/src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/page.test.tsx
On the user's request, as Webflow's custom code in rich text: as many
HTML blocks as a page needs, each carrying code as written (an embed, a
widget, a form), and one-click Copy HTML for a block or the whole page.

- An HTML block is added from the toolbar where the cursor is, and edited
  or removed from its own Edit. The editor shows its code as text; it
  never runs in Ansvisor. A draft stores it as UTF-8 base64 in an empty
  element, so no markup in it can act, and the server checks each one
  decodes and fits 50,000 characters.
- Copy HTML (header) puts the page on the clipboard as HTML to publish:
  each block as its own code, schema JSON-LD as its script. A block's
  own Copy HTML copies just its code. A refused Clipboard API falls back
  to the browser's copy command.
- The HTML view shows each block between <!-- html-block --> markers,
  kept as written; code typed between new markers becomes a block. A
  paste from elsewhere can't bring blocks in.
- The link, image and block dialogs focus their field when they open.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…locks

# Conflicts:
#	web/src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/_toolbar.tsx
#	web/src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/page.test.tsx
Inserting an HTML block scrolls the cursor into view, and ProseMirror
measures a Range to do it. jsdom's ranges have no getClientRects, so on
CI's Node 20 the measuring threw on a timer after the test and failed the
run as an unhandled error. The editor test gives ranges an empty
measurement, as jsdom has no layout anyway.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…es to a draft

A paperclip tool and drag-and-drop on the editor (CE-006). Excel and CSV
open a preview (sheet picker, first 10 rows, header row) and insert as a
table, asking first above 200 rows. Word (.docx, via mammoth), Markdown,
HTML and plain text import as content through the same cleaning as a
paste. Images, old .xls/.doc and files over 10 MB get a clear message.
Imports land under a table when the cursor is inside one.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Page types follow the kind of site (CE-023). Brand settings get a Site
type (B2B SaaS, E-commerce, B2C; guessed from Shopping mode and the
industry until picked), stored in brands.site_type (migration 00205). A
draft's page type is detected from its URL, JSON-LD schema and title,
and kept in step as the page changes, until the person picks one from
the editor header's page type menu (content_drafts.page_type_source).

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

Copy link
Copy Markdown
Collaborator Author

@gkhngyk Content Editor PR 5 (CE-023): a draft's page type is detected from its URL, schema and title and follows the page until someone picks one in the editor header; brands get a Site type (B2B SaaS / E-commerce / B2C, guessed until picked) that sets the types on offer. Migration 00205 (brands.site_type, content_drafts.page_type_source). Heads-up: your #1257 and our #1256 both add an 00203 migration. If #1257 goes in first, I'll renumber #1256's file to 00204 and merge it up the stack; this PR skips to 00205 so it stays in order either way. Stacked on #1261 → #1260 → #1259 → #1258 → #1256. Could you take a look?

@github-actions github-actions Bot added the needs-migration Adds or edits a migration — apply it to the hosted database label Oct 20, 2026
gkhngyk
gkhngyk previously approved these changes Oct 21, 2026

@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, with one small fix. Detection is deterministic (no model call), the site type goes through updateBrand under the existing brands policies, and 00205 is additive.

  1. The updatedAt a save returns is stale whenever the type changes (web/src/lib/actions/content-drafts.ts:154-186). When the detected type differs, a second update({ page_type }) runs, which fires the updated_at trigger again. The function still returns the first update's updated_at. Nothing compares it yet, but it breaks the conflict check suggested on #1258 (every type flip would look like a foreign write), and each autosave costs two writes while the type changes. Add .select('updated_at').maybeSingle() to the second update and return its value when it ran. Or send the editor's detected type with the save and write body and type in one statement (an RPC can apply the page_type_source = 'detected' condition inside the same update).

Approving this PR's own change. It merges once the PRs below it in the stack are ready; see the overview on #1256.

cihan-gyk and others added 2 commits October 21, 2026 15:01
…unsaved text ready

- saveContentDraft takes the version the editor last saw (updated_at and
  a SHA-256 of the page) and writes with .eq('updated_at', base). When
  another write came first, the page tells which kind: the same page means
  only other columns changed (Mark ready, the type), and the save goes over
  them; another page comes back `conflict` and nothing is overwritten. The
  header then says "Changed elsewhere · Reload" and autosave stops.
- Results are typed ({ ok: false, reason }) since Next.js hides server
  action messages in production: a page over 500,000 characters says "Too
  long to save" (and isn't sent at all), not "Couldn't save · Retry".
- Mark ready settles first: it waits for a save under way and isn't run
  when the page can't be saved.
- Nit: the title limit comes from 00204.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…-html

# Conflicts:
#	web/src/lib/actions/content-drafts.test.ts
#	web/src/lib/actions/content-drafts.ts
cihan-gyk and others added 10 commits October 21, 2026 15:03
…king regex

The JSON-LD pattern had two [^>]* runs around \btype, so input with many
unclosed `<script type=application/ld+json ` tags took cubic time (about
16 s at 33k characters), and the server runs it on every save. It is now
a scan (indexOf for the tag, its end and </script>, the type tested on the
tag alone), linear in the length; a 500,000-character page built to
backtrack takes milliseconds. The paste cleaner uses the same scan.

sanitize-draft-html.ts now says stored HTML is untrusted: a member can
write body_html through PostgREST past this check, so readers parse or
clean it again.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…locks

# Conflicts:
#	web/src/lib/content/html-allowlist.test.ts
#	web/src/lib/content/html-allowlist.ts
#	web/src/lib/content/sanitize-draft-html.test.ts
#	web/src/lib/content/sanitize-draft-html.ts
…limit

"Insert all N rows" had no upper bound: the editor writes each cell as
<td colspan="1" rowspan="1"><p>…</p></td>, so a wide sheet passed the
500,000-character body limit after a few hundred rows, and from then on
nothing typed was saved. The preview now measures the table as the editor
saves it against the room left in the page (rowsThatFit): a table that
doesn't fit offers "Insert the first N rows" after saying why, and one with
no room at all can't be inserted.

The sheet picker passes `items` to Select, as the repo's Base UI selects do.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…-types

Brings ansvisor#1258–ansvisor#1261's review fixes. The save keeps detecting the page type
and now returns the type write's updated_at when it ran (review note on
ansvisor#1262), so the editor goes on from the version it made; page-type detection
reads JSON-LD with the linear jsonLdScripts scan.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…locks

# Conflicts:
#	web/src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/_draft-editor.tsx
@cihan-gyk

Copy link
Copy Markdown
Collaborator Author

@gkhngyk The note on #1262 is fixed in the merge 56c1319 (and up the stack):

(With #1258's check, a stale updated_at would no longer read as a conflict, since the page is compared. But returning the right one saves the extra read on the next save.)

gkhngyk
gkhngyk previously approved these changes Oct 21, 2026

@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.

Fixes check out. The type write now returns its own updated_at, and the merge's resolution of saveContentDraft combines the version check from #1258 with the detection step correctly. Detection reads JSON-LD through the new scan, so the İ offset fix in #1259 also fixes schema detection on Turkish pages. Nothing else needs to change here.

cihan-gyk and others added 7 commits October 21, 2026 17:54
…İ before them keeps them

`toLowerCase()` turns 'İ' into two UTF-16 units, so every İ before a JSON-LD
script shifted the positions taken from the lower-cased copy: the schema was
dropped on save, with as many characters of the text after it. Only ASCII
letters are lower-cased now, which keeps the length and stays linear.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…locks

# Conflicts:
#	web/src/lib/content/sanitize-draft-html.test.ts
The test merged up from ansvisor#1259 used extractJsonLd, which this branch
replaces with extractKeptBlocks.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The PRs below this one are squash-merged on main; this keeps only this branch's own change on top.

Claude-Session: https://claude.ai/code/session_0121amRjX7UFrgmGELAtkc7A

@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.

The fixes check out. Merging with the stack.

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

Labels

needs-migration Adds or edits a migration — apply it to the hosted database

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants