Added title and favicon support

This commit is contained in:
Caleb Gardner
2024-08-02 05:40:30 -05:00
parent fd89e568af
commit 87ac3bf270
4 changed files with 27 additions and 15 deletions
+15 -3
View File
@@ -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)
}