ctdo.de/html.go

33 lines
1005 B
Go

package main
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, ""), "")
}