ctdo.de/html.go

99 lines
3.7 KiB
Go
Raw Normal View History

package main
import (
"strconv"
"strings"
)
func htmlElement(tag string, innerHTML string, args string) string {
return "<" + tag + " " + args + ">" + innerHTML + "</" + tag + ">"
}
func htmlLinkElement(innerHTML string, destination string, blank bool, args string) string {
b := ""
if blank {
2023-01-27 14:30:42 +00:00
b = "target=\"_blank\" "
}
2023-01-27 14:30:42 +00:00
return htmlElement("a", innerHTML, " href=\""+destination+"\" "+b+args)
}
func htmlInputElement(name string, _type string, value string, args string) string {
return "<input name=\"" + name + "\" type=\"" + _type + "\" value=\"" + value + "\" " + args + ">"
}
2023-01-27 14:30:42 +00:00
func htmlNav(pages [][]string, activePage string) string {
output := ""
for _, page := range pages {
2023-01-27 14:30:42 +00:00
if page[1] == "/"+activePage || (page[1] == "/home" && activePage == "") {
output += htmlElement("li", htmlLinkElement(page[0], page[1], false, "class=\"active\""), "")
} else {
output += htmlElement("li", htmlLinkElement(page[0], page[1], false, ""), "")
}
}
return htmlElement("nav", htmlElement("ul", output, ""), "")
}
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))
if getRoomState().state {
output = strings.ReplaceAll(output, "!RAUMSTATUS", "<p>Raumstatus: <b class=\"green-text\">offen</b></p>")
} else {
output = strings.ReplaceAll(output, "!RAUMSTATUS", "<p>Raumstatus: <b class=\"red-text\">geschlossen</b></p>")
}
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\""))
}
events := getEvents()
if len(events) == 0 {
output = strings.ReplaceAll(output, "!EVENTS", htmlElement("h4", "Keine Events in der nächsten Zeit.", ""))
output = strings.ReplaceAll(output, "!NEXTEVENTS", htmlElement("h4", "Keine Events in der nächsten Zeit.", ""))
} else {
tempA, tempB := "", ""
for i, Event := range events {
if i == 24 {
break
}
tempA = htmlElement("h2", Event.title, "")
tempA += htmlElement("p", Event.description, "")
tempA += htmlElement("p", Event.date, "")
tempB += htmlElement("div", tempA, "class=\"event\"")
}
output = strings.ReplaceAll(output, "!EVENTS", htmlElement("div", tempB, "class=\"eventList\""))
output = strings.ReplaceAll(output, "!NEXTEVENTS", htmlElement("div", string(tempB[0]+tempB[1]+tempB[2]+tempB[3]), "class=\"eventList\""))
}
output = strings.ReplaceAll(output, "!NEWBANNER", htmlNewBanner("Rundgang", "https://www.chaostreff-dortmund.de/rundgang/"))
if strings.Contains(activePage, "/addEvent") {
output = strings.ReplaceAll(output, "!ADMINKEY", activePage)
} else {
output = strings.ReplaceAll(output, "!ADMINKEY", activePage+"/addEvent")
}
return output
}