Repository navigation
Replies: 1 comment 1 reply
|
Makes sense. This ties to my point in #4359 My own use case is translating non-English titles into URL-friendly slugs using AI. It is too much of a hassle for end-users to do this on their own. IMO the best approach is to let plugins declare an ability to generate slugs, similar to what we do with emails. The question is what the design should look like. Say, if a site owner wants to hook different plugins based on collection or different criteria, or if a plugin has multiple "presets" a user can choose from to decide how slugs should be generated. |
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Problem
There is no supported way to control how a new entry's slug is generated. EmDash always derives it from the title, and neither the server, the admin, nor plugins can change that.
handleContentCreateusesbody.slugif given, otherwisegenerateUniqueSlug(collection, <slugified title>). There is no extension point.slugify(title)while the slug is untouched) and submits it, so server-side logic would be bypassed anyway.content:beforeSavereceives only field data, not the slug.ctx.content.update(collection, id, data)callsupdateDraftAware(collection, id, { data })without forwardingslug, even thoughupdateDraftAwarealready supportsinput.slug(staged as_slug).editorActions[].draft.patchcan only select schema fields.I'd like a way for a site to decide a new entry's slug with its own rule (for example a hook or collection-level option that runs when an entry is created without an explicit slug), or, at minimum, for plugins to be able to set the slug of an existing entry.
Use case
A Chinese-language news site migrating to EmDash. Its existing URLs use short random IDs (e.g.
/archives/HOMtdtJ3, always 8 alphanumeric characters), and we'd like new posts to follow the same scheme.With the default behavior, a post with a CJK title gets a long CJK slug, which we don't want in URLs (they get shared on social platforms and copied into other systems). Editors would otherwise have to hand-write a random ID for every new post.
The same need applies to any site with its own ID scheme: date-based, sequential, ULID/nanoid, or an ID shared with another system.
Current workarounds
POST /_emdash/api/content/posts) to swap in a generated slug. This works but depends on the admin's request shape and bypasses EmDash, so I'm not comfortable with it.ctx.content.updatedoesn't forward it. If it could, a plugin could at least add aneditorActionstoolbar button ("Generate slug") for saved entries, which would be an acceptable second-best.Your involvement
All reactions