Skip to content

Commit eb025fe

Browse files
committed
change: only show visible articles in prev/next link
1 parent d25798d commit eb025fe

1 file changed

Lines changed: 22 additions & 7 deletions

File tree

render.go

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,28 @@ func RenderArticles(tpl template.Template, articles Collections) {
6666
for i := range articles {
6767
currentArticle := articles[i].(Article)
6868
var renderArticle = RenderArticle{currentArticle, nil, nil}
69-
if i >= 1 {
70-
article := articles[i-1].(Article)
71-
renderArticle.Prev = &article
72-
}
73-
if i <= articleCount-2 {
74-
article := articles[i+1].(Article)
75-
renderArticle.Next = &article
69+
// Only show next and prev article if it is not hidden
70+
if !renderArticle.Hide {
71+
if i >= 1 {
72+
// Find prev unhidden article
73+
for j := i - 1; j >= 0; j-- {
74+
prevArticle := articles[j].(Article)
75+
if !prevArticle.Hide {
76+
renderArticle.Prev = &prevArticle
77+
break
78+
}
79+
}
80+
}
81+
if i <= articleCount-2 {
82+
// Find next unhidden article
83+
for j := i + 1; j < articleCount; j++ {
84+
nextArticle := articles[j].(Article)
85+
if !nextArticle.Hide {
86+
renderArticle.Next = &nextArticle
87+
break
88+
}
89+
}
90+
}
7691
}
7792
outPath := filepath.Join(publicPath, currentArticle.Link)
7893
wg.Add(1)

0 commit comments

Comments
 (0)