small pixel drawing of a pufferfish j3s.sh

in the beginning there was garbage
Jes Olson jolson@digitalocean.com
Fri, 28 Jan 2022 20:19:03 -0600
commit

04b4f4c8004a068aff84f1872094c7c98d2a8889

A go.mod

@@ -0,0 +1,3 @@

+module git.j3s.sh/j3s.sh + +go 1.16
A main.go

@@ -0,0 +1,56 @@

+package main + +import ( + "html/template" + "log" + "net/http" + "os" + "path/filepath" +) + +func main() { + fs := http.FileServer(http.Dir("./static")) + http.Handle("/static/", http.StripPrefix("/static/", fs)) + + http.HandleFunc("/", serveTemplate) + + log.Println("listening on :4666 tbh") + err := http.ListenAndServe(":4666", nil) + if err != nil { + log.Fatal(err) + } +} + +func serveTemplate(w http.ResponseWriter, r *http.Request) { + lp := filepath.Join("templates", "layout.html") + if r.URL.Path == "/" { + r.URL.Path = "index.html" + } + fp := filepath.Join("templates", filepath.Clean(r.URL.Path)) + + info, err := os.Stat(fp) + if err != nil { + if os.IsNotExist(err) { + http.NotFound(w, r) + return + } + } + + if info.IsDir() { + http.NotFound(w, r) + return + } + + tmpl, err := template.ParseFiles(lp, fp) + if err != nil { + log.Println(err.Error()) + http.Error(w, http.StatusText(500), 500) + return + } + + err = tmpl.ExecuteTemplate(w, "layout", nil) + if err != nil { + log.Println(err.Error()) + http.Error(w, http.StatusText(500), 500) + } +}
A templates/about.html

@@ -0,0 +1,4 @@

+{{define "title"}}small ideas{{end}} +{{define "body"}} +<p><i>shit-ass description of myself</p></i> +{{end}}
A templates/ideas.html

@@ -0,0 +1,23 @@

+{{define "title"}}small ideas{{end}} +{{define "body"}} +<p><i>these are all tiny ideas</p></i> +<p><i>that don't deserve their own blog posts</p></i> +<h4>2022</h4> +<li><a href="/idea/dynamic-blog.html">making a dynamic blog</a></li> +<h4>2021</h4> +<li><a href="/idea/using-discord-is-morally-lazy.html">using-discord-is-morally-lazy</a></li> +<li><a href="/idea/git-necronomicon.html">git-necronomicon</a></li> +<li><a href="/idea/alpine-rock64.html">alpine-rock64</a></li> +<li><a href="/idea/storing-passwords-with-age.html">storing-passwords-with-age</a></li> +<h4>2020</h4> +<li><a href="/idea/building-a-fixed-gear-bicycle.html">building-a-fixed-gear-bicycle</a></li> +<li><a href="/idea/email-is-good-actually.html">email-is-good-actually</a></li> +<li><a href="/idea/fail2ban-sux.html">fail2ban-sux</a></li> +<li><a href="/idea/fixed-gear-update.html">fixed-gear-update</a></li> +<li><a href="/idea/holy-is-thy-name.html">holy-is-thy-name</a></li> +<li><a href="/idea/no-hacktober.html">no-hacktober</a></li> +<li><a href="/idea/pumpernickel-bread.html">pumpernickel-bread</a></li> +<li><a href="/idea/something-is-different.html">something-is-different</a></li> +<hr> +<img src="/static/thoughtscrombles.png" alt="scrombles the cat"> +{{end}}
A templates/index.html

@@ -0,0 +1,11 @@

+{{define "title"}}j3s.sh{{end}} +{{define "body"}} +<p><i>the only way out is through</p></i> +<p><i>the only way out is through</p></i> +<p><i>the only way out is through</p></i> +<p><i>the only way out is through</p></i> +<p><i>fear is the mind-killer</p></i> +<p><i>fear is the mind-killer</p></i> +<p><i>fear is the mind-killer</p></i> +<p><i>fear is the mind-killer</p></i> +{{end}}
A templates/layout.html

@@ -0,0 +1,35 @@

+{{define "layout"}} +<!doctype html> +<html> +<head> + <style> +#main, #header, aside { + max-width: 444px; + margin: 0 auto; + padding: 0; +} + nav ul { list-style: none; padding: 0; margin: 0 45px 30px 0; float: left; } + .grayscale { -webkit-filter: grayscale(100%); -moz-filter: grayscale(100%); -ms-filter: grayscale(100%); filter: grayscale(100%); } + </style> + + <meta charset="utf-8"> + <title>{{template "title"}}</title> + <link rel="icon" href="data:image/svg+xml,<svg xmlns=%22http://www.w3.org/2000/svg%22><text y=%2226%22 font-size=%2226%22>🐈‍⬛</text></svg>"> +</head> +<div id="main"><body class="grayscale"> + <h1><a href="/"><img src="/static/scrombles.png" alt="scrombles the cat"></a> jes shit hell</h1> + + <p> + <a href="/ideas.html">ideas</a> + <a href="/movies.html">movies</a> + <a href="/blog.html">bl0g</a> + <a href="/about.html">about</a> + | + <a href="https://snap.as/j3s">pics -></a> + <a href="https://git.j3s.sh">git -></a> + </p> + <hr> + {{template "body"}} +</div></body> +</html> +{{end}}