-
|
I am trying to control the output of the slug (instead of the title) by following this option: `... # whatever collection
I got it from here - Decap CMS issue 445. But seems like the slug is just some numbers like this Is there any way to control the slug of the post? Thanks in advance. |
Beta Was this translation helpful? Give feedback.
Replies: 5 comments 2 replies
-
|
The example doesn’t work in Sveltia CMS because it relies on a custom widget, which is not yet supported in Sveltia. You can instead use the standard string widget to enter a slug manually: collections:
- name: posts
label: Posts
slug: '{{field.slug}}'
fields:
- name: title
label: Title
widget: string
- name: slug
label: Slug
widget: string # instead of slugOr, simply use a random ID as a slug: collections:
- name: posts
label: Posts
slug: '{{uuid_short}}' |
Beta Was this translation helpful? Give feedback.
-
|
Many thanks. I think I ask the wrong question. Sorry for that. What I am trying to do is generate a customs filename for each file. Right now, the setting you provide generate file with random numbers e.g. a222cd34441.md, f06bf1cd3691.md. What I want to do is control the file name e.g. file-name-1.md and second-post.md so on. You see, I will have lost of file generated. If I can control the file name, it will make my life easier to manage the file by just looking at the file name. I hope the question is now clear. Sorry for taking time off you. Also, this is not actually an issue, this should be moved to discussion. Thank you. |
Beta Was this translation helpful? Give feedback.
-
|
Sorry, I made a mistake in the example. (Actually, the example in the Decap CMS thread is wrong.) slug: '{{field.slug}}'has to be slug: '{{fields.slug}}'Add “s” after “field”. (Documentation) Does it work? Sveltia CMS falls back to a random ID when the configuration is wrong, the field is not found, or a slug cannot be determined. 😅 |
Beta Was this translation helpful? Give feedback.
-
|
Now it works 👍 |
Beta Was this translation helpful? Give feedback.
-
|
Would it be possible to specify a fallback field for the slug? When editing old post created pre-CMS, it likely won't have a slug (since it defaults to title, at least with Hugo). The editor then will present an empty slug string, so the user needs to manually backfill. But on secound thought, it might be better to edit the old posts retroactively to ensure a slug is present. Otherwise if the slug logic of Hugo an the CMS is different, the slugs can end up different, leading to url change. (I mean, edit manually - so this is not a task for the CMS). |
Beta Was this translation helpful? Give feedback.
Sorry, I made a mistake in the example. (Actually, the example in the Decap CMS thread is wrong.)
has to be
Add “s” after “field”. (Documentation)
Does it work?
Sveltia CMS falls back to a random ID when the configuration is wrong, the field is not found, or a slug cannot be determined. 😅