2023-01-26 20:58:13 +00:00
package main
2023-01-29 12:55:32 +00:00
import (
"strconv"
"strings"
)
2023-01-26 22:13:44 +00:00
func htmlElement ( tag string , innerHTML string , args string ) string {
2023-01-26 20:58:13 +00:00
return "<" + tag + " " + args + ">" + innerHTML + "</" + tag + ">"
}
2023-01-26 22:13:44 +00:00
func htmlLinkElement ( innerHTML string , destination string , blank bool , args string ) string {
2023-01-26 20:58:13 +00:00
b := ""
if blank {
2023-01-27 14:30:42 +00:00
b = "target=\"_blank\" "
2023-01-26 20:58:13 +00:00
}
2023-01-27 14:30:42 +00:00
return htmlElement ( "a" , innerHTML , " href=\"" + destination + "\" " + b + args )
2023-01-26 20:58:13 +00:00
}
2023-01-26 22:13:44 +00:00
func htmlInputElement ( name string , _type string , value string , args string ) string {
2023-01-26 20:58:13 +00:00
return "<input name=\"" + name + "\" type=\"" + _type + "\" value=\"" + value + "\" " + args + ">"
}
2023-01-27 14:30:42 +00:00
func htmlNav ( pages [ ] [ ] string , activePage string ) string {
2023-01-26 20:58:13 +00:00
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 , "" ) , "" )
}
2023-01-26 20:58:13 +00:00
}
2023-01-26 22:13:44 +00:00
return htmlElement ( "nav" , htmlElement ( "ul" , output , "" ) , "" )
2023-01-26 20:58:13 +00:00
}
2023-01-29 12:55:32 +00:00
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
}
2023-01-29 17:51:29 +00:00
tempA = htmlElement ( "h2" , htmlClean ( Event . title ) , "title" )
tempA += htmlElement ( "p" , htmlClean ( Event . date ) , "date" )
tempA += htmlElement ( "p" , htmlClean ( Event . description ) , "desc" )
if i > 0 {
tempB += "!SPLIT"
}
tempB += htmlLinkElement ( htmlElement ( "div" , tempA , "" ) , "event/" + string ( Event . id ) , false , "class=\"event\"" )
2023-01-29 12:55:32 +00:00
}
2023-01-29 17:51:29 +00:00
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\"" ) )
2023-01-29 12:55:32 +00:00
}
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
}
2023-01-29 15:33:16 +00:00
func htmlClean ( htmlString string ) string {
htmlString = strings . ReplaceAll ( htmlString , "<" , "[" )
htmlString = strings . ReplaceAll ( htmlString , ">" , "]" )
return htmlString
}