diff options
author | Eddy Pedroni <epedroni@pm.me> | 2025-04-08 17:01:55 +0200 |
---|---|---|
committer | Eddy Pedroni <epedroni@pm.me> | 2025-04-08 17:02:46 +0200 |
commit | 83d175b7b069bc3bbc0d600c2fab4d082e04b521 (patch) | |
tree | 9d1b7975ad16f7d5433285d3fab0a7cc38d24564 /template.go | |
parent | 38b40d8c5a8915716b3aa46aac4a0a84d0113b25 (diff) |
Python implementation with better multi-entry page support
Diffstat (limited to 'template.go')
-rw-r--r-- | template.go | 49 |
1 files changed, 0 insertions, 49 deletions
diff --git a/template.go b/template.go deleted file mode 100644 index 413c15f..0000000 --- a/template.go +++ /dev/null @@ -1,49 +0,0 @@ -package main - -import ( - "io/ioutil" - "os" - "path/filepath" - "strings" - "text/template" -) - -type templateData struct { - SiteTitle string - StylesheetUrl string - Nav []navItem - Content []string -} - -func loadTemplate(cfg config) (templ *template.Template) { - tmpl_raw, err := ioutil.ReadFile(cfg.TemplateFile) - if err != nil { - panic(err) - } - templ, err = template.New("template").Parse(string(tmpl_raw)) - if err != nil { - panic(err) - } - return -} - -func applyTemplate(dir string, data templateData, tmpl *template.Template) error { - // ensure directory exists - os.MkdirAll(strings.ToLower(dir), 0755) - file := filepath.Join(strings.ToLower(dir), "index.html") - - // create file, fail if it already exists - f, err := os.Create(file) - if err != nil { - return err - } - defer f.Close() - - // apply template, write to file - err = tmpl.Execute(f, data) - if err != nil { - return err - } - - return nil -} |