mirror of
https://git.sr.ht/~adnano/kiln
synced 2024-10-30 01:13:08 +00: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:
parent
2ef8f77d24
commit
bad156cad3
10
dir.go
10
dir.go
|
@ -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
|
||||
|
|
9
site.go
9
site.go
|
@ -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")
|
||||
|
|
Loading…
Reference in a new issue