@donotdev/ui 0.3.2 → 0.3.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (57) hide show
  1. package/README.md +2 -3
  2. package/dist/crud/components/EntityCardList.d.ts +4 -1
  3. package/dist/crud/components/EntityCardList.d.ts.map +1 -1
  4. package/dist/crud/components/EntityCardList.js +1 -1
  5. package/dist/crud/components/useRecordBreadcrumb.d.ts +3 -1
  6. package/dist/crud/components/useRecordBreadcrumb.d.ts.map +1 -1
  7. package/dist/crud/components/useRecordBreadcrumb.js +1 -1
  8. package/dist/dndev-next.css +88 -37
  9. package/dist/dndev.css +88 -37
  10. package/dist/index.js +1 -1
  11. package/dist/internal/devtools/components/LayoutReset.js +1 -1
  12. package/dist/internal/layout/components/AutoMetaTags.d.ts +3 -0
  13. package/dist/internal/layout/components/AutoMetaTags.d.ts.map +1 -1
  14. package/dist/internal/layout/components/AutoMetaTags.js +1 -1
  15. package/dist/internal/layout/components/FaviconHead.d.ts +18 -14
  16. package/dist/internal/layout/components/FaviconHead.d.ts.map +1 -1
  17. package/dist/internal/layout/components/FaviconHead.js +1 -1
  18. package/dist/internal/layout/components/headTagElement.d.ts +16 -0
  19. package/dist/internal/layout/components/headTagElement.d.ts.map +1 -0
  20. package/dist/internal/layout/components/headTagElement.js +1 -0
  21. package/dist/internal/layout/components/prerenderedHead.d.ts +15 -0
  22. package/dist/internal/layout/components/prerenderedHead.d.ts.map +1 -0
  23. package/dist/internal/layout/components/prerenderedHead.js +1 -0
  24. package/dist/internal/layout/components/trailingSlash.d.ts +13 -0
  25. package/dist/internal/layout/components/trailingSlash.d.ts.map +1 -0
  26. package/dist/internal/layout/components/trailingSlash.js +1 -0
  27. package/dist/providers/NextJsAppProviders.d.ts.map +1 -1
  28. package/dist/providers/ViteAppProviders.d.ts +11 -9
  29. package/dist/providers/ViteAppProviders.d.ts.map +1 -1
  30. package/dist/providers/ViteAppProviders.js +1 -1
  31. package/dist/routing/DnDevNavigationMenu.d.ts.map +1 -1
  32. package/dist/routing/DnDevNavigationMenu.js +1 -1
  33. package/dist/routing/hooks/hooks.next.js +1 -1
  34. package/dist/routing/hooks/useRoutePath.next.d.ts +5 -3
  35. package/dist/routing/hooks/useRoutePath.next.d.ts.map +1 -1
  36. package/dist/routing/hooks/useRoutePath.next.js +1 -1
  37. package/dist/routing/useRouteDiscovery.d.ts +3 -0
  38. package/dist/routing/useRouteDiscovery.d.ts.map +1 -1
  39. package/dist/styles/index.css +88 -37
  40. package/dist/symbol-index.json +1 -1
  41. package/dist/utils/assetResolver.d.ts +19 -19
  42. package/dist/utils/assetResolver.d.ts.map +1 -1
  43. package/dist/utils/assetResolver.js +1 -1
  44. package/dist/utils/index.d.ts +0 -1
  45. package/dist/utils/index.d.ts.map +1 -1
  46. package/dist/utils/index.js +1 -1
  47. package/dist/vite-routing/AppRoutes.d.ts.map +1 -1
  48. package/dist/vite-routing/AppRoutes.js +1 -1
  49. package/guidelines/ROUTING.md +1 -0
  50. package/guidelines/SEO.md +160 -145
  51. package/package.json +8 -8
  52. package/dist/internal/layout/components/i18nSeoMeta.d.ts +0 -54
  53. package/dist/internal/layout/components/i18nSeoMeta.d.ts.map +0 -1
  54. package/dist/internal/layout/components/i18nSeoMeta.js +0 -1
  55. package/dist/utils/useSeo.d.ts +0 -129
  56. package/dist/utils/useSeo.d.ts.map +0 -1
  57. package/dist/utils/useSeo.js +0 -1
package/guidelines/SEO.md CHANGED
@@ -7,7 +7,7 @@
7
7
  ## How It Works
8
8
 
9
9
  **Vite:** AutoMetaTags reads route manifest + i18n - Helmet renders meta tags
10
- **Next.js:** Build generates `metadata-manifest.json` - `generateMetadata()` per page
10
+ **Next.js:** the same AutoMetaTags, server-rendered by the generated layout - React 19 hoists the tags into `<head>`
11
11
 
12
12
  **Same code, both platforms. No conditional logic needed.**
13
13
 
@@ -23,8 +23,8 @@
23
23
 
24
24
  | Platform | Static Pages | Dynamic Pages |
25
25
  |----------|--------------|---------------|
