Skip to content
joinery / docs

Huella Legal's content model

Implemented1895 words · updated 6 hours agodocs/decisions/0027-huella-legal-content-model.md

🧭 Huella Legal's content model

Context

The /lab design shows fields that Entry doesn't carry: authors with bios and avatars, reading time, TOC, footnotes, bibliography, citation, issue number, series and a "Más leídas" sort. S1 in the implementation plan asks where each one comes from, where each gap gets filled, and how body HTML is sanitised. The lean was app-local mappers. The plan assumed WordPress exposes nothing beyond core. It turns out to expose several plugins, Yoast among them, so there's a second question: which plugin output to take.

Result

The live REST API was probed unauthenticated on 29 Sep 2026: 105 posts, 42 users (all public, each with at least one post), 14 categories, 35 tags and 21 pages. The recordings stay out of the repo.

The lean holds for everything derived from body, dates and terms, and is overturned for authors and SEO. WordpressProvider.listEntries never embeds author, and toEntry drops yoast_head_json, so no mapper over Entry can reach either.

Plugin outputPluginTaken
yoast_head_json on every post, term and userYoast SEOThe text fields only: title, description, robots.index
simple_local_avatar on users and embedded authorsSimple Local Avatarsfull, as the avatar
acf, empty on every post and userACFNo: installed with no fields
google-site-kit/v1Site KitNo: its routes answer 401
fluentform/v1, cookieyes/v1, akismet/v1Fluent Forms, CookieYes, AkismetLeft to S3 and S4
Design fieldSource foundFilled in
Authors_embedded.author, always one per post; no co-authors pluginPackage: Entry.authors
BioUser description, non-empty for 33 of 42Package: Author.bio
Avatarsimple_local_avatar.full for 27 of 42. The other 15 are hashless default-Gravatar URLsPackage: Author.avatar, left unset for the 15
RoleNothingDropped
Article countNothing on usersApp: aggregated from the post index
SEO title, description, noindexYoast: 48 custom titles, 84 descriptions (71 differ from the excerpt), 4 noindexPackage: Entry.seo, Term.seo
Canonical, og:url, JSON-LD, breadcrumbsYoast, with the WP host in every URLNot taken; E3 generates them against the new routes
Reading timeWord count ÷ 230. Yoast's own figures have a median of 230 wpm, and a strip-tags count lands within 10% of its wordCount on 86 of 105 postsApp mapper
TOCh2 (586) and h3 (826); 13 posts already carry heading idsApp pipeline, existing ids kept
FootnotesNo wp-block-footnotes. Word _ftn anchors appear in 1 post and bare <sup> numbers in 3App pipeline, in C1: _ftn anchors become ArticleBody.notes. Amended 2026-10-09: the bare <sup>s turned out to be ordinals and one stray number, not notes, so they render as written
BibliographyThe last heading matching bibliografía, fuentes or referencias, in 56 postsApp pipeline: split from that heading to the end
CitationAuthors, title, date, new URLApp mapper
Issue "Nº"NothingDropped
SeriesNo tag or category convention; one two-post run, numbered only in its titlesDropped
Format (B designs)Tag trabajos-de-fin-de-grado, the jurisprudencia-* tagsApp term map. Amended 2026-10-27: category ensayos was read as a format too, but its posts are short opinion pieces filed under it alone, so it is a subject like any other
Primary categoryThe first category; 103 posts have exactly oneApp mapper
hl-noteTheme class contenedor (13 uses)App pipeline class map
Quote and callout stylescita-larga (53 posts), cita-corta (32), texto-importante (24), texto-destacadoApp pipeline class map
hl-law, hl-numNot in the corpus; no heading is numberedNo source
"Más leídas"No view counts; orderby=comment_count answers 400Dropped

No post has a <table>. Bodies do carry <meta charset> (50 posts), style= (9) and empty superfontello3-* icon spans (23 uses). None has <script>, <iframe> or an on* attribute.

Sanitising runs server-side, in an app route that also runs the rest of the pipeline and caches the result. A mapper in shared/ would also run in the browser, because useContent refetches on client navigation. The library is the rehype stack. Line numbers are as of this report:

#FileChange
1packages/content/src/core/domain/content.ts:39 EntryAdd authors: Author[] and seo?: Seo. Author = { id, slug, name, bio?, avatar?: Asset }, Seo = { title?, description?, noindex? }
2content.ts:31 TermAdd seo?: Seo
3content.ts:66 EntryQueryAdd author?: string, for C2's author profile
4wordpress/WordpressTypes.ts:24author under _embedded, yoast_head_json? on entry and term, a WordpressUser type
5wordpress/WordpressProvider.ts:17Embed wp:featuredmedia,wp:term,author, and send author from query.author
6wordpress/WordpressHelpers.ts:45 toEntry, toTermMap authors and seo. seo exists only when yoast_head_json does
7nuxt/runtime/server/utils/request.ts parseQueryAdd author: toText(query.author), for entries only, the way term is handled
8nuxt/runtime/composables/useContent.ts toRequestQuerySerialise author
9packages/content/src/index.ts, packages/content/README.md "📄 The domain"Export Author and Seo; update the type block
10apps/huella-legal/server/utils/ (new)Pipeline: rehype-parse → class map, drop meta, style and icon spans, heading ids, TOC and bibliography extraction, image loading → rehype-sanitize → rehype-stringify. The schema is spelled out rather than defaulted: clobber: [], figure and figcaption added, className and id on *, the default's per-tag className lists removed (a, code, h2, li, ol, section, ul), and img gaining alt, width, height, loading, decoding, srcSet and sizes
11apps/huella-legal/server/api/articles/[slug].get.ts (new)Cached. Builds the provider from useRuntimeConfig(event).content.vendor the way resolveProvider in request.ts does, and returns the Article view model
12apps/huella-legal/server/api/authors.get.ts (new)Cached. Pages through posts at WP's 100 per request (2 requests today), and returns distinct authors with counts
13apps/huella-legal/shared/ (new)Pure mappers: Entry → ArticleSummary (reading time, primary category, format), and the citation

