Skip to content

Commit fff5ef7

Browse files
google-labs-jules[bot]vjdhama
authored andcommitted
feat: Add pagination and pinned posts to blog
This commit introduces pagination to the blog, displaying 10 posts per page. It also adds the ability to pin posts to the top of the blog list. - Enables pagination in `config.toml`. - Modifies the blog list template to display pinned posts first, followed by paginated posts. - Adds pagination controls to the blog list page.
1 parent 1ce6f9d commit fff5ef7

File tree

5 files changed

+33
-4
lines changed

5 files changed

+33
-4
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ hugo.linux
1515

1616
# Temporary lock file while building
1717
/.hugo_build.lock
18+
hugo_output.log
19+
bin/
1820

1921
### Intellij+all ###
2022
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider

config.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ baseURL = "https://www.infraspec.dev/"
22
languageCode = "en-us"
33
title = "Infraspec"
44
enableRobotsTXT = false
5+
paginate = 10
56

67
[module]
78
[module.hugoVersion]

content/blog/building-a-discord-gpt-bot.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ authorIds: ["nandhitha"]
44
date: 2024-05-31
55
draft: false
66
featured: true
7+
pinned: true
78
weight: 1
89
sitemap:
910
changefreq: "monthly"

layouts/blog/list.html

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,20 @@
1111

1212
<div class="container pt-6 pb-6">
1313
<div class="row">
14-
{{ range .Pages.ByWeight }}
15-
<div class="col-12">
16-
<div>{{ .Render "summary" }}</div>
17-
</div>
14+
{{ $pinned := where .Pages "Params.pinned" "eq" true }}
15+
{{ range $pinned }}
16+
<div class="col-12">
17+
<div>{{ .Render "summary" }}</div>
18+
</div>
19+
{{ end }}
20+
21+
{{ $paginator := .Paginate (where .Pages "Params.pinned" "ne" true) }}
22+
{{ range $paginator.Pages }}
23+
<div class="col-12">
24+
<div>{{ .Render "summary" }}</div>
25+
</div>
1826
{{ end }}
1927
</div>
28+
{{ partial "pagination.html" . }}
2029
</div>
2130
{{ end }}

layouts/partials/pagination.html

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{{ $paginator := .Paginator }}
2+
<!-- Pagination -->
3+
<div class="pagination">
4+
{{ if $paginator.HasPrev }}
5+
<a class="pagination-previous" href="{{ $paginator.Prev.URL }}">
6+
<i class="fa fa-chevron-left"></i>
7+
Older Posts
8+
</a>
9+
{{ end }}
10+
{{ if $paginator.HasNext }}
11+
<a class="pagination-next" href="{{ $paginator.Next.URL }}">
12+
Newer Posts
13+
<i class="fa fa-chevron-right"></i>
14+
</a>
15+
{{ end }}
16+
</div>

0 commit comments

Comments
 (0)