sveltia / sveltia-cms

Alternative to Netlify/Decap CMS. Fast, lightweight, Git-based headless CMS. Modern UX, first-class i18n support, open source & free. Made with Svelte.
MIT License
863 stars 43 forks source link

slug management #95

Closed sardarms closed 8 months ago

sardarms commented 8 months ago

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.

kyoshino commented 8 months ago

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 slug

Or, simply use a random ID as a slug:

collections:
  - name: posts
    label: Posts
    slug: '{{uuid_short}}'
sardarms commented 8 months ago

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.

kyoshino commented 8 months ago

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 or a slug cannot be determined. 😅