Skip to content
joinery / docs

Overview

2188 words ยท updated 6 hours agoapps/huella-legal/README.md

๐Ÿ“ฆ @joinery/huella-legal

A Nuxt 4 redesign of the Huella Legal law blog. Content comes from an external WordPress through @joinery/content; the site is Spanish-only.

Development

CommandWhat it does
pnpm devDev server against the fake WordPress, never huellalegal.com
pnpm dev:apiDev server against the live WordPress. Only when the fakes can't show it
pnpm buildProduction build into .output/. Also typechecks, which is why it's slow
pnpm previewServe the production build
pnpm testVitest. pnpm test:coverage enforces the thresholds
pnpm test:e2ePlaywright against .output/. Build first, or run nx test:e2e
pnpm storybookStorybook on port 6007; pnpm build:storybook for a static build
pnpm cache:clearEmpty the local articles and content caches so the next request rereads WordPress
pnpm exec nx nuxt-prepare @joinery/huella-legalRegenerate .nuxt by hand; Nx already runs it before lint, typecheck, test and build

Dev mocks

pnpm dev preloads mocks/server.ts, an MSW fake of WordPress serving mocks/content.json. The live host blacklists machines that read it too often. An unknown slug is a 404; any other request to huellalegal.com is an error in the dev log. Kit, Turnstile and Resend stay inert without their keys.

API reference

Every /api route is documented at /_openapi.json and browsable at /_scalar, in dev and on every deploy. A route adds itself with defineRouteMeta({ openAPI }) โ€” literals only, since Nitro reads it from source and silently drops an imported constant.

Deployment

GitHub Actions builds, Netlify hosts (deploy-huella-legal.yml). Netlify's own git builds stay off.

