Slug inputs in the site editor now filter as you type via slugify.js (built on the transliteration npm package: unicode incl. asian scripts folds to ASCII, spaces become hyphens, anything outside [a-z0-9-] is dropped) instead of erroring on commit. A new page left with an empty slug gets one derived from its title. Server-side, _check_reserved additionally rejects reserved root file names (robots.txt, ads.txt, sitemap.xml, openapi.json, favicon.ico, site.webmanifest) with a human-readable reason, which the editor surfaces in its error line so the row can be edited and committed again; those URLs are also never looked up as content when serving.
11 lines
468 B
JavaScript
11 lines
468 B
JavaScript
// Slugs are URL path segments: lowercase ASCII letters, digits, hyphens.
|
|
// The transliteration package folds unicode (incl. asian scripts) to
|
|
// ASCII and spaces to hyphens; we then drop everything outside the slug
|
|
// charset (including the reserved leading "_"/".", slashes, backslashes,
|
|
// dots).
|
|
import { slugify as transliterate } from 'transliteration'
|
|
|
|
export function slugify(s) {
|
|
return transliterate(s).replace(/[^a-z0-9-]/g, '').replace(/-{2,}/g, '-')
|
|
}
|