unified, rehype-parse, rehype-sanitize and rehype-stringify go into apps/huella-legal/package.json. That is the dependency check-in. unified 11.0.5 and rehype-slug 6.0.0 already resolve in the workspace, through @nuxt/ui → @nuxt/content → @nuxtjs/mdc.

Options considered

OptionWhy not
App-local mappers for authors and SEOThe provider discards both before Entry exists
A users resource, as a third family, for ColaboradoresEvery user has a post, so the post index yields the same authors plus the counts users lacks. A third family touches content.ts, parsing.ts, both routes and useContent
Dropping YoastLoses 48 hand-written titles, 71 descriptions that differ from the excerpt, and 4 noindex choices
Taking Yoast whole (yoast_head or all of yoast_head_json)Every URL in it is the WP host, which moves at cutover. yoast_head is raw HTML for <head>
Reading time from Yoast's twitter_miscA formatted Spanish string under a Spanish key
Issue "Nº" as the post's ordinal within its yearIt renumbers every later post when one is back-dated or unpublished, and that number goes into citations
Sanitising at render, in shared/ or a controllerShips the parser to the browser and reparses on every client navigation
ultrahtml 1.7.0No dependencies, but its sanitize transformer kept onclick and a javascript: href
sanitize-htmlSafe, but it gives no tree for TOC and bibliography extraction, so the body gets parsed twice
isomorphic-dompurifyPuts jsdom in the server function
Hand-rolled regexNot a sanitiser

Consequences

This unlocks A3 and A4, and lets B2 type against ArticleSummary. Four pieces of the kit lose their data: SeriesNav, IssueNumber, "Más leídas" and the author role. B1 and C3 drop them, or the design is revised first. Notes with back-links keep theirs, because B6 built the component and C1 parses the _ftn footnotes into it.

Order. Changes 1–9 come first, in one package change, because every app mapper types against Entry.authors. Then 10 and 11 (A4), then 13 (A3). Change 12 lands with C4, which is its only consumer.

Findings for the other spikes:

  • S2. WP echoes any request Origin in access-control-allow-origin, with credentials allowed. Browser-side search is therefore possible, contrary to the plan.
  • S4. Yoast's sitemap index answers 200, which makes it the permalink inventory. 47 bodies link to uploads by absolute URL on the live host, and 53 link to other posts the same way. Both are literal in post_content, so they break at the hostname move unless the pipeline rewrites them or Nuxt proxies /wp-content/uploads/**. The S4 map therefore feeds change 10.
  • Cost. A 10-post list with embeds is about 550 KB upstream, about 12 KB of it Yoast per post. Change 12 pulls every body, about 5.7 MB per fill. WP's _fields would cut that, but the provider has no such axis yet.

Tripwires:

  • The recordings hold the live host in every link, guid and source_url, plus real names and bios. The fake WP synthesises its data (S5).
  • WordpressProvider.spec.ts:46 and :88 assert the _embed string, and WordpressHelpers.spec.ts:92 compares a whole Entry with toEqual. ContentProvider.spec.ts and content.spec.ts build Entry literals, which a required authors fails to typecheck. Changes 1 and 5 are expected to break all of them.
  • rehype-sanitize's default schema (hast-util-sanitize 5.0.2) rewrites every id to user-content-<id>, which breaks the TOC's anchors. It also empties class on h2 and drops figure, figcaption, loading and srcset. That is why change 10 lists its schema in full.
  • contentKey.ts:13 spreads the query, so author is keyed with no change there.
  • An embedded author carries simple_local_avatar as a falsy value when unset. A hashless Gravatar URL is a placeholder, never an avatar.
  • Yoast titles already end in a site suffix the editor chose. Use them verbatim, and never append the site name again.
  • The 4 noindex posts stay out of E3's sitemap too.

Revisit this if a co-authors plugin appears, or once comments are designed: 134 already exist.

Confirmation

ClaimCheck
Entry carries authors and seo from WPpnpm exec nx test @joinery/content, with toEntry specs over an embedded author and a yoast_head_json sample
No Yoast URL field is readgrep -nE "canonical|og_url|schema|yoast_head\"" packages/content/src/core/adapters/providers/wordpress/*.ts finds nothing outside specs
The pipeline strips unsafe markupA spec beside the pipeline in apps/huella-legal/server/utils/, with inline onclick, javascript:, <script> and <meta> samples
The sanitiser never reaches the browserAfter pnpm exec nx build @joinery/huella-legal, grep -rl "user-content-" apps/huella-legal/.output finds a chunk under server/ and none under public/
No endpoint is committedgit grep -ni for the live hostname finds nothing, and every spec host is wp.test