Long-enough articles (3+ in-body h1/h2) get slug ids (python-slugify,
mirroring the editor's slugify.js) and the heading text becomes a
self-link (a.anchor) for clean link copying; {#id} always wins,
duplicates get -2/-3 suffixes, h3+ never. The implicit page title is
now injected as '# {title}' into the markdown (render(title=...)), so
it takes the same first-h1 path as an explicit one: no id, href=""
self-link scrolling to top, not counted toward the threshold. The
.body wrapper is gone — segments are direct article children — and the
editor preview swaps the whole article in one go. pagerite.js tracks
the reading position in the location hash (last tagged heading above
the viewport middle; cleared at the top, never on unscrollable pages)
and scrolls to anchors after fetch-navigation.
5.8 KiB
5.8 KiB
AGENTS.md
- Do NOT test, run the server, write tests etc.
- ESPECIALLY DO NOT make repros, do NOT install Playwright etc.
Please instead ask the user to see from dev tools what you need, e.g. to look up something in DOM or log. Use console.log for debugging where needed (and otherwise for permanently kept useful messages in the app).
Layout
Pagerite is a CMS. See docs for the full design and implementation details. Key files for code changes:
pagerite/— Python backend package (hatchling build target).app.py— FastAPI app and route registration.data.py— msgspec Structs for the kanta database.migrations.py— kanta schema migrations (migrate_vN), e.g. v1 moves legacy in-db file blobs to the on-disk store.markdown.py— markdown-it-py renderer.views.py— shared page layout and rendering.seed.py— demo content, written only on first database creation.analytics.py— visit analytics collection (seedocs/analytics.md).
frontend/src/— Vue editor and public-page JS entries.main.js— Vue editor app entry.analytics-main.js— analytics page entry (mountsAnalyticsViewat/_a).pagerite.js— public page entry.assets/— base CSS, Pygments styles, fonts.
scripts/devserver.py— dev server with auto reload (the user mostly uses this; avoid running the server yourself, ask the user to test).
Server run by CLI entry point uv run pagerite (no auto reloads, build needed). Dev mode is scripts/devserver.py (auto reloads, no build needed).
Toolchain
- Python >= 3.14, managed with uv. Dependencies:
fastapi[standard],fastapi-vue,html5tagger,kanta,markdown-it-py,mdit-py-plugins,pygments,tracerite; dev group hashttpx. Run anything viauv run ...(the venv is.venv). - Key libraries:
- html5tagger — all HTML generation (
E,Document,Template,HTMLfor trusted/raw HTML).- To create stand alone pages, begin with
doc = Document(...)that gives a HTML5 page header - Chain with
doc.p("text").br: every attribute access creates element to doc (returning self), calls add content to current element. - Closing tags are not used where optional, e.g. no
</p>or</li>is ever included in output. Due to this proper "nesting" of content is NOT required and should be avoided. Where needed, () directly after tag define attributes and content INSIDE the element, then close the element.with doc.ul:and such may be used for larger chunks. - Prefer building directly on one builder with
withblocks (recursing inside a with block for hierarchies) over preparingE.snippets into variables and composing them. Notewith doc.li:alone fails (lihas an optional end tag) — usewith doc.li.ul:style chains, ordoc.li.a(...)followed by a nestedwith doc.ul:block. Template(builder)freezes a builder with Capitalized attribute placeholders (e.g.E.Title,doc.main(E.Main, id="main")); calling it fills the slots with escaping — passHTML(...)for raw HTML. Passing a list to a template slot expands it; passing a list to a normal builder call does NOT (spread it:E.ul(*items)).- To create plain HTML snippets use
E.div(E.p("content"))etc using theEempty builder.
- To create stand alone pages, begin with
- kanta — asyncio-native embedded database:
Kanta(filename, data)root object,transaction,flush, snapshot/replay-log persistence.async with Kanta(Data(),...) as kanta:(or await kanta.open/close)with kanta.transaction(...) as data:- transactions only for writesdatamay be referenced directly to read anywhere and to modify in transactions (as datais just a shorthand access)- Data structures should be msgspec.Structs, where JSON restrictions do not apply (we can use
bytes,UUID,datetimeetc. even as dict keys)- We prefer objects rather than lists, as this works better in change diffs. E.g.
dict[str, True]where the keys indicate presence and always have valueTrue.
- We prefer objects rather than lists, as this works better in change diffs. E.g.
- Maintaining and owning the app's own
Dataobject is preferable; Kanta never copies this, only edits in place - Note: besides opening it every access is immediate direct variable access: no
await, no locks, no delays
- fastapi-vue — template glue for serving/building the Vue frontend; keep its integration points (
Frontend, build hook) intact. - markdown-it-py — Markdown rendering with
html=Trueraw passthrough; mdit-py-plugins for footnote/deflist/tasklists/attrs; in-body h1/h2 headings get auto slug ids + self-links when the body has 3+ of them (python-slugify, mirroringslugify.js); Pygments for server-side code highlighting (nowrapspans, styled byfrontend/src/assets/pygments.csswhich maps token classes 1:1 onto the--code-*variables; light/dark palette sets live inpagerite.cssand resolve vialight-dark()from the theme'scolor-scheme— themes pick a set, not individual colors).
- html5tagger — all HTML generation (
Conventions
- Keep dependencies minimal; add via
uv addand mention it. - The public URL space belongs to content (pretty slugs at root). Reserve only
/_for the machinery (/_api/,/_f/,/_assets/), plus/favicon.icofrom the build. Slugs are lowercase ASCII letters, digits, hyphens and underscores[a-z0-9_-](the site editor filters input live viaslugify.js, built on thetransliterationnpm package — unicode folds to ASCII, spaces become hyphens; an empty slug on a new page is derived from its title), may not begin with_or., and such URLs are never looked up as content. - No auth in core code; the SSO/reverse proxy gates all of
/_api(forward-auth) and owns/auth/(login/logout, session validation). Pages render identically for everyone; pagerite.js adds the editing UI only after the auth server validates the session. - Update the relevant MarkDown files when architecture, tooling, or conventions change.