Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions home/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"encoding/json"
"html/template"
"log"
"net/http"
"os"
Expand Down Expand Up @@ -47,6 +48,14 @@ func parseConfig(file string) (ConfigJSON, error) {
return conf, nil
}

// Create a template function to allow the input string to be displayed
// unescaped - as raw HTML.
//
// Warning: This should ONLY be used on trusted input.
func displayAsRawHTML(text string) template.HTML {
return template.HTML(text)
}

func main() {
// FIXME: Let user specify config location or pass an env var with config
conf, err := parseConfig("settings.json")
Expand All @@ -57,6 +66,11 @@ func main() {
router := gin.Default()
router.Use(prometheusMiddleware()) // Attach our prometheus middleware

// Register custom template functions on the router
router.SetFuncMap(template.FuncMap{
"displayAsRawHTML": displayAsRawHTML,
})

// Load in the HTML templates
router.LoadHTMLGlob("templates/*")

Expand Down
2 changes: 1 addition & 1 deletion home/templates/alert.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<div class="container-fluid p-3 bg-white">
<div class="alert alert-danger" role="alert">
<p>{{ .Config.AlertMessage }}</p>
<p>{{ .Config.AlertMessage | displayAsRawHTML }}</p>
<!-- When congress hands out shutdown lemons, sometimes you need to make shutdown lemonade :-) -->
<!-- <marquee>{{ .Config.AlertMessage }}</marquee> -->
</div>
Expand Down
Loading