Skip to content
This repository was archived by the owner on Nov 1, 2017. It is now read-only.

Commit 4cbe1c6

Browse files
committed
Merge from upstream
1 parent 7a3df31 commit 4cbe1c6

10 files changed

Lines changed: 196 additions & 2 deletions

File tree

‎Rules‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
# Reset search-index by deleting it every time
99
preprocess do
1010
File.delete("output/search-index.json") if File.exists?("output/search-index.json")
11+
create_individual_blog_pages
1112
generate_redirects(config[:redirects])
1213
end
1314

‎assets/stylesheets/pagination.css‎

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
.pagination a,
2+
.pagination span,
3+
.pagination em {
4+
position: relative;
5+
float: left;
6+
margin-left: -1px;
7+
font-size: 13px;
8+
font-weight: bold;
9+
font-style: normal;
10+
padding: 7px 12px;
11+
color: #4078c0;
12+
white-space: nowrap;
13+
vertical-align: middle;
14+
cursor: pointer;
15+
background: #fff;
16+
border: 1px solid #e5e5e5;
17+
user-select: none;
18+
}
19+
.pagination a:first-child,
20+
.pagination span:first-child,
21+
.pagination em:first-child {
22+
margin-left: 0;
23+
border-top-left-radius: 3px;
24+
border-bottom-left-radius: 3px;
25+
}
26+
.pagination a:last-child,
27+
.pagination span:last-child,
28+
.pagination em:last-child {
29+
border-top-right-radius: 3px;
30+
border-bottom-right-radius: 3px;
31+
}
32+
.pagination a:hover, .pagination a:focus,
33+
.pagination span:hover,
34+
.pagination span:focus,
35+
.pagination em:hover,
36+
.pagination em:focus {
37+
z-index: 2;
38+
background-color: #e7e7e7;
39+
border-color: #e5e5e5;
40+
text-decoration: none;
41+
}
42+
.pagination .selected {
43+
z-index: 3;
44+
}
45+
.pagination .current,
46+
.pagination .current:hover {
47+
z-index: 3;
48+
color: #fff;
49+
background-color: #4078c0;
50+
border-color: #4078c0;
51+
}
52+
.pagination .gap,
53+
.pagination .disabled,
54+
.pagination .gap:hover,
55+
.pagination .disabled:hover {
56+
background-color: #fafafa;
57+
cursor: default;
58+
color: #d3d3d3;
59+
}
60+
61+
.ajax_paginate {
62+
display: block;
63+
margin-top: 20px;
64+
}
65+
.ajax_paginate a {
66+
float: none;
67+
display: block;
68+
padding: 6px;
69+
text-align: center;
70+
}
71+
.ajax_paginate.loading a {
72+
text-indent: -3000px;
73+
background-color: #eaeaea;
74+
background-image: url("/images/spinners/octocat-spinner-16px-EAF2F5.gif");
75+
background-repeat: no-repeat;
76+
background-position: center center;
77+
border-color: #c5c5c5;
78+
}
79+
@media screen and (-webkit-min-device-pixel-ratio: 2), screen and (max--moz-device-pixel-ratio: 2) {
80+
.ajax_paginate.loading a {
81+
background-image: url("/images/spinners/octocat-spinner-32-EAF2F5.gif");
82+
background-size: 16px auto;
83+
}
84+
}
85+
86+
.paginate-container {
87+
margin-top: 20px;
88+
margin-bottom: 15px;
89+
text-align: center;
90+
}
91+
.paginate-container .pagination {
92+
display: inline-block;
93+
}

‎content/changes/index.html‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,8 @@
33
layout: blog
44
---
55

6-
<%= render '/_changes.*', :changes => api_changes %>
6+
<%= render '/_changes.*', :changes => paginated_api_changes(0, 9) %>
77

8+
<div class="paginate-container">
9+
<%= render '/includes/pagination_bar.html', :current_page => 1, :total_pages => total_pages %>
10+
</div>

