diff options
Diffstat (limited to 'hswg')
-rw-r--r-- | hswg/main.go | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/hswg/main.go b/hswg/main.go index 9fe3fd7..65557c5 100644 --- a/hswg/main.go +++ b/hswg/main.go @@ -17,6 +17,7 @@ import ( "regexp" "sort" "strings" + "sync" "syscall" "time" @@ -121,7 +122,7 @@ type Entry struct { // Published returns the date when the entry was published, or nil if unknown. func (e *Entry) Published() *time.Time { - if d, _, err := e.Attributes.GetAsString("date"); err != nil { + if d, ok, err := e.Attributes.GetAsString("date"); !ok || err != nil { return nil } else if t, err := time.Parse(time.RFC3339, d); err == nil { return &t @@ -287,14 +288,25 @@ func writeIndex(path string, t *template.Template, func finalizeEntries(entries *map[string]*Entry, t *template.Template, indexPath string, indexT *template.Template) { + // The initial render of a large amount of entries is resource-intensive. + var wg sync.WaitGroup for name, e := range *entries { e.backlinks = map[string]bool{} - if e.raw == nil { + if e.raw != nil { + continue + } + + wg.Add(1) + go func(name string, e *Entry) { + defer wg.Done() if err := renderEntry(name, e); err != nil { log.Printf("%s: %s\n", name, err) } - } + }(name, e) } + + wg.Wait() + for name, e := range *entries { // Expand LinkWords anywhere between <tags>. // We want something like the inverse of Regexp.ReplaceAllStringFunc. |