Skip to content

feat(content): keep an inventory of each brand's site pages - #936

Merged
gkhngyk merged 1 commit into
mainfrom
feature/site-page-inventory
Oct 5, 2026
Merged

gkhngyk merged 1 commit into
mainfrom
feature/site-page-inventory

Conversation

@gkhngyk

@gkhngyk gkhngyk commented Oct 5, 2026

Copy link
Copy Markdown
Contributor

Summary

First PR of Phase 2 in #857. Content opportunities suggest new content even when the site already has a page for the need. On the main test brand, an opportunity proposed a "software list for AI SEO and AEO" while the site already has a complete list of AI SEO tools that AI answers cite. This PR keeps an inventory of each brand's pages. The next PR uses it to decide between creating, optimizing, expanding or refreshing.

What is collected

  • Up to 500 pages per brand, stored in site_pages (migration 00104).
  • For each page: where it was found, its GA sessions and AI citations over 30 days, title, meta description and first heading, and the status of the last read.
  • Page bodies are not stored.

Where pages come from

The site is not crawled. Pages come from lists the brand already publishes or that we already hold:

  • Sitemap: the Sitemap: lines in robots.txt, otherwise /sitemap.xml and /sitemap_index.xml. One level of sitemap index is followed and gzipped sitemaps are read. At most 5,000 URLs.
  • GA: landing pages with sessions in the last 30 days, through the new brand_landing_page_sessions.
  • AI citations: the brand's own cited URLs, through the existing ae_owned_citations.

Which pages are kept

  • URLs are normalized: https, no www., no query or fragment, no trailing slash.
  • Other hosts, files, and the checkout, legal and careers paths from page-paths.js are dropped. Subdomains count as the site.
  • Pages with AI citations come first, then by traffic, then in sitemap order.

How pages are read

  • Each page's head is requested directly with an AnsvisorBot user agent and a 10 s timeout, five at a time.
  • Only a response that looks like a bot wall goes through Scrape.do, with render: false: a 401, 403, 429 or 503, or a challenge page.
  • A page is re-read after 30 days. Pages that leave the top 500 are removed.
  • Every run logs how many pages were read directly, through Scrape.do and failed, so the credit cost is visible.

When it runs

  • The tracking worker runs it between the cluster refresh and opportunity generation, for plans with content optimization.
  • A failure is logged, and generation still runs.

Tried on production data

The migration is applied. The main test brand produced:

  • 415 sitemap URLs, merged with GA and citations into 410 pages;
  • 392 pages read directly, with 0 sent through Scrape.do (0 credits) and 18 returning 404, in 2 min 53 s.

The 404s are real. They are deleted pages that still received 268 GA sessions in 30 days. The next PR will not treat them as existing pages.

Related issue

Part of #857 (Phase 2)

Type of change

  • feat — New feature
  • test — Adding or updating tests

How to test

  1. Run refreshSitePages('<brand id>') from server/src/lib/site-pages.js for a brand with a primary domain.
  2. Check site_pages: titles and descriptions are filled, and sources shows sitemap, ga and citation.
  3. Run it again. The log shows read: 0, because nothing is re-read within 30 days.

site-pages.test.js covers URL normalization, sitemap and robots.txt parsing, head parsing, bot-wall detection and page selection.

Checklist

  • Branch follows the naming convention
  • Commits follow Conventional Commits
  • yarn lint, yarn format:check and yarn test (969) pass (run from server/)
  • supabase/schema.sql rebuilt with build-schema.sh

🤖 Generated with Claude Code

Content opportunities can only say "update the page you have" instead of
"write a new one" if they know which pages the site has (#857, Phase 2).

- Migration 00104 adds site_pages: up to 500 pages per brand with their
  sources, GA sessions and AI citations over 30 days, title, meta
  description, first heading and last read status. Page bodies are not
  stored. It also adds brand_landing_page_sessions for the GA side.
- lib/site-pages.js picks the pages from the sitemap (robots.txt Sitemap
  lines, else /sitemap.xml, one level of index, gzip supported), GA landing
  pages and the brand's own cited URLs, pages with citations and traffic
  first. The site is not crawled.
- Each page's head is read directly and re-read every 30 days. Only a page
  that answers with a bot wall goes through Scrape.do, unrendered. The run
  logs how many pages went each way.
- The tracking worker refreshes the inventory between the cluster refresh
  and opportunity generation. A failed refresh does not block generation.
@github-actions github-actions Bot added the needs-migration Adds or edits a migration — apply it to the hosted database label Oct 5, 2026
@gkhngyk
gkhngyk merged commit 8a4dedd into main Oct 5, 2026
6 checks passed
gkhngyk added a commit that referenced this pull request Oct 5, 2026
#939)

Opportunities suggested new content even when the site already had a page
for the need (#857, Phase 2). Generation now reads the site page inventory
(#936) and says what to do with which page.

- lib/page-matching.js narrows a brand's pages to the 8 most likely to
  cover a cluster's need, by the rarer words they share. No model call.
- The generation call sees those pages, with their AI citations, sessions
  and last-modified date, and returns a decision per cluster: create,
  optimize, expand, refresh, consolidate or defend, with the pages it is
  about. Every decision but create needs a page and consolidate needs two;
  one that lacks them falls back.
- Consolidate is only for near-duplicate pages about the same need, and an
  opportunity takes at most 3 clusters from other topics before it stops
  being offered as a merge target. Both came from bad results on real data.
- Migration 00105 adds content_opportunities.decision. The pages are kept
  in source_data.targetPages and survive merges.
- The brief works on the named page instead of drafting a new one.
- The list shows the decision under the type, and the detail page has a
  "Your Site" card with the decision and links to the pages.
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.

1 participant