Added contentOnly query to send html content as json

This commit is contained in:
Caleb Gardner
2024-08-06 16:46:25 -05:00
parent 0d40dd95c1
commit f99c9bd2fb
5 changed files with 18 additions and 17 deletions
+6 -1
View File
@@ -2,6 +2,7 @@ package main
import (
"bytes"
"encoding/json"
"io"
"log"
"net/http"
@@ -15,7 +16,11 @@ const (
titleReplace = "<!--Title-->"
)
func sendIndexWithContent(w http.ResponseWriter, content string, title string, favicon string) {
func sendContent(w http.ResponseWriter, r *http.Request, content string, title string, favicon string) {
if r.URL.Query().Get("contentOnly") == "true" {
json.NewEncoder(w).Encode(map[string]string{"content": content, "title": title, "favicon": favicon})
return
}
indexFile, err := os.Open(filepath.Join(*webRoot, "index.html"))
if err != nil {
log.Println("error when opening main index.html:", err)