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

Expose slugify options to user #34

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

yankl
Copy link
Contributor

@yankl yankl commented Dec 10, 2023

I have a problem using this plugin since my site is primarily written in an alphabet for which "slugify" has no ruleset. This results in all slugs being output as an empty string. One solution would be to try to get a ruleset added to slugify for my language. Strictly speaking, however, this isn't necessary, as slugs don't have to be in ASCII. It would be sufficient to modify the regex expression that determines which characters are thrown away when creating the slug. This is allowed through the slugify option "regexp". This option and others are also exposed to the user in PHP TOC Generator, on which this plugin is based (you can even inject your own sluggifier). However, as far as I can tell, the user of this Grav plugin has no ability to modify the slugify parameters without making changes to the plugin itself.

In this commit I attempted to allow for this possibilty in the least intrunsive way possible, by taking advantage of the options parameter passed to the fix method of MarkupFixer. The user can make changes to any of the slugify parameters by modifying page-toc.yaml. If this is not done, the fix method should receive the exact same array as before this commit. I also did this so as not to have to hardcode any defaults of the slugify options.

I didn't make any changes to blueprints.yaml or the deafult page-toc.yaml, in case you don't want to make the possibility of modifying the slugify options to be too obvious to the user. (As I said I was going for minimal intrusiveness.)

Since the possibility of changing the regexp option allows (as in my case) for non-ASCII slugs, I also replaced a couple string functions with their mb_ versions.

I've tested this, changing around different slugify options on my site, and as far as I can tell it works correctly.

Also: use mb_ functions to support non-ASCII slugs
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

Successfully merging this pull request may close these issues.

1 participant