Give an agent a page's context

Print what a built page serves, says, and links, or what the whole site covers, for an agent to read before it writes or audits a page.

contentbit context reads the same build and Markdown as contentbit check, and prints what an agent needs before it changes a page: what the page serves, what each section says, and how the page links to the rest of the site. It is read-only and prints to stdout.

Build the site first. Markdown is optional. A site without it gets every part that comes from its built pages, and no declared facts, primary keywords or contracts, which come from Markdown files.

Pass the page:

contentbit context /docs/guides/check/

The output is Markdown written for an agent to read. On contentbit.dev, it starts like this, with each section's text cut short here:

# Page context: /docs/guides/check/

- URL: https://contentbit.dev/docs/guides/check/
- Source: content/docs/guides/check.mdx, route /docs/guides/check/

## Served

- Title: Check a site · contentbit
- Description: Check the built pages and the Markdown content of a site with one command, in a terminal or in CI.
- Canonical: https://contentbit.dev/docs/guides/check/
- Lang: en
- Robots: index, follow
- Hreflang: none
- Structured data: none

## Declared

- Title: Check a site
- Description: Check the built pages and the Markdown content of a site with one command, in a terminal or in CI.
- Type: docs-page
- Intent: documentation
- Primary keyword: none

## Outline, 999 words

- h1 Check a site, 159 words
  Check the built pages and the Markdown content of a site with one command…
  - h2 Set the build folder and the origin #set-the-build-folder-and-the-origin, 58 words
    Name the build folder and the public origin in the config when detection…

A page context has these parts:

PartWhat it holds
ServedWhat the head of the built page says, as above.
DeclaredWhat the page's Markdown file declares, when links.routes gives the file this page. The SEO config fills in what the frontmatter leaves out, such as a type from pageDefaults.
OutlineThe text before the first heading, then every heading of the page content with its level, id, word count, and section text. The page content is the main element, or the article in it that holds its h1, or the whole page when it has no main or its h1 sits outside it, without the header, nav, aside, and footer landmarks. The sections add up to the total.
Links inEvery link on another page that points to this one, with its text and anchor. Content links are listed one by one. Layout links are grouped by their text.
Links outThe page's content links to other pages and what each one points to.
FindingsWhat check reports for this page, including the template findings that cover it.
Markdown findingsWhat check reports for the page's Markdown file.
ContractThe acceptance checks of the SEO contract for the page's type, when the page has a Markdown file and the SEO config gives it a type.

A link counts as a content link when it sits in the page content, outside the header, nav, aside, and footer landmarks, by tag or by ARIA role. As in HTML, a header inside main, an article or a section is not a landmark. A footer is layout as the footer of the page, of main, or of the article that holds the page content, where a docs theme puts the edit link, dates and pagination. A footer inside a blockquote, a card or a comment is content, such as a testimonial's attribution. An aside is layout when at least half of its words are link text, as in a sidebar or a table of contents, so a callout or a pull quote is content: its words count and its links are content links. A docs theme's table of contents, breadcrumbs and pagination are layout when they sit outside the page content, in a nav, or in such a footer or aside.

When the SEO config is invalid, the context starts with its problems. It then has no page types, planned pages, or contracts from the SEO config.

Name the page

The target is a page path or a URL on the site's origin, a Markdown file, or a page key or slug, tried in that order. A Markdown file is its path from the current folder, or its name, such as first-loaf.md, when one file has it. A key or slug comes from the frontmatter or the SEO config. The key of a page that the SEO config plans and no Markdown file has yet prints its declared facts and its contract, so an agent can write the page to it. See Plan a page before it exists.

When nothing matches, context exits 2 and suggests the closest page path, file, key, or slug. A Markdown file with no built page exits 2 and says why: links.routes gives the file no route, the build has no page at its route, or the file is a draft. A slug that several pages share, such as one slug in two locales, exits 2 and lists the pages, and a file name that several files have exits 2 and lists the files.

Run it without a target:

contentbit context

The site context has these parts:

  • A table of every built page with its title, Markdown file, declared type, primary keyword, word count, and the number of content and layout links that point to it.
  • The primary keywords that more than one page declares, compared without regard to case or spacing.
  • The unlinked pages: the indexable pages, other than the home page, that no content link on another page points to.
  • The template findings of the site.

Read it as JSON

contentbit context /docs/guides/check/ --json
contentbit context --json

--json prints one contentbit.page-context.v1 or contentbit.site-context.v1 object and nothing else. With an invalid SEO config, seoConfigFindings comes first and holds its problems. The page context has the rendered page facts that check --json leaves out: outline holds each heading's level, text, id, body, and words. Each entry in linksIn and linksOut has a placement of content or layout. Each link out has a target with a kind of page, external, redirect, host-route, file, or missing, and the page path for a page. contract holds what the page type asks for, with its acceptance checks and up to 10 other pages of the type, and the findings that break it are in findings and contentFindings. Its target and each of its relatedPages give a page's id, key, slug, locale, title, type, the path of its Markdown file, and a source of existing, or planned for a page that only the SEO config describes. A template finding there names this page's targets, not another page's example. File paths are relative to the project root, in JSON and in the Markdown output.

Use it before an agent writes

Give the agent the site context and the page context, so it keeps the page's declared keyword, avoids a primary keyword that another page declares, and links to unlinked pages where they fit. For a new page, give it the context of the planned page's key, or of the closest page of the same type. Then rebuild the site and run check. Use with a coding agent installs that loop.

When Markdown files changed after the build, context writes a notice to stderr. Rebuild the site so the built pages show the changes. The CLI reference lists the options and exit codes.