diff --git a/docker-compose.yml b/docker-compose.yml index 0fb8943..a873944 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -17,4 +17,7 @@ services: - DOMAIN=hogelandlinux.nl # Set your actual domain here - TELEGRAM_BOT_TOKEN= # Set your Telegram bot token 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 \ No newline at end of file diff --git a/linuxservice b/linuxservice index d7b2108..30c4a42 100755 Binary files a/linuxservice and b/linuxservice differ diff --git a/main.go b/main.go index a43fd02..06762aa 100644 --- a/main.go +++ b/main.go @@ -27,6 +27,9 @@ type Config struct { Port string TelegramBotToken string TelegramChatID string + AboutName string + BirthDate string + SonBirthDate string } // PageData holds data for template rendering @@ -89,6 +92,9 @@ func NewServer() *Server { Port: ":" + getEnv("PORT", "8080"), TelegramBotToken: getEnv("TELEGRAM_BOT_TOKEN", ""), // 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 @@ -317,22 +323,25 @@ func (s *Server) healthHandler(w http.ResponseWriter, r *http.Request) { // aboutHandler handles the About Me page func (s *Server) aboutHandler(w http.ResponseWriter, r *http.Request) { data := s.createPageData("Over mij - "+s.config.CompanyName, "about") - // Populate dynamic About fields - data.AboutName = "Brendon Bosman" + // Populate dynamic About fields from config/env + data.AboutName = s.config.AboutName now := time.Now() - birthYear, birthMonth, birthDay := 1990, time.October, 17 - age := now.Year() - birthYear - if now.Month() < birthMonth || (now.Month() == birthMonth && now.Day() < birthDay) { - age-- + // Parse BirthDate (ISO YYYY-MM-DD) + if t, err := time.Parse("2006-01-02", s.config.BirthDate); err == nil { + age := now.Year() - t.Year() + if now.Month() < t.Month() || (now.Month() == t.Month() && now.Day() < t.Day()) { + age-- + } + data.AgeYears = age } - data.AgeYears = age - - sonYear, sonMonth, sonDay := 2022, time.March, 11 - sonAge := now.Year() - sonYear - if now.Month() < sonMonth || (now.Month() == sonMonth && now.Day() < sonDay) { - sonAge-- + // Parse SonBirthDate (ISO YYYY-MM-DD) + if t, err := time.Parse("2006-01-02", s.config.SonBirthDate); err == nil { + sonAge := now.Year() - t.Year() + if now.Month() < t.Month() || (now.Month() == t.Month() && now.Day() < t.Day()) { + sonAge-- + } + data.SonAgeYears = sonAge } - data.SonAgeYears = sonAge s.renderTemplate(w, "over-mij.html", data) }