@tomhughes commented on this pull request.
> + path_template: "user/\\k<username>"
+ - patterns: ["(?<key>[^\"?#<>/\\s]+)=\\*?"]
+ path_template: "wiki/Key:\\k<key>"
+ host: "https://wiki.openstreetmap.org"
+ - patterns: ["(?<key>[^\"?#<>/\\s]+)=(?<value>[^\"?#<>\\s]+)"]
+ path_template: "wiki/Tag:\\k<key>=\\k<value>"
+ host: "https://wiki.openstreetmap.org"
+ display_rules:
+ - pattern: "osm\\.org/user/"
+ replacement: "@"
+ - pattern: "osm\\.org/(?<type>node|way|relation|changeset|note)/"
+ replacement: "\\k<type>/"
+ - pattern: "osm\\.wiki/Key:(?<key>[^\"?#<>/\\s]+)"
+ replacement: "\\k<key>=*"
+ - pattern:
"osm\\.wiki/Tag:(?<key>[^\"?#<>/\\s]+)(?:=|%3D)(?<value>[^\"?#<>\\s]+)"
+ replacement: "\\k<key>=\\k<value>"
Would taginfo be a better target here? Many keys and/or key-value pairs won't
actually have a wiki page?
> end
private
+ def expand_link_shorthands(text)
+ Array.wrap(Settings.linkify&.detection_rules)
+ .select { |rule| rule.path_template && rule.patterns.is_a?(Array) }
+ .flat_map { |rule| linkify_detection_rule_to_gsub(rule) }
+ .reduce(text) { |text, (pattern, replacement)| text.gsub(pattern,
replacement) }
+ end
+
+ def linkify_detection_rule_to_gsub(rule)
+ expanded_path = "#{rule.host ||
"#{Settings.server_protocol}://#{Settings.server_url}"}/#{rule.path_template}"
+ rule.patterns
+ .select { |pattern| pattern.is_a?(String) }
+ .map do |pattern|
+ [
+ Regexp.new("(?<before>\\s|^|>)#{pattern}(?<after>\\s|$|<)",
Regexp::IGNORECASE),
Would looking for a word boundary with `\b` before and after work here and
make this a bit simpler?
> end
private
+ def expand_link_shorthands(text)
+ Array.wrap(Settings.linkify&.detection_rules)
+ .select { |rule| rule.path_template && rule.patterns.is_a?(Array) }
+ .flat_map { |rule| linkify_detection_rule_to_gsub(rule) }
Is `flat_map` correct here? We want a list of pattern and replacement pairs and
`linkify_detection_rule_to_gsub` returns a pattern/replacement pair so running
it on each rule will give us what we want and flattening will destroy that?
--
Reply to this email directly or view it on GitHub:
https://github.com/openstreetmap/openstreetmap-website/pull/6518#pullrequestreview-3541156197
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