mirror of
https://github.com/Kugelschieber/marvinblum.git
synced 2026-01-18 06:40:27 +00:00
Added template rendering, caching, started blog pages.
This commit is contained in:
1
dev.sh
1
dev.sh
@@ -6,5 +6,6 @@
|
||||
export MB_LOGLEVEL=debug
|
||||
export MB_ALLOWED_ORIGINS=*
|
||||
export MB_HOST=localhost:8080
|
||||
export MB_HOT_RELOAD=true
|
||||
|
||||
go run main.go
|
||||
|
||||
55
main.go
55
main.go
@@ -1,11 +1,13 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"github.com/NYTimes/gziphandler"
|
||||
"github.com/caddyserver/certmagic"
|
||||
"github.com/emvi/logbuch"
|
||||
"github.com/gorilla/mux"
|
||||
"github.com/rs/cors"
|
||||
"html/template"
|
||||
"net/http"
|
||||
"os"
|
||||
"strings"
|
||||
@@ -13,11 +15,18 @@ import (
|
||||
|
||||
const (
|
||||
staticDir = "static"
|
||||
staticDirPrefix = "/"
|
||||
staticDirPrefix = "/static/"
|
||||
templateDir = "template/*"
|
||||
logTimeFormat = "2006-01-02_15:04:05"
|
||||
envPrefix = "MB_"
|
||||
)
|
||||
|
||||
var (
|
||||
tpl *template.Template
|
||||
tplCache = make(map[string][]byte)
|
||||
hotReload bool
|
||||
)
|
||||
|
||||
func configureLog() {
|
||||
logbuch.SetFormatter(logbuch.NewFieldFormatter(logTimeFormat, "\t\t"))
|
||||
logbuch.Info("Configure logging...")
|
||||
@@ -41,9 +50,52 @@ func logEnvConfig() {
|
||||
}
|
||||
}
|
||||
|
||||
func loadTemplate() {
|
||||
logbuch.Debug("Loading templates")
|
||||
var err error
|
||||
tpl, err = template.ParseGlob(templateDir)
|
||||
|
||||
if err != nil {
|
||||
logbuch.Fatal("Error loading template", logbuch.Fields{"err": err})
|
||||
}
|
||||
|
||||
hotReload = os.Getenv("MB_HOT_RELOAD") == "true"
|
||||
logbuch.Debug("Templates loaded", logbuch.Fields{"hot_reload": hotReload})
|
||||
}
|
||||
|
||||
func renderTemplate(name string) {
|
||||
logbuch.Debug("Rendering template", logbuch.Fields{"name": name})
|
||||
var buffer bytes.Buffer
|
||||
|
||||
if err := tpl.ExecuteTemplate(&buffer, name, nil); err != nil {
|
||||
logbuch.Fatal("Error executing template", logbuch.Fields{"err": err, "name": name})
|
||||
}
|
||||
|
||||
tplCache[name] = buffer.Bytes()
|
||||
}
|
||||
|
||||
func serveTemplate(name string) http.HandlerFunc {
|
||||
// render once so we have it in cache
|
||||
renderTemplate(name)
|
||||
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
if hotReload {
|
||||
loadTemplate()
|
||||
renderTemplate(name)
|
||||
}
|
||||
|
||||
if _, err := w.Write(tplCache[name]); err != nil {
|
||||
logbuch.Error("Error returning page to client", logbuch.Fields{"err": err, "name": name})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func setupRouter() *mux.Router {
|
||||
router := mux.NewRouter()
|
||||
router.PathPrefix(staticDirPrefix).Handler(http.StripPrefix(staticDirPrefix, gziphandler.GzipHandler(http.FileServer(http.Dir(staticDir)))))
|
||||
router.Handle("/blog", serveTemplate("blog.html"))
|
||||
router.Handle("/", serveTemplate("about.html"))
|
||||
router.NotFoundHandler = serveTemplate("notfound.html")
|
||||
return router
|
||||
}
|
||||
|
||||
@@ -83,6 +135,7 @@ func start(handler http.Handler) {
|
||||
func main() {
|
||||
configureLog()
|
||||
logEnvConfig()
|
||||
loadTemplate()
|
||||
router := setupRouter()
|
||||
corsConfig := configureCors(router)
|
||||
start(corsConfig)
|
||||
|
||||
@@ -1,117 +0,0 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<base href="/" />
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<meta name="copyright" content="Marvin Blum" />
|
||||
<meta name="author" content="Marvin Blum" />
|
||||
<meta name="title" content="Marvin Blum" />
|
||||
<meta name="description" content="A full stack software engineer from Germany, open source and Linux enthusiast and co-founder of Emvi." />
|
||||
<meta name="msapplication-TileColor" content="#000000" />
|
||||
<meta name="theme-color" content="#000000" />
|
||||
<meta name="twitter:card" content="profile" />
|
||||
<meta name="twitter:site" content="@m5blum" />
|
||||
<meta name="twitter:title" content="Marvin Blum" />
|
||||
<meta name="twitter:description" content="A full stack software engineer from Germany, open source and Linux enthusiast and co-founder of Emvi." />
|
||||
<meta name="twitter:image" content="https://marvinblum.de/avatar.png" />
|
||||
<meta property="og:url" content="https://marvinblum.de/" />
|
||||
<meta property="og:title" content="Marvin Blum" />
|
||||
<meta property="og:description" content="A full stack software engineer from Germany, open source and Linux enthusiast and co-founder of Emvi." />
|
||||
<meta property="og:image" content="https://marvinblum.de/avatar.png" />
|
||||
<title>marvin blum</title>
|
||||
<link rel="apple-touch-icon" sizes="180x180" href="favicon/apple-touch-icon.png" />
|
||||
<link rel="icon" type="image/png" sizes="32x32" href="favicon/favicon-32x32.png" />
|
||||
<link rel="icon" type="image/png" sizes="16x16" href="favicon/favicon-16x16.png" />
|
||||
<link rel="manifest" href="favicon/site.webmanifest" />
|
||||
<link rel="mask-icon" href="favicon/safari-pinned-tab.svg" color="#5bbad5" />
|
||||
<meta name="msapplication-TileColor" content="#da532c" />
|
||||
<meta name="theme-color" content="#ffffff" />
|
||||
<link rel="stylesheet" type="text/css" href="normalize.css" />
|
||||
<link rel="stylesheet" type="text/css" href="concrete.css" />
|
||||
<link rel="stylesheet" type="text/css" href="style.css" />
|
||||
</head>
|
||||
<body>
|
||||
<div class="title">
|
||||
<div>
|
||||
<h1>marvin blum</h1>
|
||||
<h2>welcome to my website!</h2>
|
||||
</div>
|
||||
<img src="avatar_100.jpg" alt="Marvin Blum" />
|
||||
</div>
|
||||
<div class="menu">
|
||||
<!--<a href="/" class="button filled">About</a>
|
||||
<a href="/blog" class="button filled">Blog</a>-->
|
||||
<a href="mailto:marvin@marvinblum.de" class="button">Contact me</a>
|
||||
<a href="https://github.com/Kugelschieber" target="_blank" class="button">GitHub</a>
|
||||
<a href="https://twitter.com/m5blum" target="_blank" class="button">Twitter</a>
|
||||
</div>
|
||||
<section>
|
||||
<h2>who am I?</h2>
|
||||
<p>
|
||||
I'm a full stack software engineer from Germany, open source and Linux enthusiast and co-founder of <a href="https://emvi.com/" target="_blank">Emvi</a>.
|
||||
In love with Go, but fluent in a lot of programming languages.
|
||||
</p>
|
||||
</section>
|
||||
<section>
|
||||
<h2>projects</h2>
|
||||
<ul>
|
||||
<li>
|
||||
<a href="https://emvi.com/" target="_blank">Emvi</a> a note taking, collaboration and knowledge management tool for personal use and teams of any size
|
||||
</li>
|
||||
<li>
|
||||
<a href="https://github.com/emvi/logbuch" target="_blank">logbuch</a> a simple Golang logging library
|
||||
</li>
|
||||
<li>
|
||||
<a href="https://github.com/emvi/null" target="_blank">null</a> a Golang library for nullable types supporting databases and json
|
||||
</li>
|
||||
<li>
|
||||
<a href="https://github.com/emvi/hide" target="_blank">hide</a> a Golang library to obscure IDs on the API layer
|
||||
</li>
|
||||
<li>
|
||||
<a href="https://github.com/assetto-corsa-web/accweb" target="_blank">accweb</a> a web interface to manage game servers
|
||||
</li>
|
||||
</ul>
|
||||
</section>
|
||||
<section>
|
||||
<h2>skills</h2>
|
||||
<ul>
|
||||
<li>Go (Golang)</li>
|
||||
<li>JavaScript (Vue, Node)</li>
|
||||
<li>HTML, CSS, Sass and all the web fuzz</li>
|
||||
<li>Java</li>
|
||||
<li>PHP</li>
|
||||
<li>Linux</li>
|
||||
<li>Docker</li>
|
||||
<li>Kubernetes</li>
|
||||
<li>... and more</li>
|
||||
</ul>
|
||||
</section>
|
||||
<section>
|
||||
<h2>work</h2>
|
||||
<ul>
|
||||
<li>
|
||||
<a href="https://www.bertelsmann.com/divisions/arvato/#st-1" target="_blank">arvato</a> as a Java developer
|
||||
</li>
|
||||
<li>
|
||||
<a href="https://skalar.marketing/" target="_blank">skalar marketing</a> as a full stack developer and web designer
|
||||
</li>
|
||||
<li>
|
||||
<a href="https://emvi.com/" target="_blank">Emvi</a> co-founder of a note taking, collaboration and knowledge management SaaS startup
|
||||
</li>
|
||||
<li>
|
||||
some freelancing from time to time
|
||||
</li>
|
||||
</ul>
|
||||
</section>
|
||||
<hr />
|
||||
<section>
|
||||
<p>
|
||||
Like to see more? Read my blog articles on <a href="https://emvi.com/blog" target="_blank">Emvi</a>, my project page on <a href="https://github.com/Kugelschieber" target="_blank">GitHub</a> or send me a <a href="mailto:marvin@marvinblum.de">mail</a>.
|
||||
</p>
|
||||
<p>
|
||||
This page uses <a href="https://concrete.style/" target="_blank">concrete</a> for styling. Check it out!
|
||||
</p>
|
||||
</section>
|
||||
</body>
|
||||
</html>
|
||||
81
template/about.html
Normal file
81
template/about.html
Normal file
@@ -0,0 +1,81 @@
|
||||
{{template "head.html"}}
|
||||
|
||||
<div class="title">
|
||||
<div>
|
||||
<h1>marvin blum</h1>
|
||||
<h2>welcome to my website!</h2>
|
||||
</div>
|
||||
<img src="../static/avatar_100.jpg" alt="Marvin Blum" />
|
||||
</div>
|
||||
|
||||
{{template "menu.html"}}
|
||||
|
||||
<section>
|
||||
<h2>who am I?</h2>
|
||||
<p>
|
||||
I'm a full stack software engineer from Germany, open source and Linux enthusiast and co-founder of <a href="https://emvi.com/" target="_blank">Emvi</a>.
|
||||
In love with Go, but fluent in a lot of programming languages.
|
||||
</p>
|
||||
</section>
|
||||
<section>
|
||||
<h2>latest blog posts</h2>
|
||||
<p>
|
||||
TODO
|
||||
</p>
|
||||
<p>
|
||||
<a href="/blog">View all</a>
|
||||
</p>
|
||||
</section>
|
||||
<section>
|
||||
<h2>projects</h2>
|
||||
<ul>
|
||||
<li>
|
||||
<a href="https://emvi.com/" target="_blank">Emvi</a> a note taking, collaboration and knowledge management tool for personal use and teams of any size
|
||||
</li>
|
||||
<li>
|
||||
<a href="https://github.com/emvi/logbuch" target="_blank">logbuch</a> a simple Golang logging library
|
||||
</li>
|
||||
<li>
|
||||
<a href="https://github.com/emvi/null" target="_blank">null</a> a Golang library for nullable types supporting databases and json
|
||||
</li>
|
||||
<li>
|
||||
<a href="https://github.com/emvi/hide" target="_blank">hide</a> a Golang library to obscure IDs on the API layer
|
||||
</li>
|
||||
<li>
|
||||
<a href="https://github.com/assetto-corsa-web/accweb" target="_blank">accweb</a> a web interface to manage game servers
|
||||
</li>
|
||||
</ul>
|
||||
</section>
|
||||
<section>
|
||||
<h2>skills</h2>
|
||||
<ul>
|
||||
<li>Go (Golang)</li>
|
||||
<li>JavaScript (Vue, Node)</li>
|
||||
<li>HTML, CSS, Sass and all the web fuzz</li>
|
||||
<li>Java</li>
|
||||
<li>PHP</li>
|
||||
<li>Linux</li>
|
||||
<li>Docker</li>
|
||||
<li>Kubernetes</li>
|
||||
<li>... and more</li>
|
||||
</ul>
|
||||
</section>
|
||||
<section>
|
||||
<h2>work</h2>
|
||||
<ul>
|
||||
<li>
|
||||
<a href="https://emvi.com/" target="_blank">Emvi</a> co-founder of a note taking, collaboration and knowledge management SaaS startup
|
||||
</li>
|
||||
<li>
|
||||
<a href="https://skalar.marketing/" target="_blank">skalar marketing</a> as a full stack developer and web designer
|
||||
</li>
|
||||
<li>
|
||||
<a href="https://www.bertelsmann.com/divisions/arvato/#st-1" target="_blank">arvato</a> as a Java developer
|
||||
</li>
|
||||
<li>
|
||||
some freelancing from time to time
|
||||
</li>
|
||||
</ul>
|
||||
</section>
|
||||
|
||||
{{template "end.html"}}
|
||||
8
template/blog.html
Normal file
8
template/blog.html
Normal file
@@ -0,0 +1,8 @@
|
||||
{{template "head.html"}}
|
||||
{{template "menu.html"}}
|
||||
|
||||
<section>
|
||||
<p>TODO Blog</p>
|
||||
</section>
|
||||
|
||||
{{template "end.html"}}
|
||||
11
template/end.html
Normal file
11
template/end.html
Normal file
@@ -0,0 +1,11 @@
|
||||
<hr />
|
||||
<section>
|
||||
<p>
|
||||
Like to see more? Read my blog articles on <a href="https://emvi.com/blog" target="_blank">Emvi</a>, my project page on <a href="https://github.com/Kugelschieber" target="_blank">GitHub</a> or send me a <a href="mailto:marvin@marvinblum.de">mail</a>.
|
||||
</p>
|
||||
<p>
|
||||
This page uses <a href="https://concrete.style/" target="_blank">concrete</a> for styling. Check it out!
|
||||
</p>
|
||||
</section>
|
||||
</body>
|
||||
</html>
|
||||
34
template/head.html
Normal file
34
template/head.html
Normal file
@@ -0,0 +1,34 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<base href="/" />
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<meta name="copyright" content="Marvin Blum" />
|
||||
<meta name="author" content="Marvin Blum" />
|
||||
<meta name="title" content="Marvin Blum" />
|
||||
<meta name="description" content="A full stack software engineer from Germany, open source and Linux enthusiast and co-founder of Emvi." />
|
||||
<meta name="msapplication-TileColor" content="#000000" />
|
||||
<meta name="theme-color" content="#000000" />
|
||||
<meta name="twitter:card" content="profile" />
|
||||
<meta name="twitter:site" content="@m5blum" />
|
||||
<meta name="twitter:title" content="Marvin Blum" />
|
||||
<meta name="twitter:description" content="A full stack software engineer from Germany, open source and Linux enthusiast and co-founder of Emvi." />
|
||||
<meta name="twitter:image" content="https://marvinblum.de/avatar.png" />
|
||||
<meta property="og:url" content="https://marvinblum.de/" />
|
||||
<meta property="og:title" content="Marvin Blum" />
|
||||
<meta property="og:description" content="A full stack software engineer from Germany, open source and Linux enthusiast and co-founder of Emvi." />
|
||||
<meta property="og:image" content="https://marvinblum.de/avatar.png" />
|
||||
<title>marvin blum</title>
|
||||
<link rel="apple-touch-icon" sizes="180x180" href="../static/favicon/apple-touch-icon.png" />
|
||||
<link rel="icon" type="image/png" sizes="32x32" href="../static/favicon/favicon-32x32.png" />
|
||||
<link rel="icon" type="image/png" sizes="16x16" href="../static/favicon/favicon-16x16.png" />
|
||||
<link rel="manifest" href="../static/favicon/site.webmanifest" />
|
||||
<link rel="mask-icon" href="../static/favicon/safari-pinned-tab.svg" color="#5bbad5" />
|
||||
<meta name="msapplication-TileColor" content="#da532c" />
|
||||
<meta name="theme-color" content="#ffffff" />
|
||||
<link rel="stylesheet" type="text/css" href="../static/normalize.css" />
|
||||
<link rel="stylesheet" type="text/css" href="../static/concrete.css" />
|
||||
<link rel="stylesheet" type="text/css" href="../static/style.css" />
|
||||
</head>
|
||||
<body>
|
||||
7
template/menu.html
Normal file
7
template/menu.html
Normal file
@@ -0,0 +1,7 @@
|
||||
<div class="menu">
|
||||
<a href="/" class="button filled">About</a>
|
||||
<a href="/blog" class="button filled">Blog</a>
|
||||
<a href="mailto:marvin@marvinblum.de" class="button">Contact me</a>
|
||||
<a href="https://github.com/Kugelschieber" target="_blank" class="button">GitHub</a>
|
||||
<a href="https://twitter.com/m5blum" target="_blank" class="button">Twitter</a>
|
||||
</div>
|
||||
11
template/notfound.html
Normal file
11
template/notfound.html
Normal file
@@ -0,0 +1,11 @@
|
||||
{{template "head.html"}}
|
||||
|
||||
<section>
|
||||
<h2>Page not found</h2>
|
||||
<p>
|
||||
Nothing to see here...<br />
|
||||
<a href="/">Go back Home</a>
|
||||
</p>
|
||||
</section>
|
||||
|
||||
{{template "end.html"}}
|
||||
Reference in New Issue
Block a user