Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to change slug on edit #308

Closed
junnotantra opened this issue May 18, 2019 · 10 comments
Closed

How to change slug on edit #308

junnotantra opened this issue May 18, 2019 · 10 comments

Comments

@junnotantra
Copy link

Hi, I'm able to customize my slug by overriding String()

// String defines how an Article is printed. Update it using more descriptive
// fields from the Article struct type
func (a *Article) String() string {
	return a.Title
}

When I make an item with title what the slug, the slug will be what-the-slug

But this only happen when the item was first created. When I edit the title to be what the slug is this, I want the slug to change to what-the-slug-is-this instead of keeping the original slug what-the-slug. Is this possible?

I've tried to update the slug on BeforeSave() but changing the slug there not work as expected.

Btw, thanks for the awesome CMS 👍

@logicalphase
Copy link

logicalphase commented May 18, 2019 via email

@junnotantra
Copy link
Author

Just a thought, but might want the slug edit to be implicit by adding a editable field for edit view only.

it would be wonderful to have this feature

@logicalphase
Copy link

When I get a little time this weekend I'll look at doing a PR for that. Something similar to how WordPress managed permalink changes.

@junnotantra
Copy link
Author

Btw, just tried a stupid thing. I edited the DOM from my browser inspector.
Removed the disabled="true" from

<input value="what-the-slug-is-this" label="URL Slug" type="text" disabled="true" placeholder="Will be set automatically" name="slug">

Then save, it works. 👍

Not sure if it's expected or not

@logicalphase
Copy link

logicalphase commented May 18, 2019 via email

@junnotantra
Copy link
Author

Found out, it doesn't work as expected.
I cannot retrieve the item using the forcefully edited slug.
/api/content?slug=what-the-slug-is-this returns error

while I can retrieve the item using the original slug
/api/content?slug=what-the-slug
returns

{
	"data": [
		{
			"uuid": "eeb0b6ed-ddda-4738-adae-7a3c8ef5d653",
			"id": 4,
			"slug": "what-the-slug-is-this",
			"timestamp": 1558083709000,
			"updated": 1558162849040,
			"title": "what the slug is this",
			"content": "update pls<br>",
		}
	]
}

still need help to update slug and make the item retrievable by the edited slug
thanks in advance

@logicalphase
Copy link

Will do and update here.

@olliephillips
Copy link
Contributor

olliephillips commented May 18, 2019

if you override the item's implementation of sluggable you can get very close I think, the catch being that you need to save twice, which is less than ideal.

// provide custom slug here
func (a *Article) ItemSlug() string {
	return strings.Replace(a.Title, " ", "-", -1)
}

@junnotantra
Copy link
Author

Hi guys, I've opened a PR for this issue. If you have time, please take a look at #309
Thank you

@olliephillips
Copy link
Contributor

#309 just got merged into ponzu-dev. @junnotantra thanks on behalf of the Ponzu community for your work on that, it will be useful for a good number of users. Closing this issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants