[openstreetmap/openstreetmap-website] Simpliy linkify normalisation to use a single array of rules (PR #5862)

Marwin Hochfelsner notifications at github.com
Wed Dec 10 15:21:35 UTC 2025


@hlfan commented on this pull request.



> +        shorten_host(normalised_url, rule.hosts, rule.host_replacement) do |path|
+          path.sub(Regexp.new(rule.optional_path_prefix || ""), "")
+        end

Could we just pass `shorten_host` the whole rule and handle it there?

> @@ -133,9 +131,12 @@ def auto_link(text, mode)
     end
 
     def format_link_text(url)
-      url = shorten_host(url, Settings.linkify_hosts, Settings.linkify_hosts_replacement)
-      url = shorten_host(url, Settings.linkify_wiki_hosts, Settings.linkify_wiki_hosts_replacement) do |path|
-        path.sub(Regexp.new(Settings.linkify_wiki_optional_path_prefix || ""), "")
+      url = Array

Splitting the host and path related stuff made the expansion easier to read:

https://github.com/openstreetmap/openstreetmap-website/blob/c1dc08b5308b47ba5579fde79123f5588e4f2427/lib/rich_text.rb#L92-L93

Doing that here too instead of reassigning the URL could be an option.

-- 
Reply to this email directly or view it on GitHub:
https://github.com/openstreetmap/openstreetmap-website/pull/5862#pullrequestreview-3563070378
You are receiving this because you are subscribed to this thread.

Message ID: <openstreetmap/openstreetmap-website/pull/5862/review/3563070378 at github.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openstreetmap.org/pipermail/rails-dev/attachments/20251210/b8666544/attachment.htm>


More information about the rails-dev mailing list