feat: pretty shitty code
This commit is contained in:
2
go.mod
2
go.mod
@@ -1,3 +1,3 @@
|
||||
module git.yadunut.dev/yadunut.dev
|
||||
module git.yadunut.dev/yadunut/yadunut.dev
|
||||
|
||||
go 1.23.3
|
||||
|
||||
4
main.go
4
main.go
@@ -4,12 +4,12 @@ import (
|
||||
"fmt"
|
||||
"log/slog"
|
||||
|
||||
"git.yadunut.dev/yadunut.dev/site"
|
||||
"git.yadunut.dev/yadunut/yadunut.dev/site"
|
||||
)
|
||||
|
||||
func main() {
|
||||
c := site.NewConfig(slog.LevelDebug, 8080)
|
||||
c.Logger.Info("Starting server")
|
||||
c.Logger.Info("Starting server")
|
||||
if err := site.Run(c); err != nil {
|
||||
c.Logger.Error(fmt.Sprintf("failed with error %s", err))
|
||||
}
|
||||
|
||||
@@ -44,6 +44,22 @@ func (h *handler) RequestsCounterMiddleware(next http.Handler) http.Handler {
|
||||
func (h *handler) Ping(w http.ResponseWriter, r *http.Request) {
|
||||
fmt.Fprintf(w, "Pong")
|
||||
}
|
||||
func (h *handler) Index(w http.ResponseWriter, r *http.Request) {
|
||||
h.logger.Info(r.URL.Path)
|
||||
|
||||
if template, isOk := templates[r.URL.Path]; isOk {
|
||||
h.logger.Info("Found template")
|
||||
template.ExecuteTemplate(w, "base", nil)
|
||||
} else {
|
||||
h.logger.Info("default template")
|
||||
templates["index.html"].ExecuteTemplate(w, "base", nil)
|
||||
}
|
||||
}
|
||||
|
||||
func (h *handler) FileServer(w http.ResponseWriter, r *http.Request) {
|
||||
h.logger.Info("handled by file server router")
|
||||
http.FileServer(http.FS(staticContent)).ServeHTTP(w, r)
|
||||
}
|
||||
|
||||
func (h *handler) Metrics(w http.ResponseWriter, r *http.Request) {
|
||||
h.requestsCounter.mu.Lock()
|
||||
|
||||
@@ -8,6 +8,8 @@ func middlewares(h *handler, next http.Handler) http.Handler {
|
||||
|
||||
func createRoutes(h *handler) map[string]http.Handler {
|
||||
routes := map[string]http.Handler{
|
||||
"/static/": middlewares(h, http.HandlerFunc(h.FileServer)),
|
||||
"/": middlewares(h, http.HandlerFunc(h.Index)),
|
||||
"/ping": middlewares(h, http.HandlerFunc(h.Ping)),
|
||||
"/metrics": middlewares(h, http.HandlerFunc(h.Metrics)),
|
||||
"/healthz": middlewares(h, http.HandlerFunc(h.Healthz)),
|
||||
|
||||
55
site/static/css/main.css
Normal file
55
site/static/css/main.css
Normal file
@@ -0,0 +1,55 @@
|
||||
:root {
|
||||
--font-family: "Comic Mono";
|
||||
--line-height: 1.2rem;
|
||||
--font-weight-normal: 500;
|
||||
--font-weight-medium: 600;
|
||||
--font-weight-bold: 800;
|
||||
|
||||
font-family: var(--font-family), monospace;
|
||||
font-weight: var(--font-weight-normal);
|
||||
font-size: 16px;
|
||||
}
|
||||
* {
|
||||
box-sizing: border-box;
|
||||
}
|
||||
body {
|
||||
width: 100%;
|
||||
margin: 0;
|
||||
line-height: var(--line-height);
|
||||
max-width: 100ch;
|
||||
}
|
||||
h1,
|
||||
h2,
|
||||
h3,
|
||||
h4,
|
||||
h5,
|
||||
h6 {
|
||||
margin: calc(var(--line-height) * 2) 0 var(--line-height) 0;
|
||||
font-weight: var(--font-weight-bold);
|
||||
}
|
||||
h1 {
|
||||
font-size: 2rem;
|
||||
margin-bottom: calc(var(--line-height) * 2);
|
||||
text-transform: uppercase;
|
||||
}
|
||||
h2 {
|
||||
font-size: 1rem;
|
||||
text-transform: uppercase;
|
||||
}
|
||||
#grid {
|
||||
position: absolute;
|
||||
z-index: -1;
|
||||
top: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
background-image: linear-gradient(to right, #ccc 1px, transparent 1px),
|
||||
linear-gradient(to bottom, #ccc 1px, transparent 1px);
|
||||
background-size: 1ch var(--line-height); /* Adjust grid size */
|
||||
background-position: top left;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
p {
|
||||
margin-bottom: var(--line-height);
|
||||
}
|
||||
129
site/static/css/reset.css
Normal file
129
site/static/css/reset.css
Normal file
@@ -0,0 +1,129 @@
|
||||
/* http://meyerweb.com/eric/tools/css/reset/
|
||||
v2.0 | 20110126
|
||||
License: none (public domain)
|
||||
*/
|
||||
|
||||
html,
|
||||
body,
|
||||
div,
|
||||
span,
|
||||
applet,
|
||||
object,
|
||||
iframe,
|
||||
h1,
|
||||
h2,
|
||||
h3,
|
||||
h4,
|
||||
h5,
|
||||
h6,
|
||||
p,
|
||||
blockquote,
|
||||
pre,
|
||||
a,
|
||||
abbr,
|
||||
acronym,
|
||||
address,
|
||||
big,
|
||||
cite,
|
||||
code,
|
||||
del,
|
||||
dfn,
|
||||
em,
|
||||
img,
|
||||
ins,
|
||||
kbd,
|
||||
q,
|
||||
s,
|
||||
samp,
|
||||
small,
|
||||
strike,
|
||||
strong,
|
||||
sub,
|
||||
sup,
|
||||
tt,
|
||||
var,
|
||||
b,
|
||||
u,
|
||||
i,
|
||||
center,
|
||||
dl,
|
||||
dt,
|
||||
dd,
|
||||
ol,
|
||||
ul,
|
||||
li,
|
||||
fieldset,
|
||||
form,
|
||||
label,
|
||||
legend,
|
||||
table,
|
||||
caption,
|
||||
tbody,
|
||||
tfoot,
|
||||
thead,
|
||||
tr,
|
||||
th,
|
||||
td,
|
||||
article,
|
||||
aside,
|
||||
canvas,
|
||||
details,
|
||||
embed,
|
||||
figure,
|
||||
figcaption,
|
||||
footer,
|
||||
header,
|
||||
hgroup,
|
||||
menu,
|
||||
nav,
|
||||
output,
|
||||
ruby,
|
||||
section,
|
||||
summary,
|
||||
time,
|
||||
mark,
|
||||
audio,
|
||||
video {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
border: 0;
|
||||
font-size: 100%;
|
||||
font: inherit;
|
||||
vertical-align: baseline;
|
||||
}
|
||||
/* HTML5 display-role reset for older browsers */
|
||||
article,
|
||||
aside,
|
||||
details,
|
||||
figcaption,
|
||||
figure,
|
||||
footer,
|
||||
header,
|
||||
hgroup,
|
||||
menu,
|
||||
nav,
|
||||
section {
|
||||
display: block;
|
||||
}
|
||||
body {
|
||||
line-height: 1;
|
||||
}
|
||||
ol,
|
||||
ul {
|
||||
list-style: none;
|
||||
}
|
||||
blockquote,
|
||||
q {
|
||||
quotes: none;
|
||||
}
|
||||
blockquote:before,
|
||||
blockquote:after,
|
||||
q:before,
|
||||
q:after {
|
||||
content: "";
|
||||
content: none;
|
||||
}
|
||||
table {
|
||||
border-collapse: collapse;
|
||||
border-spacing: 0;
|
||||
}
|
||||
37
site/templates.go
Normal file
37
site/templates.go
Normal file
@@ -0,0 +1,37 @@
|
||||
package site
|
||||
|
||||
import (
|
||||
"embed"
|
||||
_ "embed"
|
||||
"fmt"
|
||||
"html/template"
|
||||
"io/fs"
|
||||
"path"
|
||||
"strings"
|
||||
)
|
||||
|
||||
var templates map[string]*template.Template
|
||||
|
||||
func init() {
|
||||
templates = make(map[string]*template.Template)
|
||||
fs.WalkDir(templateContent, "templates", func(p string, d fs.DirEntry, err error) error {
|
||||
if d.IsDir() || !strings.HasSuffix(p, ".html") {
|
||||
return nil
|
||||
}
|
||||
basePath := path.Base(p)
|
||||
templates[basePath] = template.Must(template.ParseFS(templateContent, p, "templates/_layout.html.tmpl"))
|
||||
fmt.Println(path.Base(p))
|
||||
return nil
|
||||
})
|
||||
fmt.Printf("successfully parsed templates: ")
|
||||
for k, t := range templates {
|
||||
fmt.Printf("%s: %s \n", k, t.Name())
|
||||
}
|
||||
fmt.Println()
|
||||
}
|
||||
|
||||
//go:embed templates/*
|
||||
var templateContent embed.FS
|
||||
|
||||
//go:embed static/*
|
||||
var staticContent embed.FS
|
||||
15
site/templates/_layout.html.tmpl
Normal file
15
site/templates/_layout.html.tmpl
Normal file
@@ -0,0 +1,15 @@
|
||||
{{ define "base" }}
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<link rel="stylesheet" type="text/css" href="/static/css/reset.css" />
|
||||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/comic-mono@0.0.1/index.css" />
|
||||
<link rel="stylesheet" type="text/css" href="/static/css/main.css" />
|
||||
<title>Yadunand's Site 🚧</title>
|
||||
</head>
|
||||
<body>
|
||||
{{ template "content" .}}
|
||||
<div id="grid"></div>
|
||||
</body>
|
||||
</html>
|
||||
{{ end }}
|
||||
12
site/templates/index.html
Normal file
12
site/templates/index.html
Normal file
@@ -0,0 +1,12 @@
|
||||
{{ define "content" }}
|
||||
<h1>Yadunand's Site WIP 🚧</h1>
|
||||
<p>Body</p>
|
||||
<h2>Header 2</h2>
|
||||
<p>Body</p>
|
||||
<h3>Header 3</h3>
|
||||
<p>Body</p>
|
||||
<h4>Header 4</h4>
|
||||
<p>Body</p>
|
||||
<h5>Header 5</h5>
|
||||
<p></p>
|
||||
{{ end }}
|
||||
Reference in New Issue
Block a user