Move from fileb0x to embed.FS. Fixes #22.
Also removed unused fontawesome JS.
This commit is contained in:
@@ -1,9 +1,11 @@
|
||||
package context
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/labstack/echo"
|
||||
"github.com/labstack/echo/middleware"
|
||||
"go.dev.pztrn.name/fastpastebin/assets/static"
|
||||
"go.dev.pztrn.name/fastpastebin/assets"
|
||||
)
|
||||
|
||||
func (c *Context) initializeHTTPServer() {
|
||||
@@ -16,7 +18,7 @@ func (c *Context) initializeHTTPServer() {
|
||||
c.Echo.HidePort = true
|
||||
|
||||
// Static files.
|
||||
c.Echo.GET("/static/*", echo.WrapHandler(static.Handler))
|
||||
c.Echo.GET("/static/*", echo.WrapHandler(http.FileServer(http.FS(assets.Data))))
|
||||
|
||||
listenAddress := c.Config.HTTP.Address + ":" + c.Config.HTTP.Port
|
||||
|
||||
|
@@ -4,28 +4,28 @@ import (
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"go.dev.pztrn.name/fastpastebin/assets/static"
|
||||
"go.dev.pztrn.name/fastpastebin/assets"
|
||||
)
|
||||
|
||||
// CreateHTML creates pagination HTML based on passed parameters.
|
||||
func CreateHTML(currentPage int, pages int, linksBase string) string {
|
||||
// Load templates.
|
||||
paginationHTMLRaw, err := static.ReadFile("pagination.html")
|
||||
paginationHTMLRaw, err := assets.Data.ReadFile("pagination.html")
|
||||
if err != nil {
|
||||
return "Missing pagination.html"
|
||||
}
|
||||
|
||||
paginationLinkRaw, err1 := static.ReadFile("pagination_link.html")
|
||||
paginationLinkRaw, err1 := assets.Data.ReadFile("pagination_link.html")
|
||||
if err1 != nil {
|
||||
return "Missing pagination_link.html"
|
||||
}
|
||||
|
||||
paginationLinkCurrentRaw, err2 := static.ReadFile("pagination_link_current.html")
|
||||
paginationLinkCurrentRaw, err2 := assets.Data.ReadFile("pagination_link_current.html")
|
||||
if err2 != nil {
|
||||
return "Missing pagination_link_current.html"
|
||||
}
|
||||
|
||||
paginationEllipsisRaw, err3 := static.ReadFile("pagination_ellipsis.html")
|
||||
paginationEllipsisRaw, err3 := assets.Data.ReadFile("pagination_ellipsis.html")
|
||||
if err3 != nil {
|
||||
return "Missing pagination_ellipsis.html"
|
||||
}
|
||||
|
@@ -30,7 +30,7 @@ import (
|
||||
|
||||
"github.com/labstack/echo"
|
||||
"github.com/rs/zerolog"
|
||||
"go.dev.pztrn.name/fastpastebin/assets/static"
|
||||
"go.dev.pztrn.name/fastpastebin/assets"
|
||||
"go.dev.pztrn.name/fastpastebin/internal/context"
|
||||
)
|
||||
|
||||
@@ -52,7 +52,7 @@ func GetErrorTemplate(ec echo.Context, errorText string) string {
|
||||
// GetRawTemplate returns only raw template data.
|
||||
func GetRawTemplate(ec echo.Context, templateName string, data map[string]string) string {
|
||||
// Getting main template.
|
||||
tplRaw, err := static.ReadFile(templateName)
|
||||
tplRaw, err := assets.Data.ReadFile(templateName)
|
||||
if err != nil {
|
||||
_ = ec.String(http.StatusBadRequest, templateName+" not found.")
|
||||
|
||||
@@ -73,7 +73,7 @@ func GetTemplate(ec echo.Context, name string, data map[string]string) string {
|
||||
log.Debug().Str("name", name).Msg("Requested template")
|
||||
|
||||
// Getting main template.
|
||||
mainhtml, err := static.ReadFile("main.html")
|
||||
mainhtml, err := assets.Data.ReadFile("main.html")
|
||||
if err != nil {
|
||||
_ = ec.String(http.StatusBadRequest, "main.html not found.")
|
||||
|
||||
@@ -81,7 +81,7 @@ func GetTemplate(ec echo.Context, name string, data map[string]string) string {
|
||||
}
|
||||
|
||||
// Getting navigation.
|
||||
navhtml, err1 := static.ReadFile("navigation.html")
|
||||
navhtml, err1 := assets.Data.ReadFile("navigation.html")
|
||||
if err1 != nil {
|
||||
_ = ec.String(http.StatusBadRequest, "navigation.html not found.")
|
||||
|
||||
@@ -89,7 +89,7 @@ func GetTemplate(ec echo.Context, name string, data map[string]string) string {
|
||||
}
|
||||
|
||||
// Getting footer.
|
||||
footerhtml, err2 := static.ReadFile("footer.html")
|
||||
footerhtml, err2 := assets.Data.ReadFile("footer.html")
|
||||
if err2 != nil {
|
||||
_ = ec.String(http.StatusBadRequest, "footer.html not found.")
|
||||
|
||||
@@ -103,7 +103,7 @@ func GetTemplate(ec echo.Context, name string, data map[string]string) string {
|
||||
tpl = strings.Replace(tpl, "{version}", context.Version, 1)
|
||||
|
||||
// Get requested template.
|
||||
reqhtml, err3 := static.ReadFile(name)
|
||||
reqhtml, err3 := assets.Data.ReadFile(name)
|
||||
if err3 != nil {
|
||||
_ = ec.String(http.StatusBadRequest, name+" not found.")
|
||||
|
||||
|
Reference in New Issue
Block a user