diff --git a/genblog.go b/genblog.go index c68b3cb..27b0b88 100644 --- a/genblog.go +++ b/genblog.go @@ -2,6 +2,7 @@ package main import ( "bytes" + _ "embed" "encoding/json" "fmt" "os" @@ -9,10 +10,11 @@ import ( "text/template" ) -//const statsPath = "/home/vilmibm/bin/townstats" - const statsPath = "/town/bin/stats" +//go:embed blog.tmpl.html +var blogTmpl string + type newsEntry struct { Title string `json:"title"` // Title of entry Pubdate string `json:"pubdate"` // Human readable date @@ -29,63 +31,19 @@ func _main() error { return err } - hypertextDocument := getHeader() - - for _, entry := range data.News { - entryHTML, err := renderEntry(entry) - if err != nil { - return err - } - - hypertextDocument += entryHTML - } - - hypertextDocument += getFooter() - - fmt.Println(hypertextDocument) - - return nil -} - -func renderEntry(entry newsEntry) (string, error) { - t, err := template.New("news").Parse(` -

{{.Title}}

- {{.Pubdate}} - {{.Content}} -`) + t, err := template.New("blog").Parse(blogTmpl) if err != nil { - return "", err + return fmt.Errorf("failed to parse the blog template: %w", err) } out := bytes.Buffer{} - err = t.Execute(&out, entry) - if err != nil { - return "", err + if err = t.Execute(&out, data); err != nil { + return fmt.Errorf("failed to render blog template: %w", err) } - return out.String(), nil -} - -func getHeader() string { - return ` - - - - web log of tilde town - - - - - -

a web log for tilde town or at least what passes for one

-` -} + fmt.Println(out.String()) -func getFooter() string { - return ` - - -` + return nil } func stats() (*tildeData, error) { diff --git a/index.html b/index.html index 43f3536..1ae169d 100644 --- a/index.html +++ b/index.html @@ -89,7 +89,7 @@ ssh join@tilde.town

--> - if you think you might enjoy being a part of this community you can apply for a good time using this form. + if you think you might enjoy being a part of this community you can apply for a homestead using this form.

it can take up to 30 days to be approved and not all applications are approved. @@ -111,7 +111,7 @@