Voyager: URL Slug lost character generate from title

Created on 12 Sep 2017  ·  15Comments  ·  Source: the-control-group/voyager

  • Laravel Version: 5.5
  • Voyager Version: dev
  • PHP Version: 7.1.8
  • Database Driver & Version: MySQL

Description:

I check on dev branches of Voyager, this issues still do not fix at this time.
It affects to SEO result because URL Friendly.

I insert title text like: Mời các bạn tối nay đến xem livestream “iPhone X”.

URL Slug auto generate like: m-i-cac-b-n-t-i-nay-n-xem-livestream-iphone-x-

See image example at (image is small, please click easy to view):
screenshot_20170912_121754

I don't know why Voyager has this issues.

I tried to create a new Laravel app, and using function str_slug('Mời các bạn tối nay đến xem livestream Iphone X', '-').

It generates URL Slug like:

moi-cac-ban-toi-nay-den-xem-livestream-iphone-x.

Can see example at:
screenshot_20170912_123059

How to fix this?

I can create a commit, but I don't know structure code at Voyager. I was read the file:

https://github.com/the-control-group/voyager/blob/54f1fb5bd1fcd054c4a2b320de1c8cccbce79bf9/src/Http/Controllers/Controller.php#L25

but can't find any method to find more information.

bug

Most helpful comment

Hello!
Sorry to all Vietnamese people, will take a look on this soon.
Thank you.

All 15 comments

I view code & see plugin slugify.js, you can try this
capture

@nguyentrongthanh seem slugify.js library is written by @akazorg .

I checked on my page and I detect it existed.

screenshot_20170912_140955

Why not using function str_slug in Laravel? I think it resolves the problem at the first time.

I make a pull request for this problem.

I was tested on my project and it's working.

slug working on js, maybe for UX but not for vietnammese :D

Hello!
Sorry to all Vietnamese people, will take a look on this soon.
Thank you.

@vanloc0301: even updated slugify, slug still hasn't changed, right?

@nguyentrongthanh No. It's updated slug and saves into database success.

You can test again.

I close this issue because my pull request is merged onto master branch.

@akazorg slugify till generates slugs which lost chars. I think, toLowerCase method in slug function must be applied after chars are replaced. https://github.com/the-control-group/voyager/blob/ea1dae48df8f6a111a01b7997897200eeed1eb1c/resources/assets/js/slugify.js#L89

I have changed the function as below:

slug: function(str) {
                str = str
                    .toString();
                var _slug = '',
                    _sep = this.settings.separator;

                // Replace Char Map
                //
                for (var i=0, l=str.length ; i<l ; i++) {
                    _slug += (this.chars[str.charAt(i)])
                             ? this.chars[str.charAt(i)]
                             : str.charAt(i);
                }

                str = _slug.toLowerCase()
                    .replace(/^\s+|\s+$/g, '')      // Trim
                    .replace(/[^-\u0600-۾\w\d\$\*\(\)\'\!\_]/g, _sep)   // Remove invalid chars
                    .replace(/\s+/g, _sep)          // Replace spaces with separator
                    .replace(/\-\-+/g, _sep);       // Replace multiple separators with single
                return str;
            },

Hi @sylmz, thanks for your message.
What language are you using?
Have you tried moving .toLowerCase() after and confirm this?
Thanks.

@akazorg, I am using Turkish language. In fact, slugify generates slug as ‘i-stanbul’ for ‘İstanbul’ string. After changes, it works fine.

I will change that. Thanks for reporting the bug.

Hi,
Laravel lastest stable voyager too
Conditions générales d'utilisation becomes conditions-generales-d'utilisation

Issues with
& becomes and (english) but for other language is not relevant
! on string end becomes -
° on string end becomes -

Fixed in #2830
I tested all cases from this issue, and all get slugified as expected!

For Devnagari unicode characters
Slugify is not working is there any idea .

This has been closed for months. You're welcome to open your own issue, or otherwise discuss it in our Slack group.

Was this page helpful?
0 / 5 - 0 ratings