1
0
Fork 0
mirror of https://git.sr.ht/~adnano/kiln synced 2024-06-07 19:46:06 +02:00

dir: Avoid looping through all the feeds

Maintain a map of feeds to avoid looping through all the configured
feeds for a task.
This commit is contained in:
adnano 2021-09-02 23:41:52 -04:00
parent 2ef8f77d24
commit bad156cad3
2 changed files with 11 additions and 8 deletions

10
dir.go
View File

@ -153,14 +153,8 @@ func (d *Dir) _read(srcDir, path string, task *Task, cfg *Site) error {
// process processes the directory's contents.
func (d *Dir) process(cfg *Site, task *Task) error {
// build feeds
// this must happen before the page processing
// to have an unprocessed Page.Content
// 192: d.Pages[i].Content = b.String()
for _, feed := range task.Feeds {
if d.path != feed.InputDir {
continue
}
// Build feeds before templates are applied to the page contents
for _, feed := range task.feeds[d.path] {
b, err := d.buildFeed(cfg, feed)
if err != nil {
return err

View File

@ -35,6 +35,7 @@ type Task struct {
OutputDir string `toml:"output_dir"` // output directory
UglyURLs bool `toml:"ugly_urls"` // whether to use ugly URLs
Feeds []Feed `toml:"feeds"`
feeds map[string][]Feed
}
type Feed struct {
@ -91,6 +92,14 @@ func LoadSite(config string) (*Site, error) {
return nil, err
}
// Populate task feeds map
for _, task := range site.Tasks {
task.feeds = map[string][]Feed{}
for _, feed := range task.Feeds {
task.feeds[feed.InputDir] = append(task.feeds[feed.InputDir], feed)
}
}
// deprecate [feeds]
if len(site.Feeds) > 0 {
log.Println("The [feeds] configuration is deprecated")