aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--data.go13
-rw-r--r--dist/styles.css0
-rw-r--r--example.json9
-rw-r--r--main.go39
-rw-r--r--templates/base/base.gohtml (renamed from templates/page/base.gohtml)6
-rw-r--r--templates/base/opengraph.gohtml (renamed from templates/page/opengraph.gohtml)0
-rw-r--r--templates/page/index.gohtml12
7 files changed, 62 insertions, 17 deletions
diff --git a/data.go b/data.go
new file mode 100644
index 0000000..e1cbf37
--- /dev/null
+++ b/data.go
@@ -0,0 +1,13 @@
+package main
+
+type Data struct {
+ Image string `json:"image"`
+ Description string `json:"description"`
+ Person *Person `json:"person"`
+}
+
+type Person struct {
+ Name string `json:"name"`
+ Pronouns string `json:"pronouns"`
+ Image string `json:"image"`
+}
diff --git a/dist/styles.css b/dist/styles.css
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/dist/styles.css
diff --git a/example.json b/example.json
new file mode 100644
index 0000000..75e887e
--- /dev/null
+++ b/example.json
@@ -0,0 +1,9 @@
+{
+ "image": "",
+ "description": "",
+ "person": {
+ "name": "",
+ "pronouns": "",
+ "image": ""
+ }
+} \ No newline at end of file
diff --git a/main.go b/main.go
index 3c3d34b..50bc462 100644
--- a/main.go
+++ b/main.go
@@ -2,41 +2,58 @@ package main
import (
"embed"
+ "encoding/json"
"flag"
"github.com/anhgelus/golatt"
"log/slog"
+ "os"
)
//go:embed templates
var templates embed.FS
var (
- domain string
- data string
+ domain string
+ dataPath string
)
func init() {
flag.StringVar(&domain, "domain", "", "domain to use")
- flag.StringVar(&data, "data", "", "data to use")
+ flag.StringVar(&dataPath, "data", "", "data to use")
}
func main() {
flag.Parse()
if domain == "" {
- slog.Error("Domain not set. Set it with --domain value")
- return
+ domain = os.Getenv("NOW_DOMAIN")
+ if domain == "" {
+ slog.Error("Domain not set. Set it with --domain value or with the env NOW_DOMAIN")
+ return
+ }
}
- if data == "" {
- slog.Error("Data not set. Set it with --data relative path")
- return
+ if dataPath == "" {
+ dataPath = os.Getenv("NOW_DATA")
+ if dataPath == "" {
+ slog.Error("Data not set. Set it with --data relative path or with the env NOW_DATA")
+ return
+ }
+ }
+ b, err := os.ReadFile(dataPath)
+ if err != nil {
+ panic(err)
+ }
+ var data Data
+ err = json.Unmarshal(b, &data)
+ if err != nil {
+ panic(err)
}
g := golatt.New(templates)
g.DefaultSeoData = &golatt.SeoData{
- Image: "",
- Description: "",
+ Image: data.Image,
+ Description: data.Description,
Domain: domain,
}
- g.Templates = append(g.Templates, "templates/page/*.gohtml")
+ g.Templates = append(g.Templates, "templates/base/*.gohtml")
//g.StartServer(":80")
}
diff --git a/templates/page/base.gohtml b/templates/base/base.gohtml
index 2de2ba4..5859805 100644
--- a/templates/page/base.gohtml
+++ b/templates/base/base.gohtml
@@ -10,13 +10,7 @@
{{template "opengraph-base" .SEO}}
</head>
<body>
- {{if .Data.HasNav}}
- {{template "navbar" .}}
- {{end}}
{{template "body" .}}
- {{if .Data.HasFooter}}
- {{template "footer" .}}
- {{end}}
<script type="module" src="{{getAssetPath "index.js"}}" defer></script>
</body>
</html>
diff --git a/templates/page/opengraph.gohtml b/templates/base/opengraph.gohtml
index f51d561..f51d561 100644
--- a/templates/page/opengraph.gohtml
+++ b/templates/base/opengraph.gohtml
diff --git a/templates/page/index.gohtml b/templates/page/index.gohtml
new file mode 100644
index 0000000..dbc228a
--- /dev/null
+++ b/templates/page/index.gohtml
@@ -0,0 +1,12 @@
+{{define "body"}}
+ <main>
+ <div class="presentation">
+ <figure>
+ <img src="{{ getStaticPath .Person.Image }}" alt="{{ .Person.Name }}'s image">
+ </figure>
+ <h2>{{ .Person.Name }}</h2>
+ <p>{{ .Person.Pronouns }}</p>
+ </div>
+ <p class="description">{{ .Description }}</p>
+ </main>
+{{end}} \ No newline at end of file