Skip to content

Commit

Permalink
Implement pagination feature (#621)
Browse files Browse the repository at this point in the history
* Implement pagination feature

* implement pagination for blog

* Styling for pagination

* Removed home path for testing blog description
  • Loading branch information
TimOsahenru authored Jan 2, 2025
1 parent fd54d74 commit 0ab1338
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 25 deletions.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ group :jekyll_plugins do
gem "github-pages"
gem "jekyll-remote-theme"
gem "jekyll-feed"
gem "jekyll-paginate"
end

# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
Expand Down
1 change: 1 addition & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,7 @@ DEPENDENCIES
github-pages
jekyll
jekyll-feed
jekyll-paginate
jekyll-remote-theme
jemoji
tzinfo-data
Expand Down
4 changes: 4 additions & 0 deletions _config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ plugins:
- jemoji
- jekyll-feed
- jekyll-sitemap
- jekyll-paginate
# - jekyll-seo-tag
# - jekyll-redirect-from
# - jekyll-remote-theme
Expand Down Expand Up @@ -111,3 +112,6 @@ defaults:
# Set to `true` to show excerpts on the homepage.
#
show_excerpts: true

paginate: 5
paginate_path: "/blog/page:num/"
27 changes: 17 additions & 10 deletions _includes/posts.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,28 @@ <h3>
</div>

{% if site.paginate %}
<div class="pager">
<ul class="pagination">
<div class="pagination">
{%- if paginator.previous_page %}
<li><a href="{{ paginator.previous_page_path | relative_url }}" class="previous-page">{{ paginator.previous_page }}</a></li>
<a href="{{ paginator.previous_page_path | relative_url }}" class="prev">&larr; Prev</a>
{%- else %}
<li><div class="pager-edge"></div></li>
<span class="disabled prev">&larr; Prev</span>
{%- endif %}
<li><div class="current-page">{{ paginator.page }}</div></li>

{%- for page in (1..paginator.total_pages) %}
{%- if page == paginator.page %}
<span class="current">{{ page }}</span>
{%- else %}
<a href="{{ paginator.previous_page_path | relative_url | replace: paginator.page, page }}" class="page">{{ page }}</a>
{%- endif %}
{%- endfor %}

{%- if paginator.next_page %}
<li><a href="{{ paginator.next_page_path | relative_url }}" class="next-page">{{ paginator.next_page }}</a></li>
<a href="{{ paginator.next_page_path | relative_url }}" class="next">Next &rarr;</a>
{%- else %}
<li><div class="pager-edge"></div></li>
<span class="disabled next">Next &rarr;</span>
{%- endif %}
</ul>
</div>
{%- endif %}

{%- endif -%}
{%- endif %}

{%- endif -%}
35 changes: 35 additions & 0 deletions assets/css/bpd.css
Original file line number Diff line number Diff line change
Expand Up @@ -522,3 +522,38 @@ ul.speaking-list {
max-width: 60%;
}
}

.pagination {
display: flex;
gap: 10px;
justify-content: center;
align-items: center;
}

.pagination a {
text-decoration: none;
padding: 5px 10px;
border: 1px solid #ddd;
border-radius: 4px;
color: #007acc;
}

.pagination a:hover {
background-color: #007acc;
color: #fff;
}

.pagination .current {
padding: 5px 10px;
border: 1px solid #007acc;
background-color: #007acc;
color: white;
border-radius: 4px;
}

.pagination .disabled {
padding: 5px 10px;
border: 1px solid #ddd;
color: #aaa;
cursor: not-allowed;
}
11 changes: 0 additions & 11 deletions blog.md

This file was deleted.

8 changes: 8 additions & 0 deletions blog/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
layout: default
lang: en
title: Blog
list_title: Posts
---

<div class="posts">{%- include posts.html -%}</div>
5 changes: 1 addition & 4 deletions tests/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,7 @@ def test_mailto_bpdevs(page_url: tuple[Page, str]) -> None:

@pytest.mark.parametrize(
"url",
(
"/",
"/blog",
),
("/blog",),
)
def test_page_description_in_index_and_blog(page_url: tuple[Page, str], url: str):
"""Checks for the descriptions data in the blog posts. There should be some objects with the class `post-description`"""
Expand Down

0 comments on commit 0ab1338

Please sign in to comment.