added admin page, adjusted way of creating posts

This commit is contained in:
rawleyIfowler
2022-03-02 07:42:14 -06:00
parent cefeeec11a
commit 402f36534f
9 changed files with 274 additions and 65 deletions

20
utils/admin_hash.go Normal file
View File

@@ -0,0 +1,20 @@
package utils
import (
"bufio"
"os"
)
func LoadAdminHash(path string) string {
file, err := os.Open(path)
if err != nil {
panic("Could not find DSN for database...")
}
defer file.Close()
reader := bufio.NewScanner(file)
// The dsn should be the first line of the file
if reader.Scan() {
return reader.Text()
}
panic(path + " is empty...")
}

27
utils/serve_page.go Normal file
View File

@@ -0,0 +1,27 @@
package utils
import (
"net/http"
"strings"
"github.com/gin-gonic/gin"
)
// Returns a handler function to serve a page based on the template that is inputted
func ServePage(temp string) gin.HandlerFunc {
title := strings.Split(temp, ".")[0]
if title == "index" {
// Index is the home page so we don't care
title = ""
} else {
// Else title it accordingly
title = " | " + title
}
return func(c *gin.Context) {
c.HTML(
http.StatusOK,
temp,
struct{ Title string }{Title: title},
)
}
}