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
78a05c255b
commit
08a6823148
|
@ -27,6 +27,7 @@ type Task struct {
|
|||
Output string `toml:"output"` // output file extension
|
||||
Template string `toml:"template"` // template file extension
|
||||
PostProcess string `toml:"postprocess"` // postprocess directive
|
||||
Static string `toml:"static"` // static file directory
|
||||
Destination string `toml:"destination"` // destination directory
|
||||
}
|
||||
|
||||
|
@ -58,6 +59,7 @@ func DefaultConfig() *Config {
|
|||
Input: ".gmi",
|
||||
Output: ".gmi",
|
||||
Template: ".gmi",
|
||||
Static: "static",
|
||||
Destination: "public",
|
||||
}
|
||||
return c
|
||||
|
|
39
main.go
39
main.go
|
@ -3,7 +3,12 @@ package main
|
|||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/fs"
|
||||
"log"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
@ -71,5 +76,39 @@ func runTask(cfg *Config, task *Task) error {
|
|||
if err := dir.write(task.Destination, task); err != nil {
|
||||
return err
|
||||
}
|
||||
// Copy static files
|
||||
if task.Static != "" {
|
||||
err := copyAll(task.Static, task.Destination)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
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