Merge pull request 'Calc dates and add config struct fields' (#2) from develop into master
Reviewed-on: #2
This commit is contained in:
@ -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
|
BIN
linuxservice
BIN
linuxservice
Binary file not shown.
35
main.go
35
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)
|
||||
}
|
||||
|
Reference in New Issue
Block a user