mirror of
https://git.sr.ht/~adnano/kiln
synced 2024-10-30 01:13:08 +00:00
Implement static directory support
This commit is contained in:
parent
5719af8727
commit
4ec169afdc
|
@ -27,6 +27,7 @@ type Task struct {
|
||||||
Output string `toml:"output"` // output file extension
|
Output string `toml:"output"` // output file extension
|
||||||
Template string `toml:"template"` // template file extension
|
Template string `toml:"template"` // template file extension
|
||||||
PostProcess string `toml:"postprocess"` // postprocess directive
|
PostProcess string `toml:"postprocess"` // postprocess directive
|
||||||
|
Static string `toml:"static"` // static file directory
|
||||||
Destination string `toml:"destination"` // destination directory
|
Destination string `toml:"destination"` // destination directory
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -58,6 +59,7 @@ func DefaultConfig() *Config {
|
||||||
Input: ".gmi",
|
Input: ".gmi",
|
||||||
Output: ".gmi",
|
Output: ".gmi",
|
||||||
Template: ".gmi",
|
Template: ".gmi",
|
||||||
|
Static: "static",
|
||||||
Destination: "public",
|
Destination: "public",
|
||||||
}
|
}
|
||||||
return c
|
return c
|
||||||
|
|
39
main.go
39
main.go
|
@ -3,7 +3,12 @@ package main
|
||||||
import (
|
import (
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"io/fs"
|
||||||
"log"
|
"log"
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
@ -71,5 +76,39 @@ func runTask(cfg *Config, task *Task) error {
|
||||||
if err := dir.write(task.Destination, task); err != nil {
|
if err := dir.write(task.Destination, task); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
// Copy static files
|
||||||
|
if task.Static != "" {
|
||||||
|
err := copyAll(task.Static, task.Destination)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func copyAll(srcDir, dstDir string) error {
|
||||||
|
return filepath.Walk(srcDir, func(path string, info fs.FileInfo, err error) error {
|
||||||
|
if info.IsDir() {
|
||||||
|
// Do nothing
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
src, err := os.Open(path)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer src.Close()
|
||||||
|
|
||||||
|
dstPath := filepath.Join(dstDir, strings.TrimPrefix(path, srcDir))
|
||||||
|
dst, err := os.Create(dstPath)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer dst.Close()
|
||||||
|
|
||||||
|
if _, err := io.Copy(dst, src); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue