[openstreetmap/openstreetmap-website] use JOSM/tag2link to linkify tag values (PR #6197)

Tom Hughes notifications at github.com
Tue Jul 15 08:59:03 UTC 2025


@tomhughes commented on this pull request.



> @@ -0,0 +1,24 @@
+# A map of each OSM key to its formatter URL. For example:
+# { "ref:vatin" => "https://example.com/$1" }
+TAG2LINK = lambda {
+  # the JSON data is an array with duplicate entries, which is not efficient for lookups.
+  # So, convert it to a hash and only keep the item with the best rank.
+  array = JSON.parse(Rails.root.join("node_modules/tag2link/index.json").read)
+
+  ranks = %w[deprecated normal preferred].freeze

Do we want to include `deprecated` at all?

> +TAG2LINK = lambda {
+  # the JSON data is an array with duplicate entries, which is not efficient for lookups.
+  # So, convert it to a hash and only keep the item with the best rank.
+  array = JSON.parse(Rails.root.join("node_modules/tag2link/index.json").read)
+
+  ranks = %w[deprecated normal preferred].freeze
+
+  output = {}
+
+  all_keys = array.map { |item| item["key"] }.uniq
+
+  all_keys.each do |key|
+    # for each key, find the item with the best rank
+    best_definition = array
+                      .select { |item| item["key"] == key }
+                      .max_by { |item| ranks.index(item["rank"]) }

Unfortunately this is not a stable algorithm as there are keys with more than one entry at the same rank - even more than one `preferred` in some cases like `Key:seamark:radio_station:mmsi` so we might get different results for different runs unless we can break the tie somehow.

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

Message ID: <openstreetmap/openstreetmap-website/pull/6197/review/3019396324 at github.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openstreetmap.org/pipermail/rails-dev/attachments/20250715/e656c5d2/attachment-0001.htm>


More information about the rails-dev mailing list