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

Tom Hughes notifications at github.com
Wed Jul 16 16:44:56 UTC 2025


@tomhughes commented on this pull request.



> @@ -0,0 +1,25 @@
+# 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.

Why do we need an immediately invoked lambda here? Just to avoid namespace pollution? You could actually write it all with only one variable other than the end result:

```ruby
TAG2LINK = JSON.parse(Rails.root.join("node_modules/tag2link/index.json").read)
               .reject { |item| item["rank"] == "deprecated" }
               .group_by { |item| item["key"] }
               .transform_keys { |key| key.sub(/^Key:/, "") }
               .transform_values { |items| items.max_by { |item| ranks.index(item["rank"]) }.fetch("url") }
```

which just needs the array of ranks...

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

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


More information about the rails-dev mailing list