Calc dates and add config struct fields #2

Merged
bdnugget merged 2 commits from develop into master 2025-09-01 12:13:51 +00:00
3 changed files with 25 additions and 13 deletions
Showing only changes of commit 5dc9cc3d71 - Show all commits

View File

@ -17,4 +17,7 @@ services:
- DOMAIN=hogelandlinux.nl # Set your actual domain here - DOMAIN=hogelandlinux.nl # Set your actual domain here
- TELEGRAM_BOT_TOKEN= # Set your Telegram bot token here - TELEGRAM_BOT_TOKEN= # Set your Telegram bot token here
- TELEGRAM_CHAT_ID= # Set your Telegram chat ID here - TELEGRAM_CHAT_ID= # Set your Telegram chat ID here
- ABOUT_NAME=Bdnugget
- BIRTH_DATE=1990-01-01
- SON_BIRTH_DATE=2022-01-01
restart: unless-stopped restart: unless-stopped

Binary file not shown.

35
main.go
View File

@ -27,6 +27,9 @@ type Config struct {
Port string Port string
TelegramBotToken string TelegramBotToken string
TelegramChatID string TelegramChatID string
AboutName string
BirthDate string
SonBirthDate string
} }
// PageData holds data for template rendering // PageData holds data for template rendering
@ -89,6 +92,9 @@ func NewServer() *Server {
Port: ":" + getEnv("PORT", "8080"), Port: ":" + getEnv("PORT", "8080"),
TelegramBotToken: getEnv("TELEGRAM_BOT_TOKEN", ""), // Set this in environment TelegramBotToken: getEnv("TELEGRAM_BOT_TOKEN", ""), // Set this in environment
TelegramChatID: getEnv("TELEGRAM_CHAT_ID", ""), // Set this in environment TelegramChatID: getEnv("TELEGRAM_CHAT_ID", ""), // Set this in environment
AboutName: getEnv("ABOUT_NAME", "Bdnugget"),
BirthDate: getEnv("BIRTH_DATE", "1990-01-01"),
SonBirthDate: getEnv("SON_BIRTH_DATE", "2022-01-01"),
} }
// Parse templates with error handling // Parse templates with error handling
@ -317,22 +323,25 @@ func (s *Server) healthHandler(w http.ResponseWriter, r *http.Request) {
// aboutHandler handles the About Me page // aboutHandler handles the About Me page
func (s *Server) aboutHandler(w http.ResponseWriter, r *http.Request) { func (s *Server) aboutHandler(w http.ResponseWriter, r *http.Request) {
data := s.createPageData("Over mij - "+s.config.CompanyName, "about") data := s.createPageData("Over mij - "+s.config.CompanyName, "about")
// Populate dynamic About fields // Populate dynamic About fields from config/env
data.AboutName = "Brendon Bosman" data.AboutName = s.config.AboutName
now := time.Now() now := time.Now()
birthYear, birthMonth, birthDay := 1990, time.October, 17 // Parse BirthDate (ISO YYYY-MM-DD)
age := now.Year() - birthYear if t, err := time.Parse("2006-01-02", s.config.BirthDate); err == nil {
if now.Month() < birthMonth || (now.Month() == birthMonth && now.Day() < birthDay) { age := now.Year() - t.Year()
age-- if now.Month() < t.Month() || (now.Month() == t.Month() && now.Day() < t.Day()) {
age--
}
data.AgeYears = age
} }
data.AgeYears = age // Parse SonBirthDate (ISO YYYY-MM-DD)
if t, err := time.Parse("2006-01-02", s.config.SonBirthDate); err == nil {
sonYear, sonMonth, sonDay := 2022, time.March, 11 sonAge := now.Year() - t.Year()
sonAge := now.Year() - sonYear if now.Month() < t.Month() || (now.Month() == t.Month() && now.Day() < t.Day()) {
if now.Month() < sonMonth || (now.Month() == sonMonth && now.Day() < sonDay) { sonAge--
sonAge-- }
data.SonAgeYears = sonAge
} }
data.SonAgeYears = sonAge
s.renderTemplate(w, "over-mij.html", data) s.renderTemplate(w, "over-mij.html", data)
} }