Files
ipal-kit/docs/slug.md
T
Radosław SmolińskiandClaude Fable 5.2 b91984fbcd IAPL rename: docs, agent guide, skills, reference site and starter on the new names; changelog draft
- docs, AGENT.md, the 16 skills, PROGRAMISTA and README use the preferred names (scripted, same list of forms);
  past CHANGELOG entries and the proposals in docs/dev are not rewritten
- AGENT.md: 'Names: IAPL and ipal-kit' — old name, new name, state in 1.x; what is not renamed; storageNames
- iapl-upgrade '→ 1.17.0', PROGRAMISTA §6 item 72, CHANGELOG 1.17.0 (draft): nothing required
- env.md, doctor.md (legacy-names, storage-names), stats.md, security.md, project-starter.md, iapl-reference, iapl-setup
- skill scripts read ipal-audit-skip and IPAL_IP_HEADER too; audit rule ids stay what they were
- reference site: iapl(), iapl-doctor.json, iapl-* skills, storageNames: 'iapl'; INDEX.md regenerated

Co-Authored-By: Claude Fable 5.2 <[email protected]>
2026-11-25 17:36:09 +01:00

3.4 KiB

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)

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

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

import { toSlug } from '@intecion/ipal-kit'

toSlug('Strona główna')   // 'strona-glowna'

Turn off, override, extend

  • The module has no option in iapl() — 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.