Skip to content

Commit

Permalink
parallelized RenderTags
Browse files Browse the repository at this point in the history
  • Loading branch information
DedLad committed Apr 9, 2024
1 parent 0af56cf commit 84a7728
Showing 1 changed file with 24 additions and 12 deletions.
36 changes: 24 additions & 12 deletions pkg/engine/anna_engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"slices"
"sort"
"strings"
"sync"
"time"

"github.com/acmpesuecc/anna/pkg/helpers"
Expand Down Expand Up @@ -47,20 +48,31 @@ func (e *Engine) RenderTags(fileOutPath string, templ *template.Template) {
e.ErrorLogger.Fatal(err)
}

// Create a wait group to wait for all goroutines to finish
var wg sync.WaitGroup

// Rendering the subpages with merged tagged posts
for tag, taggedTemplates := range e.TagsMap {
pagePath := "tags/" + tag
templateData := parser.TemplateData{
FilenameWithoutExtension: tag,
Layout: e.LayoutConfig,
Frontmatter: parser.Frontmatter{
Title: tag,
},
SpecificTagTemplates: taggedTemplates,
}

e.RenderPage(fileOutPath, template.URL(pagePath), templateData, templ, "tag-subpage")
}
wg.Add(1)
go func(tag string, taggedTemplates []parser.TemplateData) {
defer wg.Done()

pagePath := "tags/" + tag
templateData := parser.TemplateData{
FilenameWithoutExtension: tag,
Layout: e.LayoutConfig,
Frontmatter: parser.Frontmatter{
Title: tag,
},
SpecificTagTemplates: taggedTemplates,
}

e.RenderPage(fileOutPath, template.URL(pagePath), templateData, templ, "tag-subpage")
}(tag, taggedTemplates)
}

// Wait for all goroutines to finish
wg.Wait()
}

func (e *Engine) GenerateJSONIndex(outFilePath string) {
Expand Down

0 comments on commit 84a7728

Please sign in to comment.