feat(napi): add RwSite.listPages() enumerating pages with titles#579
Merged
Conversation
Closes #576. Add a reload-aware napi method that enumerates every page in a site, each with its title and its (sectionRef, subpath) key — the same pair the comment system uses as a page's document_id. This lets a host (the Backstage doc-comment inbox) cache human-readable page titles in one cheap pass when a site is already loaded, instead of N+1 per-page renderPage() calls or repeated S3 site loads at serve time. Implemented as a direct three-layer mirror of the existing listSections(): - SiteState::list_pages() walks SiteState.pages, computes each page's (section_ref, subpath) via the existing section_location seam, reads the title, and sorts by (section_ref, subpath). New public PageEntry struct. - Site::list_pages() reloads-if-needed then delegates (mirrors list_sections). - napi listPages() wraps it in spawn_blocking; new PageEntryResponse type; regenerated index.d.ts -> listPages(): Promise<Array<PageEntryResponse>>. Every page is included — the root page (empty subpath) and virtual directory pages — so any comment keyed to one still resolves a title. Fields are intentionally minimal (sectionRef, subpath, title); path/ancestors/order are omitted and can be added additively later. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #576.
Summary
Adds a reload-aware napi method that enumerates every page in a site, each with its title and its
(sectionRef, subpath)key — the same pair the comment system uses as a page'sdocument_id:Motivation
The Backstage doc-comment inbox (
rwdocs/backstage-plugins) wants to show a human page title instead of a raw path slug, and caches titles for all pages per site (rebuilt on the ownership-rebuild schedule, when each site is already loaded in memory). It needs to enumerate every page with its title in one cheap pass. The existing surface can't:listSections()enumerates sections (no title), andrenderPage()does a full render (Kroki, etc.) — far too costly per page. Resolving titles at serve time is also too expensive (the S3-modeHubLRU-caches ~20 sites, so a broad inbox would force repeated site loads).Implementation
A direct three-layer mirror of the existing
listSections():SiteState::list_pages()— walksSiteState.pages, computes each page's(section_ref, subpath)via the existingsection_locationseam, readsPage.title, sorts by(section_ref, subpath). New publicPageEntrystruct.Site::list_pages()—reload_if_needed()?then delegates (mirrorsSite::list_sections).listPages()—spawn_blockingwrapper; newPageEntryResponse; regeneratedindex.d.ts.Naming
The enumerated entity is a
Page(matchesPage/renderPage/SiteState.pagesand parallels the siblinglistSections/Section), and the set includes virtual directory pages that aren't comment "documents" — solistPages/PageEntryis the accurate, codebase-consistent name. The(sectionRef, subpath)key is still a page's commentdocument_id. (The issue proposedlistDocuments; renamed tolistPagesafter review.)Scope
Every page is included — the root page (empty
subpath) and virtual directory pages — so any comment ever keyed to one still resolves a title. Fields are intentionally minimal (sectionRef,subpath,title);path/ancestors/orderare omitted and can be added additively later.Testing
SiteState::list_pagesunit tests (root, nested-in-section, outside-any-section, virtual page,page_path_forround-trip, sort order) + 1Site::list_pagesintegration test.rw-sitesuite green (150 unit + 4 doctests);rw-napibuilds clean;index.d.tsregenerated tolistPages(): Promise<Array<PageEntryResponse>>.🤖 Generated with Claude Code