Omit last hyphen from URL

Created on 26 June 2024, 11 days ago
Updated 28 June 2024, 9 days ago

Hey there!

I found my way here from the Toc.js module page, thanks for letting me know about this module in the comments! Everything seems to work well and there are even more features I could have even hope for :)

One request though: I think the last hyphen in URL (if there is one) should always be omitted, same of course for the generated corresponding element IDs. No matter what special char/chars, spaces etc the title/header in the content has, I don't think it's ever wanted into the URL, if its the last character in the URL.

📌 Task
Status

Fixed

Version

1.0

Component

Code

Created by

🇫🇮Finland phonkala

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @phonkala
  • 🇫🇷France mably

    Hi @phonkala, happy to hear that you find toc_ng interesting.

    Would you mind explaining more in details what the problem is exactly?

    I'm not sure to understand what is wrong with a trailing hyphen in the URL hashes, if I understand it correctly.

  • 🇫🇮Finland phonkala

    Hey there!

    There is nothing wrong with it technically, but I don't think it really should be there. I guess same would apply if hyphen was the first character in the url. Sure it works fine, but for readability/cleanliness in for example search results etc, it just feels very unnecessary.

    For example, if there was a header:
    "!!! Hey this works fine, don't you think???",

    I don't think the url should be
    "mydomain.com/article-1#-hey-this-works-fine-dont-you-think-", it should be
    "mydomain.com/article-1#hey-this-works-fine-dont-you-think"

    But I guess in the end it's just my opinion. Though I do truely think that when applying this kind of automation, the goal should be as simple and easy-to-read urls as possible, and those first/last character hyphens really have no reason to be in the URL, at least I can't think of a any :)

  • Assigned to mably
  • Status changed to Fixed 10 days ago
  • 🇫🇷France mably

    Just pushed a small fix to the dev branch that trims those extra hyphens.

    You can give it a try and tell me how it goes.

  • 🇫🇮Finland phonkala

    Thanks, this seems to work nicely. All the anchor URLs look very clear and pretty now.

    I also realized that certain characters that should just be removed from the urls (like apostrophe, quotation mark etc) are currently turned into hyphens. So I was thinking: Would it be possible to just use the Drupal cores transliteration interface to achieve this (Drupal\Component\Transliteration)? This is of course just an idea, but I guess that would streamline the module with Drupals behavior even more.

    Anyways, the current dev version works perfectly for my use, thanks for the latest update!

  • 🇫🇷France mably

    Headings parsing is done client-side in Javascript, so we do not have access to Drupal API.

Production build 0.69.0 2024