mirror of
https://github.com/hkalexling/Mango.git
synced 2025-08-03 03:15:31 -04:00
Sort tags on the tags page
This commit is contained in:
parent
c5c73ddff3
commit
dcdcf29114
@ -138,12 +138,16 @@ struct MainRouter
|
||||
end
|
||||
|
||||
get "/tags" do |env|
|
||||
tags = Storage.default.list_tags
|
||||
encoded_tags = tags.map do |t|
|
||||
URI.encode_www_form t, space_to_plus: false
|
||||
tags = Storage.default.list_tags.map do |tag|
|
||||
{
|
||||
tag: tag,
|
||||
encoded_tag: URI.encode_www_form(tag, space_to_plus: false),
|
||||
count: Storage.default.get_tag_titles(tag).size,
|
||||
}
|
||||
end
|
||||
counts = tags.map do |t|
|
||||
Storage.default.get_tag_titles(t).size
|
||||
# Sort by :count reversly, and then sort by :tag
|
||||
tags.sort! do |a, b|
|
||||
(b[:count] <=> a[:count]).or(a[:tag] <=> b[:tag])
|
||||
end
|
||||
|
||||
layout "tags"
|
||||
|
@ -1,8 +1,8 @@
|
||||
<h2 class=uk-title>Tags</h2>
|
||||
<p class="uk-text-meta"><%= tags.size %> <%= tags.size > 1 ? "tags" : "tag" %> found</p>
|
||||
|
||||
<% tags.zip(encoded_tags, counts).each do |tag, encoded, count| %>
|
||||
<% tags.each do |tag| %>
|
||||
<span class="uk-label uk-label-primary" style="padding:2px 5px; margin:0 5px 5px 5px; text-transform:none;">
|
||||
<a class="uk-link-reset" href="<%= base_url %>tags/<%= encoded %>"><%= tag %> (<%= count %> <%= count > 1 ? "titles" : "title" %>)</a>
|
||||
<a class="uk-link-reset" href="<%= base_url %>tags/<%= tag[:encoded_tag] %>"><%= tag[:tag] %> (<%= tag[:count] %> <%= tag[:count] > 1 ? "titles" : "title" %>)</a>
|
||||
</span>
|
||||
<% end %>
|
||||
|
Loading…
x
Reference in New Issue
Block a user