From 79327510d78608e94ed9e51b0d130acdb2a684e8 Mon Sep 17 00:00:00 2001 From: Yadunand Prem Date: Fri, 22 Nov 2024 15:02:29 -0500 Subject: [PATCH] feat: update site --- Dockerfile | 2 +- go.mod | 6 +++ go.sum | 7 +++ site/handler.go | 6 ++- site/static/css/main.css | 86 ++++++++++++++++++++------------ site/templates.go | 21 +++++--- site/templates/_layout.html.tmpl | 3 ++ site/templates/index.html | 42 ++++++++++++---- site/templates/something.html | 3 ++ 9 files changed, 124 insertions(+), 52 deletions(-) create mode 100644 go.sum create mode 100644 site/templates/something.html diff --git a/Dockerfile b/Dockerfile index 9ae1552..830daf5 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,7 +4,7 @@ FROM golang:1.23-alpine as builder WORKDIR /app # Copy and download dependencies -COPY go.mod ./ +COPY go.mod go.sum ./ RUN go mod download # Copy the source code diff --git a/go.mod b/go.mod index 00debfd..540ffb2 100644 --- a/go.mod +++ b/go.mod @@ -1,3 +1,9 @@ module git.yadunut.dev/yadunut/yadunut.dev go 1.23.3 + +require ( + github.com/yuin/goldmark v1.7.8 // indirect + github.com/yuin/goldmark-meta v1.1.0 // indirect + gopkg.in/yaml.v2 v2.3.0 // indirect +) diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..3c12820 --- /dev/null +++ b/go.sum @@ -0,0 +1,7 @@ +github.com/yuin/goldmark v1.7.8 h1:iERMLn0/QJeHFhxSt3p6PeN9mGnvIKSpG9YYorDMnic= +github.com/yuin/goldmark v1.7.8/go.mod h1:uzxRWxtg69N339t3louHJ7+O03ezfj6PlliRlaOzY1E= +github.com/yuin/goldmark-meta v1.1.0 h1:pWw+JLHGZe8Rk0EGsMVssiNb/AaPMHfSRszZeUeiOUc= +github.com/yuin/goldmark-meta v1.1.0/go.mod h1:U4spWENafuA7Zyg+Lj5RqK/MF+ovMYtBvXi1lBb2VP0= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v2 v2.3.0 h1:clyUAQHOM3G0M3f5vQj7LuJrETvjVot3Z5el9nffUtU= +gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= diff --git a/site/handler.go b/site/handler.go index adbb743..684573f 100644 --- a/site/handler.go +++ b/site/handler.go @@ -4,6 +4,7 @@ import ( "fmt" "log/slog" "net/http" + "path" "sync" ) @@ -44,15 +45,16 @@ 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 { + if template, isOk := templates[path.Base(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) + templates["index"].ExecuteTemplate(w, "base", nil) } } diff --git a/site/static/css/main.css b/site/static/css/main.css index 96e3443..95b8b46 100644 --- a/site/static/css/main.css +++ b/site/static/css/main.css @@ -1,55 +1,77 @@ :root { - --font-family: "Comic Mono"; - --line-height: 1.2rem; - --font-weight-normal: 500; - --font-weight-medium: 600; - --font-weight-bold: 800; + --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; + font-family: var(--font-family), monospace; + font-weight: var(--font-weight-normal); + font-size: 16px; } + * { - box-sizing: border-box; + box-sizing: border-box; } + body { - width: 100%; - margin: 0; - line-height: var(--line-height); - max-width: 100ch; + 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); + 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; + font-size: 2rem; + margin-bottom: calc(var(--line-height) * 2); + text-transform: uppercase; } + h2 { - font-size: 1rem; - text-transform: uppercase; + 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; + 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); + margin-bottom: var(--line-height); +} + +li { + margin: 0; + padding: 0; +} + +ul { + padding: 0 0 0 2ch; + margin: 0 0 var(--line-height); + list-style-type: square; +} + +ul li ul { + margin-bottom: 0; } diff --git a/site/templates.go b/site/templates.go index 0936c02..3ade087 100644 --- a/site/templates.go +++ b/site/templates.go @@ -7,6 +7,7 @@ import ( "html/template" "io/fs" "path" + "path/filepath" "strings" ) @@ -14,24 +15,28 @@ 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 { + fs.WalkDir(templateDir, "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)) + basePath := strings.TrimSuffix(path.Base(p), filepath.Ext(p)) + + templates[basePath] = template.Must(template.ParseFS(templateDir, p, "templates/_layout.html.tmpl")) return nil }) - fmt.Printf("successfully parsed templates: ") - for k, t := range templates { - fmt.Printf("%s: %s \n", k, t.Name()) + fmt.Println("Parsed templates") + for k, ts := range templates { + fmt.Printf("%s: ", k) + for _, t := range ts.Templates() { + fmt.Printf("%s ", t.Name()) + } + fmt.Println() } fmt.Println() } //go:embed templates/* -var templateContent embed.FS +var templateDir embed.FS //go:embed static/* var staticContent embed.FS diff --git a/site/templates/_layout.html.tmpl b/site/templates/_layout.html.tmpl index 4df9bd7..fa8b347 100644 --- a/site/templates/_layout.html.tmpl +++ b/site/templates/_layout.html.tmpl @@ -11,5 +11,8 @@ {{ template "content" .}}
+ {{ end }} diff --git a/site/templates/index.html b/site/templates/index.html index 02cf71d..1c2feb7 100644 --- a/site/templates/index.html +++ b/site/templates/index.html @@ -1,12 +1,36 @@ {{ define "content" }}

Yadunand's Site WIP 🚧

-

Body

-

Header 2

-

Body

-

Header 3

-

Body

-

Header 4

-

Body

-
Header 5
-

+

Hi, I'm Yadunand, a software engineer currently based in πŸ‡¨πŸ‡¦, previously in πŸ‡­πŸ‡°,πŸ‡¦πŸ‡Ί,πŸ‡ΈπŸ‡¬. I'm interested in how + companies build things that scale, and how infrastructure works in general. This site is built on the exploration of + that. Most of my work (including this site, and the infrastructure) can be found on my gitea

+

Currently

+ + +

Previously

+ +

Contact Me

+

I'm always happy to chat, feel free to reach out to me a @yadunut on (Twitter, Instagram, Telegram) or on email

+ {{ end }} diff --git a/site/templates/something.html b/site/templates/something.html new file mode 100644 index 0000000..3c690a9 --- /dev/null +++ b/site/templates/something.html @@ -0,0 +1,3 @@ +{{ define "content" }} +

Something goes here

+{{ end }}