@pablobm commented on this pull request.
> end.html_safe
end
private
+ def unshorten_links(text)
+ Settings.linkify.paths.each do |path_rule|
Probably worth providing for the case where this setting is not present. This
appears to be done for `Settings.linkify_hosts`, as `shorten_host` does
`hosts&.include(host)`.
```suggestion
linkify_paths = Array.wrap(Settings.linkify&.paths)
linkify_paths.each do |path_rule|
```
> + path_rule.list.each do |expression|
+
text.gsub!(Regexp.new("(?<before>\\s|^|>)(?i)#{expression}(?<after>\\s|$|<)"),
"\\k<before>#{Settings.server_protocol}://#{path_rule.host ||
Settings.server_url}/#{path_rule.replacement}\\k<after>") if
path_rule.replacement
+ end
+ end
+ [[Settings.linkify_hosts, Settings.linkify_hosts_replacement],
[Settings.linkify_wiki_hosts, Settings.linkify_wiki_hosts_replacement]].each do
|hosts, replacement|
+ text.gsub!(/(\s)#{Regexp.escape(replacement)}/,
"\\1#{Settings.server_protocol}://#{hosts[0]}") if replacement && hosts&.any?
+ end
+ text
+ end
+
+ def shorten_link(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 || ""),
"")
+ end
+ Settings.linkify.print.each do |print_rule|
Similarly:
```suggestion
linkify_print = Array.wrap(Settings.linkify&.print)
linkify_print.each do |print_rule|
```
> + replacement: "way/\\k<id>"
+ - list: ["relation/(?<id>\\d+)", "relation (?<id>\\d{5,})", "r(?<id>\\d+)"]
+ replacement: "relation/\\k<id>"
+ - list: ["changeset/(?<id>\\d+)", "changeset (?<id>\\d{5,})", "cs
?(?<id>\\d{5,})"]
+ replacement: "changeset/\\k<id>"
+ - list: ["note/(?<id>\\d+)", "note (?<id>\\d{5,})"]
+ replacement: "note/\\k<id>"
+ - list: ["user/(?<username>[^\\s]+)", "@(?<username>[^\\s]+)"]
+ replacement: "user/\\k<username>"
+ - list: ["(?<key>[^\"?#<>/\\s]+)=\\*?"]
+ replacement: "wiki/Key:\\k<key>"
+ host: "wiki.openstreetmap.org"
+ - list: ["(?<key>[^\"?#<>/\\s]+)=(?<value>[^\"?#<>\\s]+)"]
+ replacement: "wiki/Tag:\\k<key>=\\k<value>"
+ host: "wiki.openstreetmap.org"
+ print:
I was a bit confused about the word `print` here, but now that I've looked into
this in a bit more detail, I'm very confused 😅 with all this `shorten`,
`unshorten`, `print` and `paths`.
Would you be able to explain the pipeline for me to understand? An example of
how the transformations take place.
--
Reply to this email directly or view it on GitHub:
https://github.com/openstreetmap/openstreetmap-website/pull/6518#pullrequestreview-3453087583
You are receiving this because you are subscribed to this thread.
Message ID:
<openstreetmap/openstreetmap-website/pull/6518/review/[email protected]>_______________________________________________
rails-dev mailing list
[email protected]
https://lists.openstreetmap.org/listinfo/rails-dev