TriggerDeploys
Push to masterProduction, then warms the listing caches
Pull requestA preview, linked in one PR comment
Monday 05:00 UTC, or by handProduction. Also the way to purge the CDN after an urgent fix
  • The huella-legal job is a required check, so it always reports and passes when netlify-ignore.sh finds nothing relevant changed. That list is kept by hand: a new runtime @joinery/* import needs a line there.
  • Never split the deploy into netlify build + deploy --no-build: the upload drops the image CDN config and every WordPress image breaks.
  • NETLIFY_SITE_ID is a repo variable and NETLIFY_AUTH_TOKEN a secret. Fork and Dependabot PRs get neither and pass without a preview.

Staging login

staging.huellalegal.com and every *.netlify.app URL ask for Basic Auth; the public host doesn't. modules/stagingGate.ts writes a Netlify edge function on production builds only. With STAGING_USERNAME or STAGING_PASSWORD unset, gated hosts answer 401. A new alias outside those two patterns stays open until it's added to GATED_HOSTS.

Rendering

Pages that read no query string are prerendered; the rest are cached by Netlify's CDN through isr route rules. 0033 has the reasoning.

RouteServed as
Articles, WordPress pages, /, /areas/, /colaboradores/, /contacto/, /publicar/, /sobre/, /calculo-intereses/Prerendered
Listings, /buscar/, /feed/, GET /api/*isr for a day, varying on their query keys
/api/articles/:slug/commentsisr for ten minutes
Form routes, /sitemap.xmlUncached function
  • Each layer declares its own rules under rendering in its nuxt.config.ts; modules/rendering.ts turns them into route rules. Prerendering only happens when NUXT_SITE_ENV is set, so CI and e2e builds don't shadow the fakes.
  • A WordPress outage fails the build and the previous deploy stays live. A runtime 5xx is never cached (server/plugins/cdn.ts).
  • Hydration is deferred to load or the first interaction (deferHydration.ts), and a click made before then is replayed. 0034 has the numbers.
  • An icon rendered client-side first (inside ClientOnly, a lazy component, a client navigation) must be listed in the design layer's icon.clientBundle.icons. A miss shows in Netlify's log as /api/_nuxt_icon/โ€ฆ.

Reproduce a deploy build locally (it reads the live WordPress):

NUXT_SITE_ENV=preview pnpm exec nx build @joinery/huella-legal --skip-nx-cache

Abuse and hardening

Every BFF route is public, so input is capped and checked first: each free-text field has a maximum length in the browser and the route, forms carry a honeypot and a Turnstile token, and nuxt.config.ts sets the security headers and the robots.txt that turns away AI crawlers. The Turnstile site key's hostname list in Cloudflare is what ties tokens to our domains. Abusive IPs are blocked by hand in Netlify's firewall, never in the repo.

Environment

A variable a feature can't work without goes under requiredEnv in its layer's nuxt.config.ts. A production build fails naming each unset one; nuxt dev warns; other builds ignore them. Every variable is read at startup, except that prerendered pages bake in what the build had โ€” so Netlify must expose them to builds too.

VariableWhat it is
NUXT_CONTENT_VENDOR_BASE_URLWordPress site root, with scheme, without /wp-json
NUXT_SITE_ENVproduction or preview on deploys, unset elsewhere. Unset or preview means noindex
NUXT_PUBLIC_SITE_URLOptional. Overrides the public origin used for permalinks and canonicals
NUXT_PUBLIC_PAGE_SLUGSJSON array of WordPress page slugs served at /:slug/. Leave unset for the default
NUXT_ARTICLES_HIDDEN_TERMSOptional. JSON array of category/tag slugs whose posts stay out of every listing
STAGING_USERNAME, STAGING_PASSWORDThe staging login. Needs Netlify's Functions scope
NUXT_NEWSLETTER_API_KEY, _FORM_IDKit API key and the form new readers join
NUXT_NEWSLETTER_BASE_URLOptional. Kit API origin, without /v4
NUXT_MAIL_API_KEYResend API key for Contacto and Publicar
NUXT_MAIL_BASE_URL, _FROM, _TOOptional. Resend origin, sender and Contacto's inbox
NUXT_PUBLIC_SUBMISSION_EMAILOptional. Publicar's editorial inbox
NUXT_FORMS_SLOW_REPLIES_UNTILOptional YYYY-MM-DD. Shows a "replies will be slow" notice on the forms until that day
NUXT_COMMENTS_USERNAME, _APPLICATION_PASSWORDWordPress user that files comments. Needs Editor (moderate_comments)
NUXT_TURNSTILE_SECRET_KEY, NUXT_PUBLIC_TURNSTILE_SITE_KEYTurnstile keys
NUXT_PUBLIC_OBSERVABILITY_URL, _APP_ENVIRONMENTFaro collector. Unset, browser telemetry is off
NUXT_OBSERVABILITY_URL, _INSTANCE_ID, _TOKENGrafana OTLP gateway and credentials. Unset, server telemetry is off
NUXT_PUBLIC_TRACKERS_GOOGLE_ANALYTICS_IDGA4 ID. Unset, no GA and no cookie banner
NUXT_PUBLIC_SOCIAL_INSTAGRAM, _LINKEDIN, _XFooter profile links. Each unset one is hidden

Public values that are the same everywhere (site URL, sender, inboxes) are literals in the nuxt.config.ts of the layer that owns them; the matching NUXT_ variable still overrides them.

i18n

Copy lives in i18n/locales/es-ES.json, handed straight to @nuxtjs/i18n with no TMS (Tolgee's 500-key cap was outgrown). One locale, no_prefix, no browser detection. Specs see keys, not copy: vitest.setup.ts empties the messages.

Copy keys

RuleExample
First segment is the owner: app for the shell, a page, or a component in camelCaseapp.title, article.back, articleCard.readingTime
Then element and role, camelCase, nested objectsapp.footer.links.publishThesis
Name the role, never the wordingarticle.back, not article.backToArticles
Named params; plurals use vue-i18n's | form"{page} de {total}", t("articleCard.minutes", n)
common only for copy that means the same everywherecommon.loading
Keys sorted alphabetically at every levelโ€”

Content

Only the articles layer's server routes call useContent; every page reads those routes. The routes map WordPress entries into view models, so neither the CMS URL nor raw HTML reaches the browser. Listings, search suggestions and counts slice one cached index of every post (an hour in production, five minutes in dev), so a new post can take a couple of hours plus the CDN's day to list. The module README has the cache options.

The body pipeline

toArticleBody turns a post's HTML into markup safe for v-html, server-side. 0027 has the corpus behind each rule.

StepWhat it does
Class mapWordPress classes โ†’ hl-note, hl-quote, hl-quote-short, hl-callout, hl-highlight. Everything else dropped
Sanitiserehype-sanitize, GitHub schema, ids unprefixed
Notes#_ftnN / #_ftnrefN links become notes; any other shape renders as written
BibliographySplit off at the last Bibliografรญa, Fuentes or Referencias heading
TOCEvery h2/h3 gets a unique ASCII id
ImagesLazy, and /wp-content/ URLs repointed at content.vendor.baseURL
LeadUp to the first paragraph; the featured image goes after it

Structure

app/ is the thin shell: layout, header, footer, error page and client plugins. Domain code lives in Nuxt layers under layers/, auto-registered (never add extends).

OwnerPathsMay use
ShellThe rest of app/, server/, modules/Anything
Kitapp/components/{base,listing}, app/{types,utils,composables}, i18n/The kit
Corelayers/articles/ โ€” owns all content readsItself, the kit
Capabilitylayers/forms/, layers/design/Itself, the kit
FeatureEvery other layerItself, kit, core, capabilities. Its pages may render another feature's components

eslint.layerBoundaries in eslint.config.ts enforces the table, auto-imports included.

LayerHolds
articlesView models, WordPress mappers, every content route, the cached index, comments, sitemap and RSS
archiveHome, the four listings, รกreas, colaboradores and the about page
readingThe article and WordPress-page views
search/buscar/ and the header's โŒ˜K palette
commentsThe thread and form under an article; posts to WordPress held for moderation
newsletterKit signup, double opt-in
contactContacto, sent through Resend
publishPublicar, with an optional draft attachment
interestThe interest calculator at /calculo-intereses/ (README)
trackingConsent banner and third-party scripts, loaded only when an ID is set
legacy301s from old WordPress URLs (README)
formsHoneypot, Turnstile, assertForm, sendMail
designTokens and the Nuxt UI theme (DESIGN.md)

Components link by route name ({ name: "article", params: { slug } }), never by a built string. A page sets its path in definePageMeta; typedPages fails typecheck on a wrong name.

NamePath
index/
publications/publicaciones/
article/:slug/
categories, category/areas/, /areas/:slug/
tag/etiquetas/:slug/
authors, author/colaboradores/, /colaboradores/:slug/
search/buscar/
about/sobre/
contact/contacto/
publish/publicar/

Storybook

Stories sit beside their component as *.stories.ts. It's plain @storybook/vue3-vite (the Nuxt integration stops at Nuxt 3), so .storybook/ wires Nuxt UI, fonts, i18n, auto-imports and stubs for NuxtImg and NuxtTurnstile by hand. Its router repeats the route table by hand too. The published copy lives on the developer portal.

Observability

Both halves come from @joinery/observability and are off when their URL is unset.

  • Browser: observability.client.ts loads Faro on the first interaction or after ten seconds.
  • Server: observability.ts wraps the Nitro handler itself and names spans for the matched route, never the raw path. Off while prerendering.
  • errorLog.ts logs every handled 5xx with its cause.
  • Don't set NUXT_PUBLIC_OBSERVABILITY_APP_VERSION on Netlify; the build stamps the commit.

Testing

ProjectCoversCommand
nodeserver/, shared/, modules/, tools/ in the app and each layerpnpm test
nuxtapp/ specs, one shared Nuxt environmentpnpm test
nuxt-isolatedapp/ specs that mock a modulepnpm test
e2ePlaywright, Chromium, at 390, 768 and 1280 pxpnpm test:e2e

Configs wrap the presets in @joinery/configs; thresholds live in vitest.config.ts and pages are left to Playwright.

e2e

  • The built server runs with e2e/server.ts preloaded: MSW fakes WordPress (from @joinery/content/testing), Kit and Turnstile in-process. Nothing reaches the network.
  • Data is in e2e/fakes.ts. A route the fakes don't serve is a change to the content package's testing entry.
  • Every spec runs an axe scan. No screenshot baselines while the design still moves โ€” 0037 says when they return.
  • Any console output, browser or server, fails the run. Import test from @joinery/configs/playwright/utils/test.
  • Bumping @playwright/test means moving the image tag in ci.yml in the same PR. Pre-push doesn't run e2e.

Known gaps

GapNote
A new post reaches / only on the next buildWordPress has no webhooks (0030)
hl-quote, hl-callout and friends render unstyledNo design covers them yet
Netlify image CDN answers max-age=0Fix is on WordPress's side (LiteSpeed browser cache)
No script-src CSPisr-cached HTML rules out nonces
staging. serves the production deployThe login hides nothing www doesn't show