mirror of
https://git.sr.ht/~adnano/kiln
synced 2024-10-30 01:13:08 +00:00
page: Ability to specify build tasks per page
Implements: https://todo.sr.ht/~adnano/kiln/15
This commit is contained in:
parent
40d0833127
commit
ecd9f72eeb
|
@ -4,6 +4,7 @@ title = "Example website"
|
|||
"/" = "/{{ .Date.Format `2006/01/02` }}/{{ path.Base .Path }}/"
|
||||
|
||||
[[tasks]]
|
||||
name = "Gemini"
|
||||
url = "gemini://example.com"
|
||||
input = [".gmi"]
|
||||
output = ".gmi"
|
||||
|
|
|
@ -120,6 +120,22 @@ The following keys are supported:
|
|||
---
|
||||
```
|
||||
|
||||
*outputs*
|
||||
Optionally specifies a list of tasks that can build this page. Defaults to
|
||||
all tasks.
|
||||
|
||||
Example:
|
||||
|
||||
```
|
||||
---
|
||||
outputs: ["Gemini", "HTTPS"]
|
||||
---
|
||||
|
||||
---
|
||||
outputs: [] # Excluded from all tasks
|
||||
---
|
||||
```
|
||||
|
||||
*params*
|
||||
Specifies extra parameters to be provided to templates.
|
||||
|
||||
|
@ -211,6 +227,19 @@ Tasks can be specified in the [[tasks]] array of tables.
|
|||
|
||||
The following configuration options are supported per task:
|
||||
|
||||
*name*
|
||||
An optional name for the task.
|
||||
|
||||
Example:
|
||||
|
||||
```
|
||||
[[tasks]]
|
||||
name = "Gemini"
|
||||
|
||||
[[tasks]]
|
||||
name = "HTML export"
|
||||
```
|
||||
|
||||
*input*
|
||||
A list of input file extensions. Files in the content directory with a
|
||||
matching extension will be processed.
|
||||
|
|
40
page.go
40
page.go
|
@ -18,18 +18,19 @@ import (
|
|||
|
||||
// Page represents a page.
|
||||
type Page struct {
|
||||
Title string
|
||||
Date time.Time
|
||||
Weight int
|
||||
Params map[string]interface{}
|
||||
Path string `yaml:"-"`
|
||||
FilePath string `yaml:"-"`
|
||||
URL string `yaml:"-"`
|
||||
Content string `yaml:"-"`
|
||||
Prev *Page `yaml:"-"`
|
||||
Next *Page `yaml:"-"`
|
||||
Pages []*Page `yaml:"-"`
|
||||
Dirs []*Page `yaml:"-"`
|
||||
Title string `yaml:"title"`
|
||||
Date time.Time `yaml:"date"`
|
||||
Weight int `yaml:"weight"`
|
||||
Outputs []string `yaml:"outputs"`
|
||||
Params map[string]interface{} `yaml:"params"`
|
||||
Path string `yaml:"-"`
|
||||
FilePath string `yaml:"-"`
|
||||
URL string `yaml:"-"`
|
||||
Content string `yaml:"-"`
|
||||
Prev *Page `yaml:"-"`
|
||||
Next *Page `yaml:"-"`
|
||||
Pages []*Page `yaml:"-"`
|
||||
Dirs []*Page `yaml:"-"`
|
||||
feeds map[string][]byte
|
||||
index bool
|
||||
}
|
||||
|
@ -113,6 +114,21 @@ func (p *Page) _read(fsys fs.FS, path string, task *Task, cfg *Site) error {
|
|||
if len(frontmatter) != 0 {
|
||||
if err := yaml.Unmarshal(frontmatter, page); err != nil {
|
||||
log.Printf("failed to parse frontmatter for %q: %v", path, err)
|
||||
} else if page.Outputs != nil {
|
||||
// Enforce page outputs
|
||||
if len(page.Outputs) == 0 || task.Name == "" {
|
||||
continue
|
||||
}
|
||||
found := false
|
||||
for _, output := range page.Outputs {
|
||||
if output == task.Name {
|
||||
found = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if !found {
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
// Trim leading newlines from content
|
||||
|
|
Loading…
Reference in a new issue