Skip to content

Commit

Permalink
Implement pagination
Browse files Browse the repository at this point in the history
  • Loading branch information
nscyclone authored and doomspork committed Jul 11, 2017
1 parent f6b2993 commit 4569414
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 42 deletions.
49 changes: 11 additions & 38 deletions _assets/stylesheets/poole.css
Original file line number Diff line number Diff line change
Expand Up @@ -380,51 +380,24 @@ tbody tr:nth-child(odd) th {

/*
* Pagination
*
* Super lightweight (HTML-wise) blog pagination. `span`s are provide for when
* there are no more previous or next posts to show.
*/

.pagination {
overflow: hidden; /* clearfix */
margin-left: -1rem;
margin-right: -1rem;
font-family: "PT Sans", Helvetica, Arial, sans-serif;
color: #ccc;
text-align: center;
}

/* Pagination items can be `span`s or `a`s */
.pagination-item {
width: 100%;
display: block;
padding: 1rem;
border: 1px solid #eee;
}
.pagination-item:first-child {
margin-bottom: -1px;
padding: 0px;
}

/* Only provide a hover state for linked pagination items */
a.pagination-item:hover {
background-color: #f5f5f5;
.pagination li {
list-style-type: none;
}

@media (min-width: 30em) {
.pagination {
margin: 3rem 0;
}
.pagination-item {
float: left;
width: 50%;
}
.pagination-item:first-child {
margin-bottom: 0;
border-top-left-radius: 4px;
border-bottom-left-radius: 4px;
}
.pagination-item:last-child {
margin-left: -1px;
border-top-right-radius: 4px;
border-bottom-right-radius: 4px;
}
.pagination-prev {
float: left;
margin-left: 0.5rem;
}
.pagination-next {
float: right;
margin-right: 0.5rem;
}
18 changes: 18 additions & 0 deletions _includes/pagination.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{% assign pagination = page.leaf %}
{% unless pagination.previous == nil and pagination.next == nil %}
<hr />
<ul class="pagination">
{% unless pagination.previous == nil %}
{% assign previous = site.tree[page.lang][pagination.previous.section][pagination.previous.chapter] %}
<li class="pagination-prev">
<a href="{{ previous.url }}" title="{{ previous.title }}">← {{ previous.title }}</a>
</li>
{% endunless %}
{% unless pagination.next == nil %}
{% assign next = site.tree[page.lang][pagination.next.section][pagination.next.chapter] %}
<li class="pagination-next">
<a href="{{ next.url }}" title="{{ next.title }}">{{ next.title }} →</a>
</li>
{% endunless %}
</ul>
{% endunless %}
4 changes: 3 additions & 1 deletion _layouts/page.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,7 @@ <h1 class="page-title">{{ page.title }}</h1>

{{ content }}

{% include pagination.html %}

{% include social.html %}
</div>
</div>
9 changes: 6 additions & 3 deletions _plugins/elixir_school.rb
Original file line number Diff line number Diff line change
Expand Up @@ -137,15 +137,18 @@ def contents(site, lang)
chapters.each_with_index do |chapter_name, index|
if chapter = get_chapter(site, lang, section, chapter_name)
chapter['chapter_number'] = index + 1
current = [section, chapter_name]
current = {
'section' => section,
'chapter' => chapter_name
}

contents[section] ||= {}
contents[section][chapter_name] = chapter
# insert 'previous' in current chapter
contents[section][chapter_name]['previous'] = previous
# insert 'next' in previous chapter
if previous != nil
contents[previous[0]][previous[1]]['next'] = current
contents[previous['section']][previous['chapter']]['next'] = current
end

# update previous for next iteration
Expand All @@ -154,7 +157,7 @@ def contents(site, lang)
end
end
# set 'next' for last contents entry
contents[previous[0]][previous[1]]['next'] = nil
contents[previous['section']][previous['chapter']]['next'] = nil

contents
end
Expand Down

0 comments on commit 4569414

Please sign in to comment.