Skip to content

Commit e5382f7

Browse files
committed
Group tags into buckets with statically assigned sizes
1 parent e9a4596 commit e5382f7

File tree

4 files changed

+41
-5
lines changed

4 files changed

+41
-5
lines changed

app/assets/stylesheets/publify.css.scss

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,20 @@
3333
overflow: hidden;
3434
}
3535

36+
.tag-sidebar-tag-67 { font-size: 0.67em; }
37+
.tag-sidebar-tag-75 { font-size: 0.75em; }
38+
.tag-sidebar-tag-83 { font-size: 0.83em; }
39+
.tag-sidebar-tag-91 { font-size: 0.91em; }
40+
.tag-sidebar-tag-100 { font-size: 1em; }
41+
.tag-sidebar-tag-112 { font-size: 1.12em; }
42+
.tag-sidebar-tag-125 { font-size: 1.25em; }
43+
.tag-sidebar-tag-137 { font-size: 1.37em; }
44+
.tag-sidebar-tag-150 { font-size: 1.50em; }
45+
.tag-sidebar-tag-162 { font-size: 1.62em; }
46+
.tag-sidebar-tag-175 { font-size: 1.75em; }
47+
.tag-sidebar-tag-187 { font-size: 1.87em; }
48+
.tag-sidebar-tag-200 { font-size: 2em; }
49+
3650
.hidden {
3751
display: none;
3852
}

app/models/tag_sidebar.rb

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,34 @@ def sizes
1818
average = total.to_f / @tags.size
1919
@sizes = tags.reduce({}) do |h, tag|
2020
size = tag.content_counter.to_f / average
21-
h.merge tag => size.clamp(2.0 / 3.0, 2) * 100
21+
h.merge tag => bucket(size)
2222
end
2323
end
2424

25-
def font_multiplier
26-
80
25+
BUCKETS = [
26+
67,
27+
75,
28+
83,
29+
91,
30+
100,
31+
112,
32+
125,
33+
137,
34+
150,
35+
162,
36+
175,
37+
187,
38+
200
39+
].freeze
40+
41+
private
42+
43+
def bucket(size)
44+
base_size = size.clamp(2.0 / 3.0, 2) * 100
45+
BUCKETS.each do |sz|
46+
return sz if sz >= base_size
47+
end
48+
BUCKETS.last
2749
end
2850
end
2951

app/views/tag_sidebar/_content.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<div class="sidebar-body">
44
<p class="tag-sidebar-tag-cloud">
55
<% sidebar.tags.each do |tag| %>
6-
<span style="font-size:<%= sidebar.sizes[tag] %>%"><%= link_to tag.display_name, tag_url(tag.name) %></span>
6+
<span class="tag-sidebar-tag-<%= sidebar.sizes[tag] %>"><%= link_to tag.display_name, tag_url(tag.name) %></span>
77
<% end %>
88
</p>
99
</div>

spec/models/tag_sidebar_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
create(:article, keywords: "foo, quuz")
4444

4545
result = sidebar.sizes
46-
expect(result.values.uniq).to contain_exactly (2.0 / 3.0 * 100), 200
46+
expect(result.values.uniq).to contain_exactly 67, 200
4747
end
4848
end
4949
end

0 commit comments

Comments
 (0)