getgrav / grav-plugin-admin

Grav Admin Plugin
http://getgrav.org
MIT License
354 stars 227 forks source link

Improve page name to folder name conversion #1167

Closed zzzzBov closed 7 years ago

zzzzBov commented 7 years ago

Slugifying a name like "Can't touch this" produces "can-t-touch-this" because of how non-alphanumeric characters are translated.

Can apostrophes, and any other non-alphanumeric character that might appear mid-word be dropped rather than converted to hyphens?

rhukster commented 7 years ago

I think you are talking about the 'add page' modal?

2017-07-25 at 6 38 pm

This is powered by a JS library. we'll have to see if that can be configured.

zzzzBov commented 7 years ago

I think you are talking about the 'add page' modal?

Yep

This is powered by a JS library

I've done a little digging, it looks like SpeakingURL can take a custom hash to customize how specific characters are converted.

The custom $.slugify extension can be updated to pass the custom options by default:

$.slugify.options = {
    custom: {
      "'": ''
    },
    preSlug: null,
    postSlug: null,
    slugFunc: (input, opts) => getSlug(input, opts)
};

or add.js can be updated to pass the custom options to slugify:

let slug = $.slugify(elements.title.val(), {custom: {"'": ''}});

I'd make a pull request but then I'd also have to rebuild the JS, and I don't feel like jumping through all those hoops at the moment.

Hope that helps, and thanks for your time!

rhukster commented 7 years ago

Rebuilding JS is really not that bad, it's just a matter of doing an npm install to install all the bits, then a gulp js to build JS or gulp watch-js to watch and build when changes occur.

w00fz commented 7 years ago

let slug = $.slugify(elements.title.val(), {custom: {"'": ''}});

Yes please go ahead with the PR, that's exactly the kind of implementation I would do for your proposed enhancement. If you can't get the compilation going then just leave the PR allowing us to edit it and I'll recompile for you.

Thanks!

w00fz commented 7 years ago

This was merged in a PR (#1178). Thanks @zzzzBov