Added title and favicon support
This commit is contained in:
@@ -9,9 +9,13 @@ import (
|
||||
"path/filepath"
|
||||
)
|
||||
|
||||
const replacementComment = "<!--Content-->"
|
||||
const (
|
||||
contentReplace = "<!--Content-->"
|
||||
faviconReplace = "<!--Favicon-->"
|
||||
titleReplace = "<!--Title-->"
|
||||
)
|
||||
|
||||
func sendIndexWithContent(w http.ResponseWriter, content string) {
|
||||
func sendIndexWithContent(w http.ResponseWriter, content string, title string, favicon string) {
|
||||
indexFile, err := os.Open(filepath.Join(*webRoot, "index.html"))
|
||||
if err != nil {
|
||||
log.Println("error when opening main index.html:", err)
|
||||
@@ -24,7 +28,15 @@ func sendIndexWithContent(w http.ResponseWriter, content string) {
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
dat = bytes.ReplaceAll(dat, []byte(replacementComment), []byte(content))
|
||||
dat = bytes.ReplaceAll(dat, []byte(contentReplace), []byte(content))
|
||||
if title == "" {
|
||||
title = "Darkstorm.tech"
|
||||
}
|
||||
dat = bytes.ReplaceAll(dat, []byte(titleReplace), []byte(title))
|
||||
if favicon == "" {
|
||||
favicon = "https://darkstorm.tech/favicon.png"
|
||||
}
|
||||
dat = bytes.ReplaceAll(dat, []byte(faviconReplace), []byte(favicon))
|
||||
w.Header().Set("Content-Type", "text/html; charset=utf-8")
|
||||
w.Write(dat)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user