From 35191db4fb480d022b6ad2a06fb5b847bac1192f Mon Sep 17 00:00:00 2001 From: Pierre De Lancre Date: Sun, 28 Jun 2026 09:50:02 +0300 Subject: [PATCH] i have flu --- blog/routes.go | 248 +++++------------------------------- blog/templates/base.html | 217 +++++++++++++++++++++++++++++++ blog/templates/landing.html | 70 ++++++++++ blog/templates/main.html | 25 ++++ index.html | 2 +- main.go | 6 +- 6 files changed, 348 insertions(+), 220 deletions(-) create mode 100644 blog/templates/base.html create mode 100644 blog/templates/landing.html create mode 100644 blog/templates/main.html diff --git a/blog/routes.go b/blog/routes.go index da61360..30166b3 100644 --- a/blog/routes.go +++ b/blog/routes.go @@ -1,6 +1,7 @@ package blog import ( + "embed" "html/template" "log" "net/http" @@ -8,197 +9,38 @@ import ( "strings" ) -const pageTpl = ` - - - - {{.Title}} - - {{if .Post.HTML}} - - - - - - - - - - - - - {{else}} - - - - - - {{end}} - - - - - - - - - - -
-
-
- - -
- RSS -
-
- {{if .Post.HTML}} -
-

{{.Post.Title}}

- - {{.Post.HTML | safehtml}} -
- {{else}} -

Field Notes

- {{if .Posts}} -
    - {{range .Posts}} -
  • - {{.Title}} - -
  • - {{end}} -
- {{else}} -

No posts yet.

- {{end}} - {{end}} -
-
- Running on self-hosted infrastructure. - Chaosmith Systems -
-
- - -` +//go:embed templates/*.html +var templateFS embed.FS type pageData struct { Title string Posts []Post Post Post + PostList bool ActiveSlug string } -var tmpl *template.Template - func safehtml(s string) template.HTML { return template.HTML(s) } +var tmpl *template.Template + func init() { var err error - tmpl, err = template.New("blog").Funcs(template.FuncMap{"safehtml": safehtml}).Parse(pageTpl) + tmpl, err = template.New("").Funcs(template.FuncMap{"safehtml": safehtml}).ParseFS(templateFS, "templates/*.html") if err != nil { panic(err) } } -func render(w http.ResponseWriter, data pageData) { +func render(w http.ResponseWriter, r *http.Request, data pageData) { w.Header().Set("Content-Type", "text/html; charset=utf-8") - tmpl.Execute(w, data) + if r.Header.Get("HX-Request") == "true" { + tmpl.ExecuteTemplate(w, "main-content", data) + return + } + tmpl.ExecuteTemplate(w, "base.html", data) } func RegisterRoutes(mux *http.ServeMux, contentDir string) error { @@ -235,7 +77,7 @@ func RegisterRoutes(mux *http.ServeMux, contentDir string) error { http.NotFound(w, r) return } - render(w, pageData{ + render(w, r, pageData{ Title: p.Title + " — Chaosmith Systems", Posts: store.All(), Post: p, @@ -247,72 +89,46 @@ func RegisterRoutes(mux *http.ServeMux, contentDir string) error { http.NotFound(w, r) return } - render(w, pageData{ - Title: "Chaosmith Systems — Field Notes", - Posts: store.All(), + render(w, r, pageData{ + Title: "Chaosmith Systems — Field Notes", + Posts: store.All(), + PostList: true, }) }) - // RSS feed mux.HandleFunc("/blog/feed.xml", func(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Type", "application/rss+xml; charset=utf-8") w.Write([]byte(generateRSS(store))) }) - // JSON feed mux.HandleFunc("/blog/feed.json", func(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Type", "application/feed+json; charset=utf-8") w.Write([]byte(generateJSONFeed(store))) }) - // Sitemap mux.HandleFunc("/sitemap.xml", func(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Type", "application/xml; charset=utf-8") w.Write([]byte(generateSitemap(store))) }) - // robots.txt mux.HandleFunc("/robots.txt", func(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Type", "text/plain") - w.Write([]byte(`User-agent: * -Allow: / - -Sitemap: https://chaosmith.systems/sitemap.xml - - -# +---------------------+ -# | | -# | | -# | | -# | _ | -# | .' '. | -# | .' '. | -# | .' '. | -# | .' '. | -# |.' ,-------. '.| -# | ,' . '. | -# | ( ( ) ) | -# | '. ' ,' | -# | '-------' | -# | | -# | +---------+ | -# | | AGIO | | -# | | RPC | | -# |\ +---------+ /| -# | \ .' | -# | '. / | -# | \ / | -# | \ / | -# | \ .' | -# | '. / | -# | \ / | -# | - | -# | | -# | | -# +---------------------+ -`)) + w.Write([]byte("User-agent: *\nAllow: /\n\nSitemap: https://chaosmith.systems/sitemap.xml\n")) }) log.Printf("blog: loaded %d post(s) from %s, mounted at /blog/", store.Count(), contentDir) return nil } + +func ServeLanding(w http.ResponseWriter, r *http.Request) { + if r.URL.Path != "/" { + http.NotFound(w, r) + return + } + data := pageData{Title: "Chaosmith Systems"} + if r.Header.Get("HX-Request") == "true" { + tmpl.ExecuteTemplate(w, "main-content", data) + return + } + tmpl.ExecuteTemplate(w, "base.html", data) +} diff --git a/blog/templates/base.html b/blog/templates/base.html new file mode 100644 index 0000000..83a38e2 --- /dev/null +++ b/blog/templates/base.html @@ -0,0 +1,217 @@ + + + + + {{.Title}} + + {{if .Post.HTML}} + + + + + + + + + + + + + {{else}} + + + + + + {{end}} + + + + + + + + + + + +
+
+
+ + +
+ RSS +
+
+ {{template "main-content" .}} +
+
+ Running on self-hosted infrastructure. + Chaosmith Systems +
+
+ + + diff --git a/blog/templates/landing.html b/blog/templates/landing.html new file mode 100644 index 0000000..35c40d4 --- /dev/null +++ b/blog/templates/landing.html @@ -0,0 +1,70 @@ +{{define "landing-content"}} +
+
+

Forging systems from controlled chaos.

+

+ Engineering, music, and experiments connected under one namespace. + This site is the central entry point to everything running on chaosmith.systems. +

+ +
+
+ Engineering + Modular input devices, VR / XR tooling, custom infra. +
+
+ Audio + Cinematic strings, deathstep textures, dreadful vibes. +
+
+ Labs + Prototypes, agents, data stacks, weird side projects. +
+
+ + +
+ + + +
+{{end}} diff --git a/blog/templates/main.html b/blog/templates/main.html new file mode 100644 index 0000000..46ad0b7 --- /dev/null +++ b/blog/templates/main.html @@ -0,0 +1,25 @@ +{{define "main-content"}} + {{if .Post.HTML}} +
+

{{.Post.Title}}

+ + {{.Post.HTML | safehtml}} +
+ {{else if .PostList}} +

Field Notes

+ {{if .Posts}} + + {{else}} +

No posts yet.

+ {{end}} + {{else}} + {{template "landing-content" .}} + {{end}} +{{end}} diff --git a/index.html b/index.html index 8c2e47a..56f90a7 100644 --- a/index.html +++ b/index.html @@ -377,7 +377,7 @@