Skip to content

Commit

Permalink
post: add first/last post navigation links
Browse files Browse the repository at this point in the history
  • Loading branch information
RaphaelPour committed Jul 5, 2024
1 parent 8383f14 commit 5d5802c
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* metadata: render posts with date instead of full timestamp
* post: add discussion board via github using giscus
* dependency: update go to 1.22.4
* post: add first/last post navigation links

*Not released yet*

Expand Down
6 changes: 6 additions & 0 deletions cmd/post.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,19 @@
</head>
<body>
<div class='post'>
{{if .FirstPostLink}}
<a href='{{.FirstPostLink}}'>&lt;&lt;</a>
{{end}}
{{if .PreviousPostLink}}
<a href='{{.PreviousPostLink}}'>&lt;</a>
{{end}}
<a href='{{.HomeLink}}'>up</a>
{{if .NextPostLink}}
<a href='{{.NextPostLink}}'>&gt;</a>
{{end}}
{{if .LastPostLink}}
<a href='{{.LastPostLink}}'>&gt;&gt;</a>
{{end}}
</br>

<span class='date'>{{.CreatedAt}}</span>
Expand Down
13 changes: 11 additions & 2 deletions cmd/render.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ type Post struct {
Title string
Link string
PermaLink string
FirstPostLink string
LastPostLink string
PreviousPostLink string
NextPostLink string
HomeLink string
Expand Down Expand Up @@ -190,11 +192,18 @@ var renderCmd = &cobra.Command{
continue
}

if i != 0 {
posts[i].FirstPostLink = posts[0].Link
}

if i != len(posts)-1 {
// can't be -1 as loop would've been skipped if so
posts[i].LastPostLink = posts[len(posts)-1].Link
}

if nextPost >= 0 {
posts[i].NextPostLink = posts[nextPost].Link
posts[nextPost].PreviousPostLink = posts[i].Link

fmt.Println(posts[i].Title, "<->", posts[nextPost].Title)
}
nextPost = i
}
Expand Down

0 comments on commit 5d5802c

Please sign in to comment.