Skip to content

Commit

Permalink
blog/mataroa: remove iterators
Browse files Browse the repository at this point in the history
Let's make this blog compatible to Go 1.21 at minimum.
  • Loading branch information
thiagokokada committed Aug 23, 2024
1 parent c28d36e commit 67dbfba
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
6 changes: 4 additions & 2 deletions blog.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,8 @@ func genRss(ps posts) string {
))

var items []*feeds.Item
for path, post := range ps.ReverseIterator() {
for el := ps.Back(); el != nil; el = el.Prev() {
path, post := el.Key, el.Value
link := must1(url.JoinPath(blogMainUrl, path))
var buf bytes.Buffer
must(md.Convert(post.contents, &buf))
Expand All @@ -243,7 +244,8 @@ func genRss(ps posts) string {

func genReadme(ps posts) string {
var titles []string
for path, post := range ps.ReverseIterator() {
for el := ps.Back(); el != nil; el = el.Prev() {
path, post := el.Key, el.Value
title := fmt.Sprintf(
"- [%s](%s) - %s",
post.title,
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/thiagokokada/blog

go 1.23
go 1.21

require (
github.com/elliotchance/orderedmap/v2 v2.4.0
Expand Down
12 changes: 7 additions & 5 deletions mataroa.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,11 +132,12 @@ func prepareToMataroa(ps posts) posts {
)

preparedPosts := orderedmap.NewOrderedMap[path, post]()
for filename, p := range ps.Iterator() {
for el := ps.Front(); el != nil; el = el.Next() {
path, post := el.Key, el.Value
buf := bytes.Buffer{}
must(md.Convert([]byte(p.contents), &buf))
p.contents = buf.Bytes()
preparedPosts.Set(filename, p)
must(md.Convert([]byte(post.contents), &buf))
post.contents = buf.Bytes()
preparedPosts.Set(path, post)
}
return preparedPosts
}
Expand All @@ -146,7 +147,8 @@ func publishToMataroa(ps posts) {
log.Fatal("empty MATAROA_TOKEN environment variable")
}

for _, post := range prepareToMataroa(ps).Iterator() {
for el := prepareToMataroa(ps).Front(); el != nil; el = el.Next() {
post := el.Value
p, resp := must2(getMataroaPost(post.slug))
var err error
if p.Ok {
Expand Down

0 comments on commit 67dbfba

Please sign in to comment.