xenocrat / chyrp-lite

An ultra-lightweight blogging engine, written in PHP.
https://chyrplite.net/
BSD 3-Clause "New" or "Revised" License
416 stars 43 forks source link

Feature Request: Custom slug for tags #254

Open cuixiping opened 5 months ago

cuixiping commented 5 months ago

Currently, the tag page url will look like /tag/86e921607657572b438d5c03156008dc/ when tag text is Asian characters, for example 文字.

If user can config custom slug when add or edit tags, the url will be very nice like /tag/custom-slug/.

xenocrat commented 5 months ago

Hello there,

Custom slugs for tags are difficult to implement, because the original design of the tags module is decentralized: tags are generated and saved as attributes of each post instead of being saved in a centralized database table. This means the slug must be created deterministically from the tag text.

I'll have a think about this and report back if I think of a good solution.

cuixiping commented 5 months ago

I suggest:
If there is a custom slug list, then use the custom slug which match the tag text.
Use url encoded string if no match found, for example 文字 becomes %E6%96%87%E5%AD%97, like wikipedia style.

https://zh.wikipedia.org/wiki/%E6%96%87%E5%AD%97 image

When user write a post, user can write any tag text freely or select from the tag text list. User can configure custom slug later in tag manager page.

xenocrat commented 2 months ago

With the latest release, I'm enforcing strict rules for all slugs - but I'm aware this might be an unwelcome change for non-English speaking users, so I've created a global constant to relax all slugs for posts, pages, categories, and tags. This will result in something like your suggestion above: URL encoded slugs.

You can relax the slug rules globally by setting the constant SLUG_STRICT to false in common.php. I didn't create a configuration option in the admin console because changing this constant will cause existing tags to misbehave. If you disable strict slugs, you'll need to do Admin > Manage > Tags > Edit > Rename for each of your existing tags. This will update the tag values in the database using the more relaxed slug rules.