<p></p>
<p><b>@pablobm</b> commented on this pull request.</p>

<p dir="auto">Thank you, so much better now, even if the logic is a bit cryptic to me 😅  The important part is that now this is easily testable.</p>
<p dir="auto">One detail is the commit structure. Ideally, we would want a commit for the refactor (plus initial tests), then a commit for the new functionality (with its own sets of tests). This way in the future someone reading through the commits would understand the two different changes made here. Would you be able to separate those?</p><hr>

<p>In <a href="https://github.com/openstreetmap/openstreetmap-website/pull/6470#discussion_r2465473926">config/initializers/tag2link.rb</a>:</p>
<pre style='color:#555'>> -# A map of each OSM key to its formatter URL. For example:
-# { "ref:vatin" => "https://example.com/$1" }
-# 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.
-TAG2LINK = JSON.parse(Rails.root.join("node_modules/tag2link/index.json").read)
-               # exclude deprecated and third-party URLs
-               .reject { |item| item["rank"] == "deprecated" || item["source"] == "wikidata:P3303" }
-               .group_by { |item| item["key"] }
-               .transform_keys { |key| key.sub(/^Key:/, "") }
-               # move preferred to the start of the array
-               .transform_values { |items| items.sort_by { |item| item["rank"] == "preferred" ? 0 : 1 }.uniq { |item| item["url"] } }
-               # exclude any that are ambiguous, i.e. the best and second-best have the same rank
-               .reject { |_key, value| value[1] && value[0]["rank"] == value[1]["rank"] }
-               # keep only the best match
-               .transform_values { |items| items[0]["url"] }
+require Rails.root.join("lib/tag2link")
</pre>
<p dir="auto">No need for the absolute path. <code class="notranslate">lib/</code> is automatically in the library load path:</p>
⬇️ Suggested change
<pre style="color: #555">-require Rails.root.join("lib/tag2link")
+require "tag2link"
</pre>


<p style="font-size:small;-webkit-text-size-adjust:none;color:#666;">—<br />Reply to this email directly, <a href="https://github.com/openstreetmap/openstreetmap-website/pull/6470#pullrequestreview-3383236054">view it on GitHub</a>, or <a href="https://github.com/notifications/unsubscribe-auth/AAK2OLPC3AQOJEVAWVD5CRL3ZYBBBAVCNFSM6AAAAACKBQTVXSVHI2DSMVQWIX3LMV43YUDVNRWFEZLROVSXG5CSMV3GSZLXHMZTGOBTGIZTMMBVGQ">unsubscribe</a>.<br />You are receiving this because you are subscribed to this thread.<img src="https://github.com/notifications/beacon/AAK2OLJZ2UNT6VJEFBVJZBD3ZYBBBA5CNFSM6AAAAACKBQTVXSWGG33NNVSW45C7OR4XAZNRKB2WY3CSMVYXKZLTORJGK5TJMV32UY3PNVWWK3TUL5UWJTWJVAK5M.gif" height="1" width="1" alt="" /><span style="color: transparent; font-size: 0; display: none; visibility: hidden; overflow: hidden; opacity: 0; width: 0; height: 0; max-width: 0; max-height: 0; mso-hide: all">Message ID: <span><openstreetmap/openstreetmap-website/pull/6470/review/3383236054</span><span>@</span><span>github</span><span>.</span><span>com></span></span></p>
<script type="application/ld+json">[
{
"@context": "http://schema.org",
"@type": "EmailMessage",
"potentialAction": {
"@type": "ViewAction",
"target": "https://github.com/openstreetmap/openstreetmap-website/pull/6470#pullrequestreview-3383236054",
"url": "https://github.com/openstreetmap/openstreetmap-website/pull/6470#pullrequestreview-3383236054",
"name": "View Pull Request"
},
"description": "View this Pull Request on GitHub",
"publisher": {
"@type": "Organization",
"name": "GitHub",
"url": "https://github.com"
}
}
]</script>