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

Kyℓe Hensel notifications at github.com
Tue Jul 15 09:13:26 UTC 2025


@k-yle commented on this pull request.



> +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"]) }

<details>
<summary>This problem seems to only affect 17 tags, most of which are quite obscure (click to expand)</summary>

```py
de:amtlicher_gemeindeschluessel = 7
fhrs:id = 2
hashtags = 42
icao = 8
ref:EU:bwid = 4
ref:FR:MemorialGenWeb = 2
ref:FR:museofile = 2
ref:FR:SIREN = 5
ref:ibnr = 11
ref:INEP = 2
ref:INSEE = 4
ref:ruian = 3
ref:vatin = 4
ref:WDPA = 2
*:mmsi = 2
uic_ref = 6
woeid = 2
```

</details>

Maybe we should skip these ones if there are multiple matches with equal probability? If someone complains, then perhaps they should fix the problem upstream

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

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


More information about the rails-dev mailing list