- Translate to English every doc the code branches did not touch: AGENT.md, developer guide, vibe, CHANGELOG, docs index, module pages, all skills except ipal-seo-check (14 pages follow after the security/SEO merge). Placeholder marker is now [TO FILL: …]; skill resources renamed to section-code.md / nav-code.md. AGENT.md and the ipal-skills pointer block say the docs are in English. - docs/seeding.md: create-only, natural keys, never delete, no users or secrets, empty-field globals, fallbackLocale: false, dry run, backup and restore, production update guard, seeds vs migrations, Coolify Terminal. Seed templates gain --dry-run, the SEED_UPDATE production guard (IPAL_SEED_ALLOW_PROD_UPDATE), skip of edited records and a summary. "Seeding on production" rule block in AGENT.md. - Coolify is the single deployment path (deployment, env, developer guide, ipal-setup): build vs runtime env, migrations on container start (prodMigrations), health check and rolling updates, rollback, backups and restore, DNS/Let's Encrypt/CAA. R2: custom domain needs a Cloudflare zone; default is media served by the app (R2_PUBLIC_URL empty). - docsConsistency: no Polish prose outside code/quoted data (pending pages listed); IPAL_* names may also be read by shipped skill templates. Co-Authored-By: Claude Opus 5.5 <[email protected]>
85 lines
3.4 KiB
Markdown
85 lines
3.4 KiB
Markdown
# slug
|
|
|
|
A slug field generated automatically from the title, per locale.
|
|
|
|
> **The plugin ALREADY has this — don't write your own auto-slug.** A common mistake: the project
|
|
> adds a manual field `{ name: 'slug', type: 'text' }` and makes the editor type the
|
|
> slug, or writes its own normalizing hook. Not needed — `buildSlugField`
|
|
> does it better: auto-generation when empty, never overwrites a manual one, per-locale,
|
|
> PL diacritics → ASCII. If a collection has a manual slug, REPLACE it with
|
|
> `buildSlugField({ from: 'title' })`.
|
|
|
|
## Usage (client collection)
|
|
|
|
```ts
|
|
import { buildSlugField } from '@intecion/ipal-kit'
|
|
|
|
export const Pages: CollectionConfig = {
|
|
slug: 'pages',
|
|
fields: [
|
|
{ name: 'title', type: 'text', required: true, localized: true },
|
|
buildSlugField({ from: 'title' }),
|
|
// ...
|
|
],
|
|
}
|
|
```
|
|
|
|
Returns a ready field: `slug`, text, `localized` (default), `required` (default),
|
|
`index: true`, with a `beforeValidate` hook. It does **not** set `unique` — two documents can
|
|
have the same slug (routing takes the first); add uniqueness through `overrides`.
|
|
|
|
## Behavior
|
|
|
|
The slug is generated from the source field **only when it is empty**. A manual entry stays —
|
|
also after the title changes — but it is **normalized by `toSlug`** (lowercase,
|
|
diacritics → ASCII, characters outside `[a-z0-9-]` removed). Changing the URL of a published
|
|
page breaks links, so the plugin never does it by itself.
|
|
|
|
**Note — multi-level slugs:** `toSlug` removes `/`, so `uslugi/biznesowe` typed
|
|
into this field is saved as `uslugibiznesowe` (`src/modules/slug/buildSlugField.ts`).
|
|
Routing (`resolveRoute`, `generateStaticParams`) handles slugs with `/`, but you cannot
|
|
enter them through `buildSlugField` — you need your own field/hook (`overrides.hooks`).
|
|
|
|
Diacritics go through `slugify`: "Strona główna" → `strona-glowna`.
|
|
|
|
## Per locale
|
|
|
|
The slug is localized — each language has its own. Editing in PL sets
|
|
`slug.pl`, in EN `slug.en`.
|
|
|
|
**Consequence:** the slug is generated only for the locale in which the title was filled in.
|
|
Create a page in Polish, switch the front end to `/en/…` — 404, because `slug.en`
|
|
is empty. Switch the locale in the admin panel and type the title in English.
|
|
|
|
It is the same slug map that hreflang alternates (see seo.md) and the
|
|
language switcher (see i18n.md) are built from.
|
|
|
|
## Options
|
|
|
|
```ts
|
|
buildSlugField({
|
|
from: 'title', // source field (default 'title')
|
|
name: 'slug', // field name (default 'slug')
|
|
required: true, // default true
|
|
localized: true, // default true
|
|
overrides: {}, // Partial<TextField> — spread LAST onto the field
|
|
})
|
|
```
|
|
|
|
`overrides` overrides everything, including `hooks` (passing `overrides.hooks` removes
|
|
auto-generation unless you add it back yourself) and `admin` (`admin` is merged with the description).
|
|
|
|
## Helpers
|
|
|
|
```ts
|
|
import { toSlug } from '@intecion/ipal-kit'
|
|
|
|
toSlug('Strona główna') // 'strona-glowna'
|
|
```
|
|
|
|
## Turn off, override, extend
|
|
|
|
- The module has no option in `ipalKit()` — you add the field yourself; turning off = a plain `text` field instead of `buildSlugField`.
|
|
- Override: `name`, `from`, `required`, `localized`, `overrides` (e.g. `{ unique: true }`, your own `admin`, your own `hooks`).
|
|
- The normalization rules (`slugify` with `lower`, `strict`, `trim`) are currently fixed — a different format needs your own hook; you can use `toSlug` as a building block.
|