Files
site/utils/serve_page.go
2022-03-02 07:42:14 -06:00

28 lines
515 B
Go

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},
)
}
}