diff --git a/CHANGELOG.md b/CHANGELOG.md index e152847..bff71da 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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* diff --git a/cmd/post.tmpl b/cmd/post.tmpl index a90bacf..266748e 100644 --- a/cmd/post.tmpl +++ b/cmd/post.tmpl @@ -75,6 +75,9 @@
+ {{if .FirstPostLink}} + << + {{end}} {{if .PreviousPostLink}} < {{end}} @@ -82,6 +85,9 @@ {{if .NextPostLink}} > {{end}} + {{if .LastPostLink}} + >> + {{end}}
{{.CreatedAt}} diff --git a/cmd/render.go b/cmd/render.go index 51346c5..f7f6d4d 100644 --- a/cmd/render.go +++ b/cmd/render.go @@ -53,6 +53,8 @@ type Post struct { Title string Link string PermaLink string + FirstPostLink string + LastPostLink string PreviousPostLink string NextPostLink string HomeLink string @@ -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 }