‎gulpfile.js‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ gulp.task("css", function() {
2424
return gulp.src([
2525
"assets/stylesheets/reset.css",
2626
"assets/stylesheets/documentation.css",
27+
"assets/stylesheets/pagination.css",
2728
"assets/stylesheets/pygments.css",
2829
"assets/vendor/octicons/octicons/octicons.css"
2930
])

‎layouts/head.html‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,4 @@
1414
<script src="/assets/javascripts/dev_mode.js" type="text/javascript"></script>
1515
<% end %>
1616
</head>
17+
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<!-- @count_gap refers to the minimum number of sibling pages to show -->
2+
<% @count_gap = 2; @i = 1; @total_pages = total_pages; %>
3+
<div class="pagination">
4+
<% if @current_page > 1 %>
5+
<a href="/changes/<%= @current_page - 1 %>" class="previous_page">Previous</a>
6+
<% else %>
7+
<span class="disabled">Previous</span>
8+
<% end %>
9+
10+
<!-- using a while loop here as it's the only way to skip several iterations -->
11+
<% while @i <= @total_pages do %>
12+
<% @gap = false %>
13+
<!-- first half ensures we're not caught in an infinite loop at @total_pages - 1 -->
14+
<!-- second half, with the .abs, checks for gap siblings ahead *and* behind the current page -->
15+
<% if @i < (@total_pages - 1) && (@i - @current_page).abs > @count_gap %>
16+
<% @gap = true %>
17+
<!-- we skip multiple iterations to insert the gap (`...`), and continue with the regular links -->
18+
<% @i = (@i < @current_page ? @current_page - @count_gap : @total_pages - 1) - 1 %>
19+
<% end %>
20+
21+
<% if @gap %>
22+
<span class='disabled'></span>
23+
<% else %>
24+
<a href="/changes/<%= @i %>" class="<%= @current_page == @i ? 'current' : '' %>"><%= @i %></a>
25+
<% end %>
26+
27+
<% @i += 1 %>
28+
<% end %>
29+
30+
<% if @current_page < @total_pages %>
31+
<a href="/changes/<%= @current_page + 1 %>" class="next_page">Next</a>
32+
<% else %>
33+
<span class="disabled">Next</span>
34+
<% end %>
35+
</div>

‎layouts/pagination_page.html‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<%= render '/_changes.*', :changes => paginated_api_changes(@first, @last) %>
2+
3+
<div class="paginate-container">
4+
<%= render '/includes/pagination_bar.html', :current_page => @current_page, :total_pages => total_pages %>
5+
</div>

‎lib/changes_helper.rb‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
module ChangesHelper
2+
PER_PAGE = 10
3+
24
MimeFormat ||= "application/vnd.github.%s+json".freeze
35
# Public: Filters the change items out. If a version is given, show only the
46
# items related to that version.
@@ -19,6 +21,15 @@ def api_changes(version = nil)
1921
end
2022
end
2123

24+
def paginated_api_changes(first, last, version = nil)
25+
changes = api_changes(version)
26+
changes[first..last]
27+
end
28+
29+
def total_pages(version = nil)
30+
(api_changes(version).length / PER_PAGE).floor + 1
31+
end
32+
2233
# Public
2334
def current_api
2435
@current_api ||= (api_versions[-2] || api_versions.first).first

‎lib/default.rb‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
# All files in the 'lib' directory will be loaded
22
# before nanoc starts compiling.
3-
include Nanoc::Helpers::Rendering, Nanoc::Helpers::Blogging, ChangesHelper
3+
include Nanoc::Helpers::Rendering
4+
include Nanoc::Helpers::Blogging
5+
include ChangesHelper

‎lib/paginate.rb‎

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
class Nanoc::Item
2+
attr_accessor :page_items
3+
attr_accessor :page_parent
4+
attr_accessor :sub_pages
5+
6+
def paginated?
7+
!page_items.nil? && !page_items.empty? && !page_parent.nil?
8+
end
9+
end
10+
11+
module Paginate
12+
BLOG_TYPE = 'changes'
13+
14+
def paginated_items(items)
15+
items.select { |i| i.identifier =~ %r(/#{BLOG_TYPE}/\d{4}) }.sort_by { |b| Time.parse(b[:created_at].to_s) }
16+
end
17+
18+
def create_individual_blog_pages
19+
paginated_blog_items = paginated_items(items)
20+
21+
# create individual blog pages
22+
blog_pages = []
23+
blog_pages << paginated_blog_items.slice!(0...PER_PAGE) until paginated_blog_items.empty?
24+
25+
blog_pages.each_index do |i|
26+
next_i = i + 1 # accounts for 0-index array
27+
first = i * PER_PAGE
28+
last = (next_i * PER_PAGE) - 1
29+
30+
@items.create(
31+
"<%= render '/pagination_page.html',
32+
:current_page => #{next_i},
33+
:per_page => PER_PAGE,
34+
:first => #{first}, :last => #{last} %>",
35+
{ :title => 'GitHub API Changes' },
36+
"/changes/#{next_i}"
37+
)
38+
end
39+
end
40+
end
41+
42+
include Paginate

0 commit comments

Comments
 (0)