diff --git a/config.toml b/config.toml new file mode 100644 index 0000000..9c9e96c --- /dev/null +++ b/config.toml @@ -0,0 +1,16 @@ +# Site title +title = "" +# Site URLs +urls = [] + +# Site feeds +[feeds] +# "/blog/" = "Example blog" + +# Site tasks +[tasks.gemini] +input_ext = ".gmi" +output_ext = ".gmi" +template_ext = ".gmi" +static_dir = "static" +output_dir = "public" diff --git a/doc/kiln.1.scd b/doc/kiln.1.scd index 2dd00f0..1434f58 100644 --- a/doc/kiln.1.scd +++ b/doc/kiln.1.scd @@ -6,14 +6,30 @@ kiln - a simple static site generator # SYNOPSIS -_kiln_ [-c ] [-t ] +*kiln* build++ + [-c _config_]++ + [-t _task_] + +*kiln* new _path_ + +*kiln* version + +# DESCRIPTION + +*kiln build* builds a kiln site. + +*kiln new* creates a new kiln site at the given path. + +*kiln version* prints version information for the *kiln* program. # OPTIONS -\-c +## kiln build + +*-c* _config_ Specifies the configuration file to use. Defaults to "config.toml". -\-t +*-t* _task_ Specifies the task to run. Defaults to "all", which runs all tasks. # OVERVIEW diff --git a/main.go b/main.go index 857b153..1772936 100644 --- a/main.go +++ b/main.go @@ -7,6 +7,7 @@ import ( "io/fs" "log" "os" + "path" "path/filepath" "strings" ) @@ -16,22 +17,38 @@ var ( ) func main() { + if len(os.Args) >= 2 { + switch os.Args[1] { + case "build": + build() + return + case "new": + if len(os.Args) < 3 { + fmt.Println("usage: kiln new ") + os.Exit(1) + } + newSite(os.Args[2]) + return + case "version": + fmt.Println("kiln", Version) + return + } + } + + fmt.Println("usage: kiln args...") + os.Exit(1) +} + +func build() { var ( - task string - config string - version bool + task string + config string ) flag.StringVar(&task, "t", "all", "the task to run") flag.StringVar(&config, "c", "config.toml", "the configuration file to use") - flag.BoolVar(&version, "v", false, "print version") flag.Parse() - if version { - fmt.Println("kiln", Version) - return - } - // Load config cfg, err := LoadConfig(config) if err != nil { @@ -123,3 +140,17 @@ func copyAll(srcDir, dstDir string) error { return nil }) } + +func newSite(name string) { + name = path.Clean(name) + os.Mkdir(name, 0755) + os.Mkdir(path.Join(name, "content"), 0755) + os.Mkdir(path.Join(name, "templates"), 0755) + os.Mkdir(path.Join(name, "static"), 0755) + + config, _ := builtin.ReadFile("config.toml") + os.WriteFile(path.Join(name, "config.toml"), config, 0644) + + index := []byte("# Hello, world!\n") + os.WriteFile(path.Join(name, "content/index.gmi"), index, 0644) +} diff --git a/templates.go b/templates.go index c3977a5..83a9a4d 100644 --- a/templates.go +++ b/templates.go @@ -11,8 +11,8 @@ import ( "text/template" ) -//go:embed templates -var builtinTemplates embed.FS +//go:embed templates config.toml +var builtin embed.FS // Templates contains site templates. type Templates struct { @@ -43,7 +43,7 @@ func (t *Templates) LoadDefault() { } func (t *Templates) loadDefault(name string) { - b, err := builtinTemplates.ReadFile("templates/" + name) + b, err := builtin.ReadFile("templates/" + name) if err != nil { panic(err) }