Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add suitable links to tags overview page where possible
For some tags such as wikipedia, website, url, wikidata, phone, etc. this will add one or more links to relevant web sites to the tags overview tab.
- Loading branch information
Showing
11 changed files
with
154 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
|
||
class TagLink | ||
|
||
attr_reader :title, :url | ||
|
||
def initialize(title, url) | ||
@title = title | ||
@url = url | ||
end | ||
|
||
def html | ||
external_link('', @title, @url, true) | ||
end | ||
|
||
end | ||
|
||
class TagMatch | ||
|
||
attr_reader :regex | ||
|
||
def initialize(regex, func) | ||
@regex = regex | ||
@func = func | ||
end | ||
|
||
def match(value) | ||
value =~ @regex | ||
end | ||
|
||
def call(value) | ||
@func.call(value) | ||
end | ||
|
||
def links(value) | ||
if match(value) | ||
return call(value).map{ |link| link.html } | ||
end | ||
[] | ||
end | ||
|
||
end | ||
|
||
def tag_match(regex, func) | ||
TagMatch.new(regex, func) | ||
end | ||
|
||
# https://wikistats.wmcloud.org/wikimedias_csv.php | ||
# grep ,wikipedia, wikimedias.csv | cut -d, -f2 | sort | ||
TAGLINKS = { | ||
'addr:country': tag_match(%r{^[A-Z][A-Z]$}, lambda { |value| | ||
return [ TagLink.new('ISO: ' + value, 'https://www.iso.org/obp/ui/#iso:code:3166:' + value), | ||
TagLink.new('Wikipedia: ' + value, 'https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2#' + value) ] | ||
}), | ||
phone: tag_match(%r{^\+[0-9. -]+$}, lambda { |value| return [ TagLink.new('Phone number: ' + value, 'tel:' + value.gsub(/[ .-]+/, '-')) ] }), | ||
'ref:bag': tag_match(%r{^[0-9]+$}, lambda { |value| | ||
id = value.rjust(16, '0') | ||
return [ TagLink.new('Basisregistratie Adressen en Gebouwen (BAG): ' + id, 'https://bagviewer.kadaster.nl/lvbag/bag-viewer/index.html#?searchQuery=' + id) ] | ||
}), | ||
species: tag_match(%r{^[a-zA-Z -]+$}, lambda { |value| return [ TagLink.new('Wikispecies: ' + value, 'https://species.wikimedia.org/wiki/' + value) ] }), | ||
url: tag_match(%r{^https?://}, lambda { |value| return [ TagLink.new('Website', value) ] }), | ||
website: tag_match(%r{^https?://}, lambda { |value| return [ TagLink.new('Website', value) ] }), | ||
wikidata: tag_match(%r{^Q[0-9]{1,10}$}, lambda { |value| return [ TagLink.new('Wikidata: ' + value, 'https://www.wikidata.org/wiki/' + value) ] }), | ||
wikipedia: tag_match(%r{^[a-z-]{2,8}:}, lambda { |value| | ||
c = value.split(':') | ||
if $WIKIPEDIA_SITES.include?(c[0]) | ||
return [ TagLink.new('Wikipedia', "https://#{c[0]}.wikipedia.org/wiki/#{c[1]}") ] | ||
end | ||
return [] | ||
}) | ||
} | ||
|
||
def get_links(key, value) | ||
tm = TAGLINKS[key.to_sym] | ||
if tm | ||
return tm.links(value) | ||
end | ||
|
||
return [] | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<div class="pre" lang="en" dir="ltr"> | ||
<h1>Tag links</h1> | ||
<p>The following keys support tag links, i.e. autogenerated links from tag | ||
values to. The regular expression must match for this to work.</p> | ||
</div> | ||
<div class="box"> | ||
<table class="list"> | ||
<thead><th>Key</th><th>Count</th><th>Unique values</th><th>Matching values</th><th>Regex</th><th>Links (simplified display)</th></thead> | ||
<tbody> | ||
<% TAGLINKS.each_with_index do |(key, match), n| c = (n%2!=0) ? ' even' : '' %> | ||
<tr> | ||
<td class="<%= c %>"><a href="/keys/<%= h(key) %>"><%= h(key) %></a></td> | ||
<td class="tr<%= c %>"><%= @data[key]['count_all'].to_s_with_ts %></td> | ||
<td class="tr<%= c %>"><%= @data[key]['values_all'].to_s_with_ts %></td> | ||
<td class="tr<%= c %>"><%= @data[key]['values_match'].to_s_with_ts %> (<%= (@data[key]['values_match'] * 100 / @data[key]['values_all']).to_i %>%)</td> | ||
<td class="<%= c %>"><tt><%= h(match.regex.inspect[1..-2]) %></tt></td> | ||
<td class="<%= c %>"><ul><%= @data[key]['links'].map{ |tl| '<li>' + h(tl.title) + ' → ' + h(tl.url) + '</li>' }.join %></ul></td> | ||
</tr> | ||
<% end %> | ||
</tbody> | ||
</table> | ||
</div> |