26
- | **Vite** | Prerender at build - meta in HTML | `<Seo>` + react-helmet-async - meta in prerendered HTML |
27
- | **Next.js** | `generateMetadata()` - server renders meta | `<Seo>` client-side OR `generateMetadata()` with fetch |
26
+ | **Vite** | Prerendered at build, one page per language - meta in HTML | Entity pages: one static HTML per public record at build, identity from the record (same as Next). Other dynamic pages: AutoMetaTags (the route's PageMeta + i18n, same for every URL) |
27
+ | **Next.js** | AutoMetaTags, in the server HTML | Entity pages: generated server metadata from the record (no app code). Other dynamic pages: the page module's own `generateMetadata`, else AutoMetaTags |
28
28
 
29
29
  **Verify:** View Page Source (not DevTools). Meta tags should be visible without JS.
30
30
 
@@ -35,12 +35,27 @@
35
35
  With 2+ languages every page has one URL per language (default language at the root, others
36
36
  under `/<lang>`, see core `I18N.md`). Automatic:
37
37
 
38
- - **Canonical / `og:url` / JSON-LD `url`:** the page in its own language (`/en/x` on the English page).
38
+ - **Canonical / `og:url` / JSON-LD `url`:** the page in its own language (`/en/x` on the English page), entity pages included (AutoMetaTags emits canonical / `og:url` on every route).
39
39
  - **`hreflang`:** one `<link rel="alternate">` per language plus `x-default` (the root URL).
40
- - **Sitemap (Next `src/app/sitemap.xml/route.next.ts`):** every language's URL of each page, each entry with `alternates.languages`.
40
+ - **Sitemap (Next `src/app/sitemap.xml/route.next.ts`, Vite `dist/sitemap.xml`):** every language's URL of each page, each entry with `alternates.languages`.
41
+ - **Prerendered pages (Vite):** one file per language URL (`dist/about.html`, `dist/en/about.html`), each with its hreflang alternates.
41
42
 
42
43
  One language: unprefixed URLs, no `hreflang`.
43
44
 
45
+ **Trailing slash (Next):** with `trailingSlash: true` in `defineNextConfig` (passed through to Next, which then redirects `/about` to `/about/`), every public URL the framework emits ends with `/`, language homes included (`/fr/`, `/about/`): canonical, `og:url`, `hreflang`, JSON-LD (`url`, breadcrumb items, entity page Product `url`, search `urlTemplate`), sitemap and llms.txt. File URLs (`/rss.xml`, images) keep their form. The build writes the setting into the route manifest (`routes.manifest.trailingSlash`) and the generated sitemap / llms.txt routes; `formatTrailingSlash` (`@donotdev/core`) is the one place that applies it. Unset or `false`: URLs unchanged.
46
+
47
+ ---
48
+
49
+ ## Dynamic Pages: Per-URL SEO Required
50
+
51
+ The build fails on a public, indexable `:param` route (not `auth`, not `seo: { noindex: true }`) that has no per-URL identity: all its URLs would share one title and description. Ways out, in the error (`[dndev-routes] <file>: public dynamic route <path> has no per-URL SEO ...`):
52
+
53
+ 1. Declare the record entity it shows: `entity: productEntity` (imported from `'entities'`, see Entity pages).
54
+ 2. Next only: export Next's `generateMetadata` from the page module (see Other dynamic pages). Vite has no server: not a way out there.
55
+ 3. `seo: { noindex: true }`.
56
+
57
+ Exempt, like the sitemap: error routes (`/404`, `/not-found`, `/500`, `/error`), catch-all routes (`/docs/*`: no URL list, never in the sitemap), blog post routes (`blog` namespace: identity from the post's frontmatter).
58
+
44
59
  ---
45
60
 
46
61
  ## Vite: Prerendering
@@ -53,31 +68,111 @@ export default defineViteConfig({
53
68
  });
54
69
  ```
55
70
 
56
- **What happens:**
57
- 1. Build discovers all routes from `src/pages/`
58
- 2. Renders each page to static HTML
59
- 3. `<Seo>` and AutoMetaTags populate `<head>` via react-helmet-async
60
- 4. Output: `dist/about/index.html` with full meta tags
71
+ **What happens** (after the bundle, no browser):
72
+
73
+ 1. `dist/_shell.html`: the SPA shell as Vite built it. The hosting rewrite serves it for every URL without a file (an unprerendered dynamic URL, a record published after the build); `dist/index.html` becomes the prerendered home page, so its tags never land on other URLs.
74
+ 2. One page per public static route and blog post **and per language** (default language at the root, others under `/<lang>`): `dist/about.html`, `dist/en/about.html`, `dist/index.html`, `dist/en.html`. Its head is the identity AutoMetaTags computes for that URL (`routeSeo` / `routeHeadTags` from `@donotdev/core`, the same functions: PageMeta + i18n in the page language, absolute `og:image` / `twitter:image`) plus canonical, `og:url`, `og:site_name` and hreflang (see Languages; `seo.hreflang: false` respected).
75
+ 3. One page per public record of each entity route and language (see Entity pages (Vite)).
76
+ 4. `dist/sitemap.xml` and `dist/llms.txt` of the same URL set (see Sitemap & llms.txt).
77
+
78
+ **Output layout: `<path>.html`.** A page URL has no trailing slash on Vite; `/produits/serum` is `dist/produits/serum.html`. The hosting serves it at the slash-less URL with no redirect (`cleanUrls`, see Hosting).
79
+
80
+ **In the browser:** each page embeds its identity tags (`<script type="application/json" id="dndev-prerendered-head">`, data: any CSP allows it). On that URL AutoMetaTags renders exactly them, and react-helmet-async keeps the prerendered nodes (they carry its `data-rh` marker): no flip, no duplicate. After a client navigation it replaces them like its own tags.
81
+
82
+ **Dynamic routes** without an entity (e.g., `/search/:q`): AutoMetaTags gives them the route's identity (PageMeta + i18n: one title and description for every URL), on the shell.
61
83
 
62
- **Dynamic routes** (e.g., `/products/:id`): Prerender with known IDs or use client-side `<Seo>`.
84
+ ### Entity pages (Vite): one static HTML per record
85
+
86
+ With `prerender: 'auto'` (the default), the build writes one page per public record of each entity route (Next's rule: single `:param`, indexable, page declaring `entity` in PageMeta) and per language: `dist/produits/serum.html`, `dist/en/produits/serum.html`. No app code.
87
+
88
+ - **Records:** the Next build's (`listPublicPages`: `status` not in `HIDDEN_STATUSES`, at most 1000 per route), read once at build as a signed-out visitor with the app's public reader: `@donotdev/supabase` (`VITE_SUPABASE_URL`, `VITE_SUPABASE_PUBLIC_KEY`, RLS decides) or `@donotdev/firebase` (`VITE_FIREBASE_API_KEY`, `VITE_FIREBASE_PROJECT_ID`, Security Rules decide). The same read fills sitemap.xml and llms.txt, so an app with entity routes reads its records at every build (also with `prerenderRecords: false`, for the sitemap). The build fails on a missing env, a failed read, another provider, no `entities` package, no site name, or (record pages) a `VITE_APP_URL` that ends with `/` (the browser builds the same URLs from it). A deploy build also fails on an unset or local `VITE_APP_URL`; a local build takes a local one and, without one, writes no record page (see Sitemap & llms.txt, URLs).
89
+ - **Head:** the Next entity page identity (`entityRecordSeo`, shared: title `<record title> | <site name>`, description, Open Graph, Twitter card, og:type from `seo.type`, Product JSON-LD for `product`, BreadcrumbList ending with the record title, text in the page language) plus the site tags and hreflang.
90
+ - **SPA shell instead** (the route's PageMeta + i18n identity): a record published after the build (until the next build), a value a static route already serves (the static page wins, as on Next), a value no file name can hold (`a/b`, `..`; listed in the build log).
91
+ - **Opt out:** `appConfig.prerenderRecords: false`. An explicit `prerender: ['/a', '/b']` list prerenders those routes only (globs `'/blog/*'` match page paths, never a `:param` template). A page module's `generateMetadata` is Next only: the Vite record page keeps the entity identity.
92
+
93
+ ### Hosting: clean URLs, the shell as fallback
94
+
95
+ The scaffolded configs serve `<path>.html` at `/<path>` (200, no redirect) and fall back to the shell:
96
+
97
+ - **Firebase Hosting** (`firebase.json`): `"cleanUrls": true` and the rewrite `{ "source": "**", "destination": "/_shell.html" }`. Firebase serves an existing file before any rewrite.
98
+ - **Vercel, Git deploy** (`vercel.json`): `"cleanUrls": true` and the rewrite `{ "source": "/(.*)", "destination": "/_shell" }` (with `cleanUrls`, destinations have no extension).
99
+ - **Vercel, `dndev deploy`** (Build Output API): each `<path>.html` gets an `overrides` entry (`{ "path": "<path>" }`), the fallback route is `/_shell`.
100
+
101
+ An app whose own config lacks `cleanUrls` never serves the prerendered pages at their URLs (`/about` finds no file `about`), and one still rewriting to `/index.html` serves the home page's head (canonical included) on every other URL: update its `firebase.json` / `vercel.json` to the lines above.
102
+
103
+ **Not found (Vite):** a client-rendered app answers every URL with HTTP 200, so the not-found state carries `<meta name="robots" content="noindex">`: the framework 404 (the `*` route) and a record page while the record its URL names is not found (`useCrudDoc` reporting `notFound` for the route's declared entity and `:param` value; a secondary read on the page never does, crud `CRUD.md`). Next serves a real 404 instead (`notFound()`, not-found pages) and adds no robots tag.
63
104
 
64
105
  ---
65
106
 
66
107
  ## Next.js: Server Rendering
67
108
 
68
- **Automatic.** Each page's `generateMetadata()` runs server-side.
109
+ **Automatic.** The generated layout renders the app's providers, which render AutoMetaTags (a client component) above the page. Both are server-rendered (SSR is the default; `appConfig.ssr: false` renders them in the browser only), and React 19 hoists every `<title>`, `<meta>` and `<link>` into `<head>`.
110
+
111
+ **React 19 does not dedupe head tags** (Helmet does, on Vite): two sources of a `<title>` ship two titles. One owner per tag:
112
+
113
+ | Route | Page identity (title, description, Open Graph, Twitter, robots, JSON-LD) | Always AutoMetaTags |
114
+ |-------|------|------|
115
+ | Static (`/about`), dynamic without server metadata | AutoMetaTags (PageMeta + i18n) | canonical, `og:url`, `og:site_name`, `hreflang`, BreadcrumbList / WebSite / Organization JSON-LD |
116
+ | Entity page (`/produits/:slug`, see below) | The generated page: `generateMetadata` + JSON-LD from the record (AutoMetaTags emits none) | same, except the BreadcrumbList: the page renders it (record title last) |
117
+ | Page module exporting `generateMetadata` | That `generateMetadata` (AutoMetaTags emits none) | same |
118
+ | Blog post (`blog` namespace, dynamic route) | The generated page's `generateMetadata` (per-post title, description, Open Graph) | same |
119
+
120
+ The route generator writes the routes of the last three rows into the route manifest (`routes.manifest.serverMetadataPaths`); AutoMetaTags skips the identity exactly there. Entity pages are also in `routes.manifest.recordBreadcrumbPaths`: AutoMetaTags emits no BreadcrumbList there.
69
121
 
70
- **Static pages:** Meta resolved at build time from `metadata-manifest.json`.
71
- **Dynamic pages:** Use `generateMetadata()` with `fetch()` or client-side `<Seo>`.
122
+ - **Route of a URL** (both platforms): exact path, then `:param` patterns (most specific), then catch-alls: a `/docs/*` route's PageMeta applies to every URL under `/docs` (longest prefix wins).
123
+ - **Site-level metadata:** `export const metadata` in `src/app/AppDocument.tsx` (`metadataBase`), re-exported by the generated root layout. No page titles there.
124
+
125
+ ### Entity pages: identity from the record, no app code
126
+
127
+ A public single-param route whose page declares its entity in PageMeta (indexable, not `auth`) gets its head from the server; its records are also the sitemap's. The page renders no SEO component.
128
+
129
+ ```tsx
130
+ // src/pages/products/ProductPage.tsx (the folder shapes the URL and breadcrumbs only)
131
+ import { productEntity } from 'entities';
132
+
133
+ export const meta: PageMeta = {
134
+ namespace: 'product',
135
+ route: '/produits/:slug',
136
+ entity: productEntity, // the defineEntity definition: collection 'products'
137
+ seo: { type: 'product' },
138
+ };
139
+ ```
140
+
141
+ - **Declaring the entity:** `entity` is the `defineEntity` definition imported from the app's `entities` package; the build resolves it to its `collection` (`meta.entity`). A string, an identifier not imported from `'entities'`, or a value that is not a `defineEntity` with a literal `collection` fails the build, and so does any other expression: `import * as entities from 'entities'` with `entity: entities.productEntity` (the build reads the meta statically; write `import { productEntity } from 'entities'`). A dynamic page without `entity` is a plain dynamic page: its own exported `generateMetadata` (Next), else `seo: { noindex: true }` (see Dynamic Pages: Per-URL SEO Required).
142
+
143
+ - **Read:** the generated `page.tsx` reads the record named by the URL (`<param> == value`, `status` not in `HIDDEN_STATUSES`) with the public server reader of `generateStaticParams` (signed-out visitor: RLS / Security Rules decide; `@donotdev/supabase` or `@donotdev/firebase`, any other provider fails the build). React `cache`: `generateMetadata` and the page share one read per request. The page's own client data reads are separate. `appConfig.prerenderRecords: false` stops the build-time prerender only: each URL still reads its record on its first request.
144
+ - **`generateMetadata`:** title `<record title> | <site name>` (absolute: no layout title template; site name = `appConfig.seo.siteName`, else `appConfig.app.name`), description, Open Graph (title, description, absolute image, `og:type`), Twitter card. Derived by `deriveEntitySeo` with the entity's `seo` option (see Entity-derived identity), text in the URL's language (entity namespace then `crud` translations, `@donotdev/core/rsc`). Canonical, `og:url` and `hreflang` stay with AutoMetaTags.
145
+ - **`og:type`:** PageMeta `seo.type` (`website` default, `article`, `product`). `product` also renders Product JSON-LD (`<script type="application/ld+json">`, from `buildProductJsonLd`) and `<meta property="og:type" content="product">` in the page (Next's metadata API has no `product` type).
146
+ - **BreadcrumbList JSON-LD:** rendered by the page (`buildBreadcrumbJsonLd`, shared with the Vite record pages): the site name, the URL's segments named as the visible breadcrumb names them (words title-cased), the record title last: the label the visible breadcrumb shows on the segment naming the record (`useRecordBreadcrumb`: the slug on `/produits/:slug`, the id on `/products/:id`). No record title: no BreadcrumbList.
147
+ - **Missing record** (unknown value, hidden status): `notFound()`. The response is HTTP 404 with the app's 404 page and Next's `noindex`; a page component's own not-found state is never served for such a URL.
148
+ - **Own `generateMetadata` wins:** a server page module (no `'use client'`) exporting `generateMetadata` replaces the generated metadata, JSON-LD and 404 (one source, no second title); it then calls `notFound()` itself.
149
+ - **Build fails** without the app's `entities` package, without a site name, or with a provider that has no server reader. Opt a route out with `seo: { noindex: true }` (also leaves the sitemap).
150
+ - The per-request tree (`dndev-session`) re-exports the same `generateMetadata`.
151
+
152
+ ### Other dynamic pages: Next's `generateMetadata`
153
+
154
+ A page module may export Next's own `generateMetadata` (standard Next API). The generated `page.tsx` re-exports it (and the per-request tree page too), and AutoMetaTags emits no identity on that route.
72
155
 
73
156
  ```tsx
74
- // Server-rendered metadata for dynamic route
75
- export async function generateMetadata({ params }): Promise<Metadata> {
76
- const product = await fetch(`/api/products/${params.id}`).then(r => r.json());
77
- return { title: product.name, description: product.description };
157
+ // src/pages/search/SearchPage.tsx: a server module (no 'use client')
158
+ import type { Metadata } from 'next';
159
+
160
+ export const meta: PageMeta = { route: '/recherche/:q' };
161
+
162
+ export async function generateMetadata({ params }: { params: Promise<{ q: string }> }): Promise<Metadata> {
163
+ const { q } = await params;
164
+ return { title: { absolute: `${q} | Shop` } };
165
+ }
166
+
167
+ export default function SearchPage() {
168
+ return <SearchResults />; // a 'use client' component
78
169
  }
79
170
  ```
80
171
 
172
+ - **`'use client'` page exporting `generateMetadata`:** the build fails (Next reads it only from server modules, the page would ship without metadata). Keep the page module a server component that renders the client UI.
173
+ - **Canonical / `hreflang`:** AutoMetaTags emits them; do not set `alternates` or `openGraph.url` (a second canonical).
174
+ - **Vite:** ignored (no server).
175
+
81
176
  ---
82
177
 
83
178
  ## Standard Use: i18n-First
@@ -127,16 +222,26 @@ export const meta: PageMeta = {
127
222
 
128
223
  ## Link-Preview Image
129
224
 
130
- The build generates `public/og-image.png` (1200x630, logo centered) from `public/logo.svg`, next to the favicon and PWA icons. Vite and Next.js both default `og:image` to it, as an absolute URL when `APP_URL` is set.
225
+ The build generates `public/og-image.png` (1200x630, logo centered) from `public/logo.svg`, next to the favicon and PWA icons. Vite and Next.js both default `og:image` to it (`appConfig.seo.defaultImage`, default `DEFAULT_OG_IMAGE`, `/og-image.png`), as an absolute URL when `APP_URL` is set. One default for every tag: AutoMetaTags, the Vite prerendered pages (static and record), the Next entity page metadata and `getMetadataForPath`.
131
226
 
132
227
  - **Replace it:** put your own `public/og-image.png`; an existing file is never overwritten.
133
228
  - **Per page:** `seo.image` in `PageMeta`, or `meta.image` in the namespace's translations.
134
- - **Dynamic pages:** `<Seo image={product.imageUrl} />`.
229
+ - **Entity pages (Next, Vite record pages):** the record's first image (`deriveEntitySeo`), else the site default.
230
+ - **Site-wide:** `appConfig.seo.defaultImage` (e.g. `'/og-image.jpg'`) replaces the default everywhere (build-written and runtime tags stay identical).
231
+ - **Not generated** without `public/logo.svg` or without `sharp` installed (the build log lists it as skipped): `og:image` then points to a missing `/og-image.png`. Add the file to `public/`.
135
232
 
136
233
  Use JPG or PNG: link-preview crawlers do not reliably render SVG.
137
234
 
138
235
  ---
139
236
 
237
+ ## Site Logo (JSON-LD)
238
+
239
+ The JSON-LD logo is always the app's `public/logo.svg` (`SITE_LOGO_PATH`, `@donotdev/core`), as an absolute URL: the Organization `logo` (home page, when `appConfig.app.links` is set) and the WebPage / Article `publisher.logo` (every page with an app URL). One path, no existence check or asset-manifest lookup at render, so the server render, the browser and the Vite prerendered pages write the same URL (no hydration mismatch). The generated PWA icons (`icon-*x*.png`) are never used for it.
240
+
241
+ - **Missing `public/logo.svg`:** the build warns (`logo.svg not found in public/`); the JSON-LD logo then points to a missing file, and no favicon, PWA icons or `og-image.png` are generated. Add `public/logo.svg`.
242
+
243
+ ---
244
+
140
245
  ## All SEO Options
141
246
 
142
247
  ```tsx
@@ -158,7 +263,8 @@ export const meta: PageMeta = {
158
263
 
159
264
  // Other
160
265
  keywords: ['blog', 'news'],
161
- noindex: true, // Hide from search engines
266
+ noindex: true, // Hide from search engines (noindex, nofollow)
267
+ noindex: false, // Indexable even when auth-only (default there: noindex)
162
268
  },
163
269
  };
164
270
  ```
@@ -169,60 +275,29 @@ export const meta: PageMeta = {
169
275
 
170
276
  Resolution order (highest to lowest):
171
277
 
172
- 1. **`<Seo>` component** - Runtime dynamic data (always wins)
173
- 2. **i18n `meta.fullTitle`** - Translated, language-aware
174
- 3. **`seo.fullTitle`** - Static fallback
175
- 4. **i18n `title`** - "Translated | SiteName"
176
- 5. **`seo.title`** - "Static | SiteName"
177
- 6. **SiteName only** - Default fallback
178
-
179
- ---
180
-
181
- ## Dynamic Data: `<Seo>` Component
182
-
183
- **Pattern:** For pages with runtime data (fetched content), use `<Seo>`.
278
+ On Next routes with server metadata (entity pages, a page's own `generateMetadata`, blog posts) that metadata is the only identity. Everywhere else:
184
279
 
185
- ```tsx
186
- import { Seo } from '@donotdev/ui';
280
+ 1. **`seo.fullTitle`** - Exact title, set on the page
281
+ 2. **i18n `meta.fullTitle`** - Translated, language-aware (the page's own namespace)
282
+ 3. **`seo.title`** - "Static | SiteName" (`seo.title: null`: SiteName only)
283
+ 4. **i18n `title`** - "Translated | SiteName" (the page's own namespace)
284
+ 5. **SiteName only** - Default fallback
187
285
 
188
- export const meta: PageMeta = {
189
- namespace: 'apartments',
190
- route: { params: ['id'] },
191
- };
286
+ What the page sets in PageMeta wins over its translations, for the full title as for the title.
192
287
 
193
- export default function ApartmentPage() {
194
- const { id } = useParams<{ id: string }>();
195
- const { data: apartment } = useApartment(id);
196
-
197
- if (!apartment) return <Loading />;
198
-
199
- return (
200
- <>
201
- <Seo
202
- fullTitle={`${apartment.reference} - ${apartment.rent} | SiteName`}
203
- description={apartment.description}
204
- image={apartment.photos[0]}
205
- type="product"
206
- />
207
- <ApartmentDetails data={apartment} />
208
- </>
209
- );
210
- }
211
- ```
288
+ **Page without a `namespace`:** it reads the site defaults, the namespace `appConfig.seo.defaultNamespace` (default `home`), for its description, image, type, keywords and author, never for its title: its title is its own `seo.fullTitle` / `seo.title`, else the site name. Another page's title (the home page's) never lands on it.
212
289
 
213
- **Works in SSR/prerender** - meta tags are in initial HTML.
290
+ (`routeSeo` in core `headTags.ts`, written once: AutoMetaTags, the Vite prerendered pages, llms.txt page labels (`routeTitle`, the same chain), and the Next metadata manifest of `getMetadataForPath`, which the plain-Node build reads from `config/utils/headTags.js`, generated from `headTags.ts` by `bun run bpr`.)
214
291
 
215
- ### Entity-derived: `<Seo entity data>`
292
+ ---
216
293
 
217
- ```tsx
218
- <Seo entity={apartmentEntity} data={apartment} type="product" />
219
- ```
294
+ ## Entity-derived identity
220
295
 
221
- `deriveEntitySeo` (`@donotdev/core`) builds the identity; explicit props win.
296
+ `deriveEntitySeo` (`@donotdev/core`) builds a record's identity, the same on the Next entity page metadata, llms.txt and the CRUD breadcrumb:
222
297
 
223
298
  - **title:** `listCardFields.title` texts, formatted exactly like the CRUD card (`formatFieldText`: select labels, numbers in the locale, `displayKey`, `displayValue`), joined with `titleSeparator`; empty fields dropped. No slot layout: first `text` field.
224
299
  - **description:** first long-text field with a value (textarea/richtext, HTML stripped), else the card subtitle texts then content texts (joined ` · `). Max 160 chars.
225
- - **JSON-LD (`type="product"`):** `offers` when a price/currency field is positive; `offers.availability` from the record `status`: `available` → `https://schema.org/InStock`, other statuses only when mapped (unmapped → no `availability`). Needs `status` in the record the page renders, so a guest-visible `status` field: the base `status` field is `visibility: 'admin'`, so guests (crawlers) get no `availability` unless the entity declares its own `status` with `visibility: 'guest'`. Availability that depends on private data (e.g. stock shown to professionals only) is not emitted: leave it unmapped.
300
+ - **JSON-LD (PageMeta `seo.type: 'product'`):** `offers` when a price/currency field is positive; `offers.availability` from the record `status`: `available` → `https://schema.org/InStock`, other statuses only when mapped (unmapped → no `availability`). Needs `status` in the record the public reader returns, so a guest-visible `status` field: the base `status` field is `visibility: 'admin'`, so guests (crawlers) get no `availability` unless the entity declares its own `status` with `visibility: 'guest'`. Availability that depends on private data (e.g. stock shown to professionals only) is not emitted: leave it unmapped.
226
301
  - **Overrides:** entity `seo` option.
227
302
 
228
303
  ```ts
@@ -240,92 +315,31 @@ defineEntity({
240
315
 
241
316
  ---
242
317
 
243
- ## Sitemap & llms.txt: One URL Set
244
-
245
- Both list the same pages, generated from `src/pages` - no app code:
246
-
247
- - **In:** public static routes, plus one URL per public record (`status` not in `HIDDEN_STATUSES`: any status except `draft`/`deleted`) of each single-param route's entity (`/produits/:slug` → `meta.entity` collection). Never a `:param` template.
248
- - **Out:** `auth.required` routes, `seo: { noindex: true }` routes and error routes (`/404`, `/not-found`, `/500`, `/error`).
249
- - **RSS:** `<link rel="alternate" type="application/rss+xml">` to `/rss.xml` is in the head only when the app has blog posts (`src/content/blog/*_en.md`), the condition under which the feed is generated (`routes.manifest.hasBlogFeed`).
250
- - **URLs:** absolute, from `seo.baseUrl` or `NEXT_PUBLIC_APP_URL` / `VITE_APP_URL`. A production build with a localhost URL fails.
251
- - **llms.txt labels (app default language):** page = namespace `title` → `seo.title` → namespace `meta.fullTitle` → `seo.fullTitle` (a static page with none fails the build); entity record = `deriveEntitySeo` title/description (same as `<Seo entity data>`); entity section = `namePlural` of its `entity-*` translations.
252
- - **Prerendered pages (Next):** the same records fill each entity page's `generateStaticParams` (`listStaticParams`, one route → collection decision `publicCollection`): every URL of the sitemap's dynamic routes is built at build time (`appConfig.prerenderRecords: false` to opt out).
253
- - **Reader (Next):** records are read on the server as a signed-out visitor, from the app's public env, never a privileged key: `@donotdev/supabase` (RLS decides) or `@donotdev/firebase` (`@donotdev/firebase/public`, Firestore Security Rules decide; they must allow the whole `status not-in` query). Any other provider fails the build when a route lists records.
254
- - **Next:** `src/app/sitemap.xml/route.next.ts` and `src/app/llms.txt/route.next.ts`, revalidated hourly (`appConfig.revalidate`: other lifetime in seconds, or `false` until the next deploy). Entity definitions come from the app's `entities` package.
255
- - **Vite:** written at build; static pages only (same as the Vite sitemap).
256
-
257
- ---
258
-
259
- ## `<Seo>` Props
260
-
261
- ```tsx
262
- <Seo
263
- // Title (pick one)
264
- title="Page Title" // "Page Title | SiteName"
265
- fullTitle="Exact Title" // "Exact Title"
266
-
267
- // Content
268
- description="Page description"
269
- image="/og-image.png"
270
- type="website" // 'website' | 'article' | 'product'
271
- keywords={['key1', 'key2']}
272
- noindex={false}
273
-
274
- // Article-specific
275
- publishDate="2024-01-15T00:00:00Z"
276
- modifiedDate="2024-01-20T00:00:00Z"
277
-
278
- // URL
279
- canonicalUrl="https://example.com/page"
280
- />
281
- ```
282
-
283
- ---
318
+ ## Robots: `noindex`, Never robots.txt
284
319
 
285
- ## Hook Alternative
320
+ Google's rule: robots.txt does not keep a page out of the index (a blocked URL linked elsewhere can still be indexed, without a description), and a `noindex` on a page robots.txt blocks is never read. So:
286
321
 
287
- ```tsx
288
- import { useSeo } from '@donotdev/ui';
289
-
290
- export default function ProductPage() {
291
- const { data: product } = useProduct(id);
292
-
293
- const SeoTags = useSeo(product ? {
294
- title: product.name,
295
- description: product.description,
296
- image: product.image,
297
- } : null);
298
-
299
- return (
300
- <>
301
- <SeoTags />
302
- <ProductDetails data={product} />
303
- </>
304
- );
305
- }
306
- ```
322
+ - **robots.txt** (generated, Vite and Next) disallows non-page paths only: `Disallow: /api`, and on Vite `Disallow: /_shell` (the SPA shell's own URL, `/_shell` and `/_shell.html`; the pages the hosting rewrites to it keep their URL and stay crawlable, so the shell carries no robots tag). Every page is crawlable, auth-only pages included. AI crawler groups (`appConfig.seo.aiCrawlers`) are separate.
323
+ - **Auth-only pages** (PageMeta `auth`): `<meta name="robots" content="noindex">` by default, from AutoMetaTags: in the server HTML on Next, in the browser on Vite (the Vite prerender skips auth pages). Out of the sitemap and llms.txt.
324
+ - **Opt back in:** `seo: { noindex: false }` (the page stays out of the sitemap). `seo: { noindex: true }` on any page: `noindex, nofollow`, out of the sitemap and llms.txt.
325
+ - **Next routes with server metadata** (entity pages, a page's own `generateMetadata`, blog posts): that metadata owns `robots`. `getMetadataForPath` (`@donotdev/core/next`) applies the same rule (`{ index: false }` on auth-only pages).
307
326
 
308
327
  ---
309
328
 
310
- ## Next.js: Manual `generateMetadata`
311
-
312
- For advanced cases, override in the page file:
313
-
314
- ```tsx
315
- // src/app/products/[id]/page.tsx (manual, not generated)
316
- import type { Metadata } from 'next';
329
+ ## Sitemap & llms.txt: One URL Set
317
330
 
318
- export async function generateMetadata({ params }): Promise<Metadata> {
319
- const product = await fetchProduct(params.id);
320
- return {
321
- title: `${product.name} | Store`,
322
- description: product.description,
323
- openGraph: { images: [product.image] },
324
- };
325
- }
326
- ```
331
+ Both list the same pages, generated from `src/pages` - no app code:
327
332
 
328
- **For static pages, framework handles this automatically.**
333
+ - **In:** public static routes, plus one URL per public record (`status` not in `HIDDEN_STATUSES`: any status except `draft`/`deleted`) of each single-param route whose page declares its entity (`/produits/:slug`, `entity: productEntity` → collection `products`). Never a `:param` template.
334
+ - **Out:** `auth.required` routes, `seo: { noindex: true }` routes, error routes (`/404`, `/not-found`, `/500`, `/error`) and catch-all routes (`/docs/*`: no URL list to expand them from).
335
+ - **RSS:** `<link rel="alternate" type="application/rss+xml">` to `/rss.xml` is in the head only when the app has blog posts (`src/content/blog/*_en.md`), the condition under which the feed is generated (`routes.manifest.hasBlogFeed`).
336
+ - **URLs:** absolute, from `seo.baseUrl` or `NEXT_PUBLIC_APP_URL` / `VITE_APP_URL`. **Deploy vs local build.** A deploy build (`dndev deploy`, which sets `DNDEV_DEPLOY=1`; a Vercel build, `VERCEL=1`; CI, `CI` set and not `false`) fails on a missing or local URL. A local build never fails because of the URL: it publishes the URL it has, localhost included, with one warning line. Without a usable URL, a local Vite build skips what needs one (sitemap.xml, llms.txt, robots.txt, rss.xml, canonical URLs, record pages: one warning line), and a local Next build uses `http://localhost:$PORT` (`next start`'s port, 3000 by default; `isDeployBuild` / `publishedBaseUrl` in core `config/utils/SEOGenerator.js`).
337
+ - **llms.txt labels (app default language):** page = its own title, without ` | SiteName` (`routeTitle` `pageTitle`, the Priority Chain's: `seo.title`, else the namespace `title`; a page without a `namespace`: its `seo.title` only); without one, its full title (`seo.fullTitle`, i18n `meta.fullTitle`), else the site name. A page without a title is listed under the site name on Vite and Next alike, never fails the build nor drops llms.txt; page description = `seo.description` → namespace `description`; entity record = `deriveEntitySeo` title/description (same as the entity page metadata), the site name for a record without a title (its page's title then); entity section = `namePlural` of its `entity-*` translations.
338
+ - **Prerendered pages (Next):** the same records fill each entity page's `generateStaticParams` and resolve its metadata (any other URL of the route is a 404) (`listStaticParams`, one route → collection decision `publicCollection`): every URL of the sitemap's dynamic routes is built at build time (`appConfig.prerenderRecords: false` to opt out).
339
+ - **Reader (Next):** records are read on the server as a signed-out visitor, from the app's public env, never a privileged key: `@donotdev/supabase` (`SupabasePublicReader` from `@donotdev/supabase/server`, RLS decides) or `@donotdev/firebase` (`FirestorePublicReader` from `@donotdev/firebase/public`, Firestore Security Rules decide; they must allow the whole `status not-in` query). Any other provider fails the build when a route lists records.
340
+ - **Read schema (Next and Vite):** every record read (sitemap, llms.txt, entity pages, Vite record pages) passes the entity's read schema (`entityReadSchemas`: `createSchemas(entity).get` per collection), so records keep the entity's field names (`availability_date` stays `availability_date`). The public reader filters nothing: it returns everything the database returns to a signed-out visitor (`SupabasePublicReader`: `select=*`; `FirestorePublicReader`: documents as stored, not validated), whatever a field's `visibility` (`status` and `updatedAt` feed availability and `lastmod`). RLS / Security Rules decide what is public; the derivations output only their own fields.
341
+ - **Next:** `src/app/sitemap.xml/route.next.ts` and `src/app/llms.txt/route.next.ts`, revalidated hourly (`appConfig.revalidate`: other lifetime in seconds, or `false` until the next deploy). Entity definitions and their read schemas come from the app's `entities` package, imported only when the app has entity routes; an entity route in an app without one fails the build (`[dndev-routes] <path> lists published "<collection>" records, read with their entity definition's read schema, but the app does not depend on an `entities` package ...`), the sitemap route included. A file the build fails to write (Next: robots.txt, rss.xml, seo-manifest.json, the sitemap.xml / llms.txt routes, llms-full.txt; Vite SEO plugin: robots.txt, rss.xml, seo-manifest.json, llms-full.txt, `_redirects`) fails a deploy build (`[dndev-seo] <files> not written: <cause>`) and is one warning line on a local build, the other files still written (`seoStep` in core `config/utils/SEOGenerator.js`, the URL check's rule); a build error (misconfigured app) fails every build.
342
+ - **Vite:** `dist/sitemap.xml` and `dist/llms.txt` written after the bundle with the Next builders (`buildSitemap`, `buildLlmsTxt`) over the same routes: every language URL with its alternates, records included (one read, shared with the record pages, same reader and env as Entity pages (Vite)). A record published later is listed by the next build.
329
343
 
330
344
  ---
331
345
 
@@ -334,7 +348,8 @@ export async function generateMetadata({ params }): Promise<Metadata> {
334
348
  - [ ] Set `namespace` in PageMeta for i18n-driven SEO
335
349
  - [ ] Add `title`, `description`, `meta` to translation files
336
350
  - [ ] Use `seo.fullTitle` to escape "Page | App" format
337
- - [ ] Use `<Seo>` for pages with dynamic/fetched data
351
+ - [ ] Entity pages (Next and Vite): nothing to add; set PageMeta `seo.type` (`product`, `article`) and the entity's `seo` option when the card text is not the right title. Vite: the public reader's env at build (see Entity pages (Vite))
352
+ - [ ] Other dynamic pages (Next): export `generateMetadata` from a server page module
338
353
  - [ ] Verify meta tags: View Source or browser DevTools
339
354
 
340
355
  ---
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@donotdev/ui",
3
- "version": "0.3.2",
3
+ "version": "0.3.3",
4
4
  "type": "module",
5
5
  "private": false,
6
6
  "license": "MIT",
@@ -67,13 +67,13 @@
67
67
  "@tanstack/react-query-next-experimental": "5.107.1"
68
68
  },
69
69
  "peerDependencies": {
70
- "@donotdev/ai": "^0.3.1",
71
- "@donotdev/auth": "^0.3.1",
72
- "@donotdev/billing": "^0.3.1",
73
- "@donotdev/components": "^0.3.2",
74
- "@donotdev/core": "^0.3.1",
75
- "@donotdev/crud": "^0.3.1",
76
- "@donotdev/oauth": "^0.3.1",
70
+ "@donotdev/ai": "^0.3.2",
71
+ "@donotdev/auth": "^0.3.2",
72
+ "@donotdev/billing": "^0.3.2",
73
+ "@donotdev/components": "^0.3.3",
74
+ "@donotdev/core": "^0.3.2",
75
+ "@donotdev/crud": "^0.3.2",
76
+ "@donotdev/oauth": "^0.3.2",
77
77
  "@hookform/resolvers": "^5.9.2",
78
78
  "lucide-react": "^0.575.0",
79
79
  "react": "^19.3.1",
@@ -1,54 +0,0 @@
1
- /**
2
- * @fileoverview SEO fields from a namespace's `meta` translations
3
- * @description Reads `<ns>:meta.*` key by key, as the i18n convention requires:
4
- * `useTranslation` returns strings only, never objects or arrays.
5
- *
6
- * @version 0.2.2
7
- * @since 0.2.2
8
- * @author AMBROISE PARK Consulting
9
- */
10
- import type { TFunction } from 'i18next';
11
- /**
12
- * Resolves a title or description: explicit value, else its translation.
13
- *
14
- * @param seoValue - `null` omits the field, a string is used as is, `undefined` looks up the translation
15
- * @param translationKey - Namespaced key, e.g. `home:description`
16
- * @param t - Translation function loaded with the key's namespace
17
- * @returns The resolved text, or undefined when omitted or not translated
18
- *
19
- * @version 0.2.2
20
- * @since 0.2.2
21
- * @author AMBROISE PARK Consulting
22
- */
23
- export declare function resolveSeoField(seoValue: string | null | undefined, translationKey: string, t: TFunction): string | undefined;
24
- /**
25
- * SEO fields a namespace can define under `meta`.
26
- *
27
- * @version 0.2.2
28
- * @since 0.2.2
29
- * @author AMBROISE PARK Consulting
30
- */
31
- export interface I18nSeoMeta {
32
- fullTitle?: string;
33
- image?: string;
34
- type?: string;
35
- keywords?: string[];
36
- author?: string;
37
- }
38
- /**
39
- * Reads the SEO fields of a namespace from its translations.
40
- *
41
- * @param t - Translation function loaded with `ns`
42
- * @param ns - Namespace holding the `meta` object
43
- * @returns The defined fields; a missing or empty field is undefined
44
- *
45
- * @example
46
- * // JSON: { "meta": { "image": "/og.png", "keywords": ["a", "b"] } }
47
- * readI18nSeoMeta(t, 'home'); // { image: '/og.png', keywords: ['a', 'b'] }
48
- *
49
- * @version 0.2.2
50
- * @since 0.2.2
51
- * @author AMBROISE PARK Consulting
52
- */
53
- export declare function readI18nSeoMeta(t: TFunction, ns: string): I18nSeoMeta;
54
- //# sourceMappingURL=i18nSeoMeta.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"i18nSeoMeta.d.ts","sourceRoot":"","sources":["../../../../src/internal/layout/components/i18nSeoMeta.ts"],"names":[],"mappings":"AAEA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAUzC;;;;;;;;;;;GAWG;AACH,wBAAgB,eAAe,CAC7B,QAAQ,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,EACnC,cAAc,EAAE,MAAM,EACtB,CAAC,EAAE,SAAS,GACX,MAAM,GAAG,SAAS,CAIpB;AAED;;;;;;GAMG;AACH,MAAM,WAAW,WAAW;IAC1B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;IACpB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,eAAe,CAAC,CAAC,EAAE,SAAS,EAAE,EAAE,EAAE,MAAM,GAAG,WAAW,CAmBrE"}
@@ -1 +0,0 @@
1
- import{translateArray as d}from"@donotdev/core";var s=20,u={defaultValue:""};function f(n,t,e){if(n!==null)return n!==void 0?n:e(t,u)||void 0}function l(n,t){let e=(i=>n(i,u)),r=i=>e(`${t}:meta.${i}`)||void 0,o=d(e,`${t}:meta.keywords`,s);return{fullTitle:r("fullTitle"),image:r("image"),type:r("type"),keywords:o.length>0?o:void 0,author:r("author")}}export{l as readI18nSeoMeta,f as resolveSeoField};