107 lines
4.1 KiB
Go
107 lines
4.1 KiB
Go
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 {
|
|
b = "target=\"_blank\" "
|
|
}
|
|
|
|
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 + ">"
|
|
}
|
|
|
|
func htmlNav(pages [][]string, activePage string) string {
|
|
output := ""
|
|
|
|
for _, page := range pages {
|
|
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", htmlClean(Event.title), "title")
|
|
tempA += htmlElement("p", htmlClean(Event.date), "date")
|
|
tempA += htmlElement("p", htmlClean(Event.description), "desc")
|
|
tempB += htmlLinkElement(htmlElement("div", tempA, "class=\"event\""), "event/"+strconv.Itoa(Event.id), false, "class=\"event\"")
|
|
tempB += "!SPLIT"
|
|
}
|
|
output = strings.ReplaceAll(output, "!EVENTS", htmlElement("div", strings.ReplaceAll(tempB, "!SPLIT", ""), "class=\"eventList\""))
|
|
//tempC := strings.Split(tempB, "!SPLIT")
|
|
//output = strings.ReplaceAll(output, "!NEXTEVENTS", htmlElement("div", tempC[0]+tempC[1]+tempC[2]+tempC[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
|
|
}
|
|
|
|
func htmlClean(htmlString string) string {
|
|
htmlString = strings.ReplaceAll(htmlString, "<", "[")
|
|
htmlString = strings.ReplaceAll(htmlString, ">", "]")
|
|
return htmlString
|
|
}
|