Skip to content

Commit

Permalink
docs: sort posts
Browse files Browse the repository at this point in the history
  • Loading branch information
gernest committed Feb 17, 2024
1 parent 248467e commit 344a7f9
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 16 deletions.
17 changes: 3 additions & 14 deletions tools/docs/blog.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,32 +214,21 @@ func (ls Posts) Swap(i, j int) {
ls[i], ls[j] = ls[j], ls[i]
}

func (ls Posts) Timestamp() (o int64) {
for i, p := range ls {
if i == 0 {
o = p.Timestamp()
continue
}
o = max(o, p.Timestamp())
}
return
}

func (ls Posts) Sections() (o Sections) {
m := make(map[string]Posts)
for _, p := range ls {
m[p.Section] = append(m[p.Section], p)
}
for k, v := range m {
sort.Sort(v)
sort.Sort(sort.Reverse(v))
o = append(o, &Section{
Title: k,
URL: slug.Make(k),
Posts: v,
Timestamp: v.Timestamp(),
Timestamp: v[0].Timestamp(),
})
}
sort.Sort(o)
sort.Sort(sort.Reverse(o))
return
}

Expand Down
6 changes: 4 additions & 2 deletions tools/docs/post.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,16 @@
<p class="author"><span>{{.Date}}</span> by <span><i>{{.Author}}</i></span> </p>
{{.Content}}
{{end}}
{{range .Sections}}
<h2><a href="/blog/{{.URL}}" class="permalink">#</a>{{.Title}} </h2>
{{with .Sections}}
<ul>
{{range .}}
{{range .Posts}}
<li><a href="/blog/{{.URL}}"><i>{{.Date}}</i> - {{.Title}}</a> </li>
{{end}}
{{end}}
</ul>
{{end}}

{{with .Section}}
<h2><a href="/blog/{{.URL}}" class="permalink">#</a>{{.Title}} </h2>
<ul>
Expand Down

0 comments on commit 344a7f9

Please sign in to comment.