diff --git a/func.go b/func.go index c5ef8f7..d34b8b8 100644 --- a/func.go +++ b/func.go @@ -32,6 +32,7 @@ func handler() { httpHandleFunc("style/main.css", "./web/styles/main.css", "text/css") httpHandleFunc("style/kontakt.css", "./web/styles/kontakt.css", "text/css") httpHandleFunc("style/home.css", "./web/styles/home.css", "text/css") + httpHandleFunc("style/events.css", "./web/styles/events.css", "text/css") //Images httpHandleFunc("image/logo_ctdo.svg", "./web/images/logo_ctdo.svg", "image/svg+xml") @@ -104,6 +105,14 @@ func getRoomState() status { return *roomState } +func htmlNewBanner(text string, link string) string { + output := "" + + output += htmlElement("div", htmlLinkElement(text, link, true, ""), "class=\"newBanner\"") + + return output +} + func htmlReplacer(input string, activePage string) string { output := strings.ReplaceAll(input, "!NAV", htmlNav(getPages(), activePage)) @@ -115,5 +124,76 @@ func htmlReplacer(input string, activePage string) string { output = strings.ReplaceAll(output, "!FOOTERNAV", htmlNav(getFooterPages(), activePage)) + if getNextTopic().days == 0 { + output = strings.ReplaceAll(output, "!TOPICTREFF", htmlElement("h3", "Nächster Topictreff findet Heute statt!", "")) + } else if getNextTopic().days == 1 { + output = strings.ReplaceAll(output, "!TOPICTREFF", htmlElement("h3", "Nächster Topictreff findet Morgen statt!", "class=\"topic\"")+htmlElement("p", "Am "+getNextTopic().date, "class=\"topic\"")) + } else if getNextTopic().days < 10 { + output = strings.ReplaceAll(output, "!TOPICTREFF", htmlElement("h3", "Nächster Topictreff findet in "+strconv.FormatInt(int64(getNextTopic().days), 10)+" Tagen statt!", "class=\"topic\"")+htmlElement("p", "Am "+getNextTopic().date, "class=\"topic\"")) + } else { + output = strings.ReplaceAll(output, "!TOPICTREFF", htmlElement("h3", "Nächster Topictreff findet in "+string(getNextTopic().days)+" Tagen statt!", "class=\"topic\"")+htmlElement("p", "Am "+getNextTopic().date, "class=\"topic\"")) + } + + output = strings.ReplaceAll(output, "!NEWBANNER", htmlNewBanner("Rundgang", "https://www.chaostreff-dortmund.de/rundgang/")) + + return output +} + +func ifFloatRange(variable float64, min float64, max float64, includeMin bool, includeMax bool) bool { + a, b := false, false + + if includeMin { + a = variable >= min + } else { + a = variable > min + } + + if includeMax { + b = variable <= max + } else { + b = variable < max + } + + return a && b +} + +func stringSplit(input string, sep string) []string { + output := *new([]string) + for _, element := range strings.Split(input, sep) { + if element != "" { + output = append(output, element) + } + } + return output +} + +// jeden ersten donnerstag und dritten dienstag +func getNextTopic() topic { + date := time.Now() + + var output topic + + for i := 0; i < 31; i++ { + newDate := stringSplit(date.AddDate(0, 0, 1*i).Format(time.UnixDate), " ") + + if newDate[0] == "Thu" || newDate[0] == "Tue" { + dayA, errA := strconv.Atoi(newDate[2]) + if errA != nil { + panic(errA) + } + + dayB, errB := strconv.Atoi(newDate[2]) + if errB != nil { + panic(errB) + } + + if ifFloatRange(float64(dayA)/7, 0, 1, false, true) || (ifFloatRange(float64(dayB)/7, 2, 3, false, true) && newDate[0] == "Tue") { + output.date = date.AddDate(0, 0, 1*i).Format("02.01.2006") + output.days = i + break + } + } + } + return output } diff --git a/structs.go b/structs.go index 53d5003..c0204f2 100644 --- a/structs.go +++ b/structs.go @@ -16,3 +16,8 @@ type event struct { media []string date string } + +type topic struct { + date string + days int +} diff --git a/tester.go b/tester.go new file mode 100644 index 0000000..37875a1 --- /dev/null +++ b/tester.go @@ -0,0 +1,5 @@ +package main + +func testFuncOutput(functionOutput any, rightOutput any) bool { + return functionOutput == rightOutput +} diff --git a/web/pages/about.html b/web/pages/about.html index 952d051..23b4ba6 100644 --- a/web/pages/about.html +++ b/web/pages/about.html @@ -8,6 +8,7 @@ + !NEWBANNER
ctdo logo !NAV diff --git a/web/pages/datenschutz.html b/web/pages/datenschutz.html index 0f209c0..a89d345 100644 --- a/web/pages/datenschutz.html +++ b/web/pages/datenschutz.html @@ -8,6 +8,7 @@ + !NEWBANNER
ctdo logo !NAV diff --git a/web/pages/events.html b/web/pages/events.html index 004e130..3d79b5a 100644 --- a/web/pages/events.html +++ b/web/pages/events.html @@ -6,10 +6,12 @@ ctdo - events + + !NEWBANNER
- ctdo logo + ctdo logo !NAV
diff --git a/web/pages/home.html b/web/pages/home.html index 57c30cf..501b6e3 100644 --- a/web/pages/home.html +++ b/web/pages/home.html @@ -9,12 +9,21 @@ + !NEWBANNER
ctdo logo !NAV
- Raum 2 mit gemütlichen Sofas + + !RAUMSTATUS

Hi

@@ -30,7 +39,8 @@

Die nächsten Events

-

Es sind gerade keine besonderen Veranstaltungen geplant.

+ !TOPICTREFF + !NEXTEVENTS