Added title and favicon support
This commit is contained in:
@@ -18,7 +18,7 @@ const (
|
|||||||
|
|
||||||
authorInfo = `
|
authorInfo = `
|
||||||
<table><tr>
|
<table><tr>
|
||||||
<td><img src="%v" alt="%v" style="width:100px"></td>
|
<td><img src="%v" alt="%v" class='author-pic'></td>
|
||||||
<td><h2 class="author-title">%v</h2>%v</td>
|
<td><h2 class="author-title">%v</h2>%v</td>
|
||||||
</tr></table>`
|
</tr></table>`
|
||||||
)
|
)
|
||||||
@@ -28,19 +28,19 @@ func latestBlogsHandle(w http.ResponseWriter, _ *http.Request) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
if err == backend.ErrNotFound {
|
if err == backend.ErrNotFound {
|
||||||
w.WriteHeader(404)
|
w.WriteHeader(404)
|
||||||
sendIndexWithContent(w, "Page not found")
|
sendIndexWithContent(w, "Page not found", "", "")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
w.WriteHeader(http.StatusInternalServerError)
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
log.Println("error getting latest blogs:", err)
|
log.Println("error getting latest blogs:", err)
|
||||||
sendIndexWithContent(w, "Error getting page")
|
sendIndexWithContent(w, "Error getting page", "", "")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
var out string
|
var out string
|
||||||
for _, b := range latest {
|
for _, b := range latest {
|
||||||
out += blogElement(b)
|
out += blogElement(b)
|
||||||
}
|
}
|
||||||
sendIndexWithContent(w, out)
|
sendIndexWithContent(w, out, "", "")
|
||||||
}
|
}
|
||||||
|
|
||||||
func blogHandle(w http.ResponseWriter, blog string) {
|
func blogHandle(w http.ResponseWriter, blog string) {
|
||||||
@@ -48,15 +48,15 @@ func blogHandle(w http.ResponseWriter, blog string) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
if err == backend.ErrNotFound {
|
if err == backend.ErrNotFound {
|
||||||
w.WriteHeader(404)
|
w.WriteHeader(404)
|
||||||
sendIndexWithContent(w, "Page not found")
|
sendIndexWithContent(w, "Page not found", "", "")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
w.WriteHeader(http.StatusInternalServerError)
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
log.Printf("error getting blog %v: %v\n", blog, err)
|
log.Printf("error getting blog %v: %v\n", blog, err)
|
||||||
sendIndexWithContent(w, "Error getting page")
|
sendIndexWithContent(w, "Error getting page", "", "")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
sendIndexWithContent(w, blogElement(bl))
|
sendIndexWithContent(w, blogElement(bl), bl.Title, bl.Favicon)
|
||||||
}
|
}
|
||||||
|
|
||||||
func blogElement(b *blog.Blog) (out string) {
|
func blogElement(b *blog.Blog) (out string) {
|
||||||
|
|||||||
@@ -48,6 +48,6 @@ func filesRequest(w http.ResponseWriter, r *http.Request) {
|
|||||||
if r.URL.Query().Get("contentOnly") == "true" {
|
if r.URL.Query().Get("contentOnly") == "true" {
|
||||||
w.Write([]byte(pageContent))
|
w.Write([]byte(pageContent))
|
||||||
} else {
|
} else {
|
||||||
sendIndexWithContent(w, pageContent)
|
sendIndexWithContent(w, pageContent, "Files", "")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+4
-4
@@ -23,16 +23,16 @@ func portfolioRequest(w http.ResponseWriter, r *http.Request) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println("error getting portfolio projects:", err)
|
log.Println("error getting portfolio projects:", err)
|
||||||
w.WriteHeader(http.StatusInternalServerError)
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
sendIndexWithContent(w, "Error getting portfolio")
|
sendIndexWithContent(w, "Error getting portfolio", "", "")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
aboutMe := "<h1 style='margin-bottom:-5px'>About Me</h1>"
|
aboutMe := "<h1 class='about-me-header'>About Me</h1>"
|
||||||
if me, err := blogApp.AboutMe(); err != nil {
|
if me, err := blogApp.AboutMe(); err != nil {
|
||||||
aboutMe += "Error getting info about me :("
|
aboutMe += "Error getting info about me :("
|
||||||
} else {
|
} else {
|
||||||
aboutMe += authorSection(me)
|
aboutMe += authorSection(me)
|
||||||
}
|
}
|
||||||
aboutMe += "<h1 style='margin-bottom:15px'>My Projects</h1>"
|
aboutMe += "<h1 class='my-projects-header' style='margin-bottom:15px'>My Projects</h1>"
|
||||||
langs := make(map[string]struct{})
|
langs := make(map[string]struct{})
|
||||||
out := ""
|
out := ""
|
||||||
for _, p := range proj {
|
for _, p := range proj {
|
||||||
@@ -63,5 +63,5 @@ func portfolioRequest(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
out = aboutMe + fmt.Sprintf(portfolioSelector, tmp) + out
|
out = aboutMe + fmt.Sprintf(portfolioSelector, tmp) + out
|
||||||
sendIndexWithContent(w, out)
|
sendIndexWithContent(w, out, "Portfolio", "")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,9 +9,13 @@ import (
|
|||||||
"path/filepath"
|
"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"))
|
indexFile, err := os.Open(filepath.Join(*webRoot, "index.html"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println("error when opening main index.html:", err)
|
log.Println("error when opening main index.html:", err)
|
||||||
@@ -24,7 +28,15 @@ func sendIndexWithContent(w http.ResponseWriter, content string) {
|
|||||||
w.WriteHeader(http.StatusInternalServerError)
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
return
|
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.Header().Set("Content-Type", "text/html; charset=utf-8")
|
||||||
w.Write(dat)
|
w.Write(dat)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user