Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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