switch to embedding blog template
parent
355af071eb
commit
8be261647c
62
genblog.go
62
genblog.go
|
@ -2,6 +2,7 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
_ "embed"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
@ -9,10 +10,11 @@ import (
|
||||||
"text/template"
|
"text/template"
|
||||||
)
|
)
|
||||||
|
|
||||||
//const statsPath = "/home/vilmibm/bin/townstats"
|
|
||||||
|
|
||||||
const statsPath = "/town/bin/stats"
|
const statsPath = "/town/bin/stats"
|
||||||
|
|
||||||
|
//go:embed blog.tmpl.html
|
||||||
|
var blogTmpl string
|
||||||
|
|
||||||
type newsEntry struct {
|
type newsEntry struct {
|
||||||
Title string `json:"title"` // Title of entry
|
Title string `json:"title"` // Title of entry
|
||||||
Pubdate string `json:"pubdate"` // Human readable date
|
Pubdate string `json:"pubdate"` // Human readable date
|
||||||
|
@ -29,63 +31,19 @@ func _main() error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
hypertextDocument := getHeader()
|
t, err := template.New("blog").Parse(blogTmpl)
|
||||||
|
|
||||||
for _, entry := range data.News {
|
|
||||||
entryHTML, err := renderEntry(entry)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return fmt.Errorf("failed to parse the blog template: %w", err)
|
||||||
}
|
|
||||||
|
|
||||||
hypertextDocument += entryHTML
|
|
||||||
}
|
|
||||||
|
|
||||||
hypertextDocument += getFooter()
|
|
||||||
|
|
||||||
fmt.Println(hypertextDocument)
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func renderEntry(entry newsEntry) (string, error) {
|
|
||||||
t, err := template.New("news").Parse(`
|
|
||||||
<h2>{{.Title}}</h2>
|
|
||||||
<em>{{.Pubdate}}</em>
|
|
||||||
{{.Content}}
|
|
||||||
`)
|
|
||||||
if err != nil {
|
|
||||||
return "", err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
out := bytes.Buffer{}
|
out := bytes.Buffer{}
|
||||||
err = t.Execute(&out, entry)
|
if err = t.Execute(&out, data); err != nil {
|
||||||
if err != nil {
|
return fmt.Errorf("failed to render blog template: %w", err)
|
||||||
return "", err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return out.String(), nil
|
fmt.Println(out.String())
|
||||||
}
|
|
||||||
|
|
||||||
func getHeader() string {
|
return nil
|
||||||
return `
|
|
||||||
<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<title>web log of tilde town</title>
|
|
||||||
<meta charset="UTF-8">
|
|
||||||
<link rel="icon" href="/favicon.ico">
|
|
||||||
<link rel="stylesheet" href="style.css">
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<h1>a web log for tilde town or at least what passes for one</h1>
|
|
||||||
`
|
|
||||||
}
|
|
||||||
|
|
||||||
func getFooter() string {
|
|
||||||
return `
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func stats() (*tildeData, error) {
|
func stats() (*tildeData, error) {
|
||||||
|
|
|
@ -89,7 +89,7 @@
|
||||||
|
|
||||||
<code>ssh join@tilde.town</code><br><br>
|
<code>ssh join@tilde.town</code><br><br>
|
||||||
-->
|
-->
|
||||||
if you think you might enjoy being a part of this community you can apply for a good time <a href="https://cgi.tilde.town/users/signup">using this form</a>.
|
if you think you might enjoy being a part of this community you can apply for a homestead <a href="https://cgi.tilde.town/users/signup">using this form</a>.
|
||||||
</p>
|
</p>
|
||||||
<p>
|
<p>
|
||||||
it can take up to 30 days to be approved and not all applications are approved.
|
it can take up to 30 days to be approved and not all applications are approved.
|
||||||
|
@ -111,7 +111,7 @@
|
||||||
</section>
|
</section>
|
||||||
<section id="donate">
|
<section id="donate">
|
||||||
<p>
|
<p>
|
||||||
the town is a non-commercial thing. <a href="https://patreon.com/nathanielksmith">donations</a> are appreciated
|
the town is a non-commercial thing. <a href="https://patreon.com/vilmibm">donations</a> are appreciated
|
||||||
</p>
|
</p>
|
||||||
</section>
|
</section>
|
||||||
<section id="lostkey">
|
<section id="lostkey">
|
||||||
|
|
Loading…
Reference in New Issue