Skip to content

Commit 0ab1338

Browse files
authored
Implement pagination feature (#621)
* Implement pagination feature * implement pagination for blog * Styling for pagination * Removed home path for testing blog description
1 parent fd54d74 commit 0ab1338

File tree

8 files changed

+67
-25
lines changed

8 files changed

+67
-25
lines changed

Gemfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ group :jekyll_plugins do
99
gem "github-pages"
1010
gem "jekyll-remote-theme"
1111
gem "jekyll-feed"
12+
gem "jekyll-paginate"
1213
end
1314

1415
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem

Gemfile.lock

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,7 @@ DEPENDENCIES
317317
github-pages
318318
jekyll
319319
jekyll-feed
320+
jekyll-paginate
320321
jekyll-remote-theme
321322
jemoji
322323
tzinfo-data

_config.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ plugins:
6060
- jemoji
6161
- jekyll-feed
6262
- jekyll-sitemap
63+
- jekyll-paginate
6364
# - jekyll-seo-tag
6465
# - jekyll-redirect-from
6566
# - jekyll-remote-theme
@@ -111,3 +112,6 @@ defaults:
111112
# Set to `true` to show excerpts on the homepage.
112113
#
113114
show_excerpts: true
115+
116+
paginate: 5
117+
paginate_path: "/blog/page:num/"

_includes/posts.html

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,21 +30,28 @@ <h3>
3030
</div>
3131

3232
{% if site.paginate %}
33-
<div class="pager">
34-
<ul class="pagination">
33+
<div class="pagination">
3534
{%- if paginator.previous_page %}
36-
<li><a href="{{ paginator.previous_page_path | relative_url }}" class="previous-page">{{ paginator.previous_page }}</a></li>
35+
<a href="{{ paginator.previous_page_path | relative_url }}" class="prev">&larr; Prev</a>
3736
{%- else %}
38-
<li><div class="pager-edge"></div></li>
37+
<span class="disabled prev">&larr; Prev</span>
3938
{%- endif %}
40-
<li><div class="current-page">{{ paginator.page }}</div></li>
39+
40+
{%- for page in (1..paginator.total_pages) %}
41+
{%- if page == paginator.page %}
42+
<span class="current">{{ page }}</span>
43+
{%- else %}
44+
<a href="{{ paginator.previous_page_path | relative_url | replace: paginator.page, page }}" class="page">{{ page }}</a>
45+
{%- endif %}
46+
{%- endfor %}
47+
4148
{%- if paginator.next_page %}
42-
<li><a href="{{ paginator.next_page_path | relative_url }}" class="next-page">{{ paginator.next_page }}</a></li>
49+
<a href="{{ paginator.next_page_path | relative_url }}" class="next">Next &rarr;</a>
4350
{%- else %}
44-
<li><div class="pager-edge"></div></li>
51+
<span class="disabled next">Next &rarr;</span>
4552
{%- endif %}
46-
</ul>
4753
</div>
48-
{%- endif %}
4954

50-
{%- endif -%}
55+
{%- endif %}
56+
57+
{%- endif -%}

assets/css/bpd.css

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -522,3 +522,38 @@ ul.speaking-list {
522522
max-width: 60%;
523523
}
524524
}
525+
526+
.pagination {
527+
display: flex;
528+
gap: 10px;
529+
justify-content: center;
530+
align-items: center;
531+
}
532+
533+
.pagination a {
534+
text-decoration: none;
535+
padding: 5px 10px;
536+
border: 1px solid #ddd;
537+
border-radius: 4px;
538+
color: #007acc;
539+
}
540+
541+
.pagination a:hover {
542+
background-color: #007acc;
543+
color: #fff;
544+
}
545+
546+
.pagination .current {
547+
padding: 5px 10px;
548+
border: 1px solid #007acc;
549+
background-color: #007acc;
550+
color: white;
551+
border-radius: 4px;
552+
}
553+
554+
.pagination .disabled {
555+
padding: 5px 10px;
556+
border: 1px solid #ddd;
557+
color: #aaa;
558+
cursor: not-allowed;
559+
}

blog.md

Lines changed: 0 additions & 11 deletions
This file was deleted.

blog/index.html

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
layout: default
3+
lang: en
4+
title: Blog
5+
list_title: Posts
6+
---
7+
8+
<div class="posts">{%- include posts.html -%}</div>

tests/test.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,10 +106,7 @@ def test_mailto_bpdevs(page_url: tuple[Page, str]) -> None:
106106

107107
@pytest.mark.parametrize(
108108
"url",
109-
(
110-
"/",
111-
"/blog",
112-
),
109+
("/blog",),
113110
)
114111
def test_page_description_in_index_and_blog(page_url: tuple[Page, str], url: str):
115112
"""Checks for the descriptions data in the blog posts. There should be some objects with the class `post-description`"""

0 commit comments

Comments
 (0)