diff --git a/config.go b/config.go index 5f9f772..dac1977 100644 --- a/config.go +++ b/config.go @@ -66,6 +66,5 @@ func (c *Config) LoadTemplates(path string) error { } }, }) - c.Templates.LoadDefault() return c.Templates.Load(path) } diff --git a/main.go b/main.go index c8cd6e7..70e2fe0 100644 --- a/main.go +++ b/main.go @@ -1,6 +1,7 @@ package main import ( + "embed" "flag" "fmt" "io" @@ -138,11 +139,15 @@ func copyAll(srcDir, dstDir string) error { }) } +//go:embed templates config.toml +var builtin embed.FS + 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, "templates/_default"), 0755) os.Mkdir(path.Join(name, "static"), 0755) config, _ := builtin.ReadFile("config.toml") @@ -150,4 +155,10 @@ func newSite(name string) { index := []byte("# Hello, world!\n") os.WriteFile(path.Join(name, "content/index.gmi"), index, 0644) + + templates := []string{"atom.xml", "index.gmi", "page.gmi"} + for _, template := range templates { + b, _ := builtin.ReadFile(path.Join("templates", template)) + os.WriteFile(path.Join(name, "templates/_default", template), b, 0644) + } } diff --git a/templates.go b/templates.go index 83a9a4d..1423e3a 100644 --- a/templates.go +++ b/templates.go @@ -1,7 +1,6 @@ package main import ( - "embed" "io/ioutil" "log" "os" @@ -11,9 +10,6 @@ import ( "text/template" ) -//go:embed templates config.toml -var builtin embed.FS - // Templates contains site templates. type Templates struct { tmpls map[string]*template.Template @@ -33,23 +29,6 @@ func (t *Templates) Funcs(funcs template.FuncMap) { t.funcs = funcs } -// LoadDefault loads the default templates. -// Should be called after Funcs. -func (t *Templates) LoadDefault() { - t.loadDefault("index.gmi") - t.loadDefault("page.gmi") - t.loadDefault("atom.xml") - t.loadDefault("output.html") -} - -func (t *Templates) loadDefault(name string) { - b, err := builtin.ReadFile("templates/" + name) - if err != nil { - panic(err) - } - t.LoadTemplate("/_default/"+name, b) -} - // LoadTemplate loads a template from the provided path and content. func (t *Templates) LoadTemplate(path string, content []byte) { tmpl := template.New(path) diff --git a/templates/output.html b/templates/output.html deleted file mode 100644 index 513c17c..0000000 --- a/templates/output.html +++ /dev/null @@ -1,6 +0,0 @@ - - - -{{ .Title }} - -{{ .Content }}