Starting work on the actual website

This commit is contained in:
Caleb Gardner
2024-07-13 03:31:37 -05:00
parent e43409923c
commit 15dcc2928a
6 changed files with 97 additions and 13 deletions
+30
View File
@@ -0,0 +1,30 @@
package main
import (
"bytes"
"io"
"log"
"net/http"
"os"
"path/filepath"
)
const replacementComment = "<!--Content-->"
func sendIndexWithContent(w http.ResponseWriter, content string) {
indexFile, err := os.Open(filepath.Join(*webRoot, "index.html"))
if err != nil {
log.Println("error when opening main index.html:", err)
w.WriteHeader(http.StatusNotFound)
return
}
dat, err := io.ReadAll(indexFile)
if err != nil {
log.Println("error reading main index.html:", err)
w.WriteHeader(http.StatusInternalServerError)
return
}
dat = bytes.ReplaceAll(dat, []byte(replacementComment), []byte(content))
w.Header().Set("Content-Type", "text/html; charset=utf-8")
w.Write(dat)
}