Add newer/older navigation to the photo detail page
Replace the standalone Back link with a three-cell nav row so each photo page links to its neighbours in the timeline. Prefetch the neighbouring pages and bind the arrow keys for keyboard navigation.
This commit is contained in:
1 parent
856439f3fd
commit
3639bd5577
3 files changed
+55
-11
No files matched your search
+12
-3
@@ -108,8 +108,15 @@ func (g *Generator) Build() error {
|
||||
if err := g.renderIndexPages(photos); err != nil {
|
||||
return err
|
||||
}
|
||||
for _, p := range photos {
|
||||
if err := g.renderPhotoPage(p); err != nil {
|
||||
for i := range photos {
|
||||
var newer, older *Photo
|
||||
if i > 0 {
|
||||
newer = &photos[i-1]
|
||||
}
|
||||
if i+1 < len(photos) {
|
||||
older = &photos[i+1]
|
||||
}
|
||||
if err := g.renderPhotoPage(photos[i], newer, older); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
@@ -358,13 +365,15 @@ func (g *Generator) renderIndexPages(photos []Photo) error {
|
||||
}
|
||||
|
||||
// renderPhotoPage writes public/photo/<slug>/index.html.
|
||||
func (g *Generator) renderPhotoPage(p Photo) error {
|
||||
func (g *Generator) renderPhotoPage(p Photo, newer, older *Photo) error {
|
||||
dir := filepath.Join(g.outputDir, "photo", p.Slug)
|
||||
if err := os.MkdirAll(dir, 0755); err != nil {
|
||||
return err
|
||||
}
|
||||
return g.render("photo.html", filepath.Join(dir, "index.html"), map[string]any{
|
||||
"Photo": p,
|
||||
"Newer": newer,
|
||||
"Older": older,
|
||||
"BaseURL": g.baseURL,
|
||||
"Year": time.Now().Year(),
|
||||
"Author": g.author,
|
||||
|
||||
Reference in new issue
Block a user