feat: make age dynamic

This commit is contained in:
Stevan Freeborn
2025-11-24 08:58:47 -06:00
parent dac40f228d
commit c09461f9c9
3 changed files with 24 additions and 3 deletions
+1
View File
@@ -0,0 +1 @@
# TODO: implement pull request workflow
+2 -1
View File
@@ -13,11 +13,12 @@
<body> <body>
<div class="image-container"> <div class="image-container">
<!-- TODO: Generate alt text dynamically??? -->
<img class="profile-picture" src="https://github.com/StevanFreeborn.png" <img class="profile-picture" src="https://github.com/StevanFreeborn.png"
alt="A man with short brown hair, a grey hoodie, and a white t-shirt smiles at the camera. He has a white earbud in his left ear. The background is a blurred office setting with warm lighting visible through glass partitions." /> alt="A man with short brown hair, a grey hoodie, and a white t-shirt smiles at the camera. He has a white earbud in his left ear. The background is a blurred office setting with warm lighting visible through glass partitions." />
<div class="bio"> <div class="bio">
<h1>Stevan Freeborn</h1> <h1>Stevan Freeborn</h1>
<p>I'm a 32-year old dad of 2 who enjoys drinking coffee, lifting weights, and solving problems with code.</p> <p>I'm a {{ .Age }}-year old dad of 2 who enjoys drinking coffee, lifting weights, and solving problems with code.</p>
</div> </div>
</div> </div>
<nav class="links-container"> <nav class="links-container">
+21 -2
View File
@@ -2,14 +2,27 @@
package handlers package handlers
import ( import (
"math"
"net/http" "net/http"
"text/template" "text/template"
"time"
"github.com/StevanFreeborn/links.stevanfreeborn.com/internal/assets" "github.com/StevanFreeborn/links.stevanfreeborn.com/internal/assets"
) )
const DAYS_IN_YEAR = 365
const HOURS_IN_DAY = 24
var birthday time.Time = time.Date(1993, time.April, 21, 0, 0, 0, 0, time.UTC)
type IndexViewModel struct {
Age float64
}
func Index(w http.ResponseWriter, r *http.Request) { func Index(w http.ResponseWriter, r *http.Request) {
// Links coming in external JSON data // TODO: Links coming in external JSON data
// this could be static file in the repo
// or it could be fetched
// { link: "link", text: "text", "icon": "icon" } // { link: "link", text: "text", "icon": "icon" }
t, err := template.ParseFS(assets.Templates, "templates/index.gohtml") t, err := template.ParseFS(assets.Templates, "templates/index.gohtml")
@@ -19,7 +32,13 @@ func Index(w http.ResponseWriter, r *http.Request) {
return return
} }
t.Execute(w, nil) age := time.Since(birthday).Hours() / HOURS_IN_DAY / DAYS_IN_YEAR
viewModel := IndexViewModel{
Age: math.Floor(age),
}
t.Execute(w, viewModel)
} }
func CSS(w http.ResponseWriter, r *http.Request) { func CSS(w http.ResponseWriter, r *http.Request) {