1
0
Fork 0
mirror of https://git.sr.ht/~adnano/kiln synced 2024-05-14 20:46:05 +02:00

Add 'kiln new' command

This commit is contained in:
Adnan Maolood 2021-04-20 16:00:39 -04:00
parent d2bbec49d9
commit c9004640db
4 changed files with 78 additions and 15 deletions

16
config.toml Normal file
View File

@ -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"

View File

@ -6,14 +6,30 @@ kiln - a simple static site generator
# SYNOPSIS
_kiln_ [-c <config>] [-t <task>]
*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 <config>
## kiln build
*-c* _config_
Specifies the configuration file to use. Defaults to "config.toml".
\-t <task>
*-t* _task_
Specifies the task to run. Defaults to "all", which runs all tasks.
# OVERVIEW

49
main.go
View File

@ -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 <path>")
os.Exit(1)
}
newSite(os.Args[2])
return
case "version":
fmt.Println("kiln", Version)
return
}
}
fmt.Println("usage: kiln <build | new | version> 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)
}

View File

@ -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)
}