i have flu
This commit is contained in:
248
blog/routes.go
248
blog/routes.go
@@ -1,6 +1,7 @@
|
||||
package blog
|
||||
|
||||
import (
|
||||
"embed"
|
||||
"html/template"
|
||||
"log"
|
||||
"net/http"
|
||||
@@ -8,197 +9,38 @@ import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
const pageTpl = `<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>{{.Title}}</title>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
{{if .Post.HTML}}
|
||||
<meta name="description" content="{{.Post.Description}}">
|
||||
<meta property="og:title" content="{{.Post.Title}}">
|
||||
<meta property="og:description" content="{{.Post.Description}}">
|
||||
<meta property="og:type" content="article">
|
||||
<meta property="og:url" content="https://chaosmith.systems/blog/posts/{{.Post.Slug}}">
|
||||
<meta property="og:image" content="https://chaosmith.systems{{.Post.OGImage}}">
|
||||
<meta property="og:site_name" content="Chaosmith Systems">
|
||||
<meta property="article:published_time" content="{{.Post.Date.Format "2006-01-02T15:04:05Z07:00"}}">
|
||||
<meta name="twitter:card" content="summary_large_image">
|
||||
<meta name="twitter:title" content="{{.Post.Title}}">
|
||||
<meta name="twitter:description" content="{{.Post.Description}}">
|
||||
<meta name="twitter:image" content="https://chaosmith.systems{{.Post.OGImage}}">
|
||||
{{else}}
|
||||
<meta property="og:title" content="{{.Title}}">
|
||||
<meta property="og:type" content="website">
|
||||
<meta property="og:url" content="https://chaosmith.systems/blog/">
|
||||
<meta property="og:site_name" content="Chaosmith Systems">
|
||||
<meta name="twitter:card" content="summary">
|
||||
{{end}}
|
||||
<link rel="stylesheet" href="/src/thirdparty/fonts/fonts.css" media="print" onload="this.media='all'">
|
||||
<link rel="alternate" type="application/rss+xml" title="Chaosmith Systems — Field Notes" href="/blog/feed.xml">
|
||||
<link rel="alternate" type="application/feed+json" title="Chaosmith Systems — Field Notes (JSON)" href="/blog/feed.json">
|
||||
<link rel="stylesheet" href="/src/thirdparty/highlight/default.min.css" media="print" onload="this.media='all'">
|
||||
<script defer src="/src/thirdparty/highlight/highlight.min.js"></script>
|
||||
<script defer src="/src/lang/ergon.js"></script>
|
||||
<script defer src="/src/lang/archasm.js"></script>
|
||||
<style>
|
||||
:root {
|
||||
--bg: #05030a;
|
||||
--accent: #b574ff;
|
||||
--accent-soft: rgba(181, 116, 255, 0.12);
|
||||
--text: #f3f0ff;
|
||||
--text-dim: #a9a3c4;
|
||||
--border: rgba(255, 255, 255, 0.06);
|
||||
}
|
||||
* { box-sizing: border-box; }
|
||||
body {
|
||||
margin: 0; min-height: 100vh;
|
||||
background: radial-gradient(circle at top, #1a1035 0, #05030a 55%);
|
||||
color: var(--text);
|
||||
font-family: "Inter", system-ui, sans-serif;
|
||||
display: flex; justify-content: center;
|
||||
}
|
||||
.wrap { position: relative; z-index: 1; width: 100%; max-width: 1040px; padding: 32px 20px 40px; }
|
||||
header {
|
||||
display: flex; justify-content: space-between; align-items: center;
|
||||
gap: 24px; padding: 18px 22px; border-radius: 18px;
|
||||
border: 1px solid var(--border);
|
||||
background: linear-gradient(135deg, rgba(255,255,255,0.02), rgba(0,0,0,0.35));
|
||||
backdrop-filter: blur(18px);
|
||||
}
|
||||
.logo-mark {
|
||||
width: 44px; height: 44px; border-radius: 14px;
|
||||
border: 1px solid rgba(181,116,255,0.7);
|
||||
background: radial-gradient(circle at 20% 0, rgba(255,255,255,0.25), transparent 55%),
|
||||
radial-gradient(circle at 80% 100%, rgba(181,116,255,0.9), transparent 60%);
|
||||
display: flex; align-items: center; justify-content: center;
|
||||
font-family: "JetBrains Mono", monospace; font-weight: 600; font-size: 20px;
|
||||
}
|
||||
.logo-mark a { color: inherit; text-decoration: none; }
|
||||
nav { display: flex; gap: 16px; align-items: center; }
|
||||
nav a { color: var(--text-dim); text-decoration: none; font-size: 13px; text-transform: uppercase; letter-spacing: 0.1em; }
|
||||
nav a:hover { color: var(--accent); }
|
||||
main { margin-top: 24px; }
|
||||
.post-list { list-style: none; padding: 0; margin: 0; }
|
||||
.post-list li { padding: 12px 0; border-top: 1px solid var(--border); }
|
||||
.post-list li:first-child { border-top: 0; }
|
||||
.post-list a { color: var(--text); text-decoration: none; font-size: 16px; }
|
||||
.post-list a:hover { color: var(--accent); }
|
||||
.article h1 { font-size: 28px; margin: 0 0 4px; }
|
||||
.post-date { display: block; font-size: 13px; color: var(--text-dim); margin-bottom: 24px; }
|
||||
.post-date-inline { font-size: 12px; color: var(--text-dim); }
|
||||
.article p { line-height: 1.7; color: var(--text-dim); }
|
||||
.article pre {
|
||||
background: rgba(0,0,0,0.5); border: 1px solid var(--border);
|
||||
border-radius: 12px; padding: 16px; overflow-x: auto;
|
||||
}
|
||||
.article code { font-family: "JetBrains Mono", monospace; font-size: 13px; }
|
||||
.article a { color: var(--accent); }
|
||||
.article img { max-width: 100%; border-radius: 12px; }
|
||||
.article blockquote {
|
||||
border-left: 3px solid var(--accent); margin: 0; padding: 4px 16px;
|
||||
color: var(--text-dim);
|
||||
}
|
||||
.article h1 { color: var(--text); }
|
||||
.article h2, .article h3 { color: var(--accent); }
|
||||
.article ul, .article ol { color: var(--text-dim); line-height: 1.7; }
|
||||
.article details {
|
||||
border: 1px solid var(--border); border-radius: 12px;
|
||||
background: rgba(0,0,0,0.4); margin: 20px 0;
|
||||
overflow: hidden;
|
||||
}
|
||||
.article details summary {
|
||||
cursor: pointer; padding: 14px 18px; font-size: 14px;
|
||||
color: var(--accent); user-select: none; line-height: 1.5;
|
||||
background: linear-gradient(135deg, rgba(181,116,255,0.06), rgba(0,0,0,0.5));
|
||||
list-style: none;
|
||||
}
|
||||
.article details summary::-webkit-details-marker { display: none; }
|
||||
.article details summary::before { content: '▸ '; font-size: 12px; }
|
||||
.article details[open] summary::before { content: '▾ '; }
|
||||
.article details summary:hover { color: var(--text); }
|
||||
.article details[open] summary { border-bottom: 1px solid var(--border); }
|
||||
.article details[open] {
|
||||
color: var(--text-dim); line-height: 1.7; font-size: 14px;
|
||||
}
|
||||
.article details[open] > *:not(summary) {
|
||||
display: block; padding: 14px 18px;
|
||||
}
|
||||
footer { margin-top: 30px; font-size: 11px; color: var(--text-dim); display: flex; justify-content: space-between; padding: 4px 2px; }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="wrap">
|
||||
<header>
|
||||
<div style="display:flex; gap:14px; align-items:center;">
|
||||
<div class="logo-mark"><a href="/blog/">CS</a></div>
|
||||
<nav>
|
||||
<a href="/" hx-get="/" hx-target="main" hx-push-url="true">Home</a>
|
||||
<a href="/blog/" hx-get="/blog/" hx-target="main" hx-push-url="true">Blog</a>
|
||||
</nav>
|
||||
</div>
|
||||
<a href="/blog/feed.xml" style="margin-left:auto; font-size:13px; text-transform:uppercase; letter-spacing:0.1em; color:var(--text-dim); text-decoration:none;" hx-boost="false">RSS</a>
|
||||
</header>
|
||||
<main>
|
||||
{{if .Post.HTML}}
|
||||
<article class="article">
|
||||
<h1>{{.Post.Title}}</h1>
|
||||
<time class="post-date">{{.Post.Date.Format "January 2, 2006"}}</time>
|
||||
{{.Post.HTML | safehtml}}
|
||||
</article>
|
||||
{{else}}
|
||||
<h1>Field Notes</h1>
|
||||
{{if .Posts}}
|
||||
<ul class="post-list">
|
||||
{{range .Posts}}
|
||||
<li>
|
||||
<a href="/blog/posts/{{.Slug}}" hx-get="/blog/posts/{{.Slug}}" hx-target="main" hx-push-url="true">{{.Title}}</a>
|
||||
<span class="post-date-inline">{{.Date.Format "Jan 2, 2006"}}</span>
|
||||
</li>
|
||||
{{end}}
|
||||
</ul>
|
||||
{{else}}
|
||||
<p style="color: var(--text-dim);">No posts yet.</p>
|
||||
{{end}}
|
||||
{{end}}
|
||||
</main>
|
||||
<footer>
|
||||
<span>Running on self-hosted infrastructure.</span>
|
||||
<span>Chaosmith Systems</span>
|
||||
</footer>
|
||||
</div>
|
||||
<script>
|
||||
function initPage(){hljs.highlightAll();}
|
||||
window.addEventListener('DOMContentLoaded',initPage);
|
||||
document.body.addEventListener('htmx:afterSwap',initPage);
|
||||
</script>
|
||||
</body>
|
||||
</html>`
|
||||
//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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user