V0.3.3: Even more optimization
Some checks failed
Build and Push Docker Image to GHCR / build-and-push (push) Has been cancelled
Some checks failed
Build and Push Docker Image to GHCR / build-and-push (push) Has been cancelled
In this realease, I have further optimized Passport. The css that Passport now uses is entirely handrolled and build via postcss (sadly). Several bugs have also been fixed in this release, as well as a few performance improvements relating to the admin UI.
This commit is contained in:
30
src/main.go
30
src/main.go
@@ -1,4 +1,4 @@
|
||||
//go:generate tailwindcss -i styles/main.scss -o assets/tailwind.css --minify
|
||||
//go:generate npm run build
|
||||
|
||||
package main
|
||||
|
||||
@@ -44,7 +44,7 @@ import (
|
||||
_ "modernc.org/sqlite"
|
||||
)
|
||||
|
||||
//go:embed assets/** templates/** schema.sql scripts/**.js styles/**.css
|
||||
//go:embed assets/** templates/** schema.sql scripts/**.js
|
||||
var embeddedAssets embed.FS
|
||||
|
||||
var devContent = `<script>
|
||||
@@ -285,7 +285,12 @@ func UploadFile(file *multipart.FileHeader, contentType string, c fiber.Ctx) (st
|
||||
return "", err
|
||||
}
|
||||
|
||||
fileName := fmt.Sprintf("%s.%s", fileId.String(), filepath.Ext(file.Filename))
|
||||
var fileName string
|
||||
if filepath.Ext(file.Filename) != ".svg" {
|
||||
fileName = fmt.Sprintf("%s.webp", fileId.String())
|
||||
} else {
|
||||
fileName = fmt.Sprintf("%s.svg", fileId.String())
|
||||
}
|
||||
|
||||
srcFile, err := file.Open()
|
||||
if err != nil {
|
||||
@@ -307,6 +312,10 @@ func UploadFile(file *multipart.FileHeader, contentType string, c fiber.Ctx) (st
|
||||
return "", errors.New("unsupported file type")
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
if contentType != "image/svg+xml" {
|
||||
off, err := srcFile.Seek(0, io.SeekStart)
|
||||
if err != nil {
|
||||
@@ -708,6 +717,10 @@ func main() {
|
||||
|
||||
engine := handlebars.NewFileSystem(http.FS(templatesDir), ".hbs")
|
||||
|
||||
engine.AddFunc("eq", func(a, b any) bool {
|
||||
return a == b
|
||||
})
|
||||
|
||||
engine.AddFunc("embedFile", func(fileToEmbed string) string {
|
||||
content, err := fs.ReadFile(embeddedAssets, fileToEmbed)
|
||||
if err != nil {
|
||||
@@ -715,6 +728,7 @@ func main() {
|
||||
}
|
||||
|
||||
fileExtension := filepath.Ext(fileToEmbed)
|
||||
|
||||
switch fileExtension {
|
||||
case ".js":
|
||||
return fmt.Sprintf("<script>%s</script>", content)
|
||||
@@ -761,10 +775,13 @@ func main() {
|
||||
|
||||
router.Use("/assets", static.New("", static.Config{
|
||||
FS: assetsDir,
|
||||
Browse: false,
|
||||
MaxAge: 31536000,
|
||||
}))
|
||||
|
||||
router.Get("/", func(c fiber.Ctx) error {
|
||||
c.Response().Header.Set("Link", "</assets/fonts/InstrumentSans-VariableFont_wdth,wght.woff2>; rel=preload; as=font; type=font/woff2; crossorigin")
|
||||
|
||||
renderData := fiber.Map{
|
||||
"SearchProviderURL": app.Config.SearchProvider.URL,
|
||||
"SearchParam": app.Config.SearchProvider.Query,
|
||||
@@ -785,7 +802,7 @@ func main() {
|
||||
renderData["UptimeData"] = app.UptimeManager.GetUptime()
|
||||
}
|
||||
|
||||
return c.Render("views/index", renderData, "layouts/main")
|
||||
return c.Render("views/index", renderData)
|
||||
})
|
||||
|
||||
router.Use(middleware.AdminMiddleware(app.db))
|
||||
@@ -795,7 +812,7 @@ func main() {
|
||||
return c.Redirect().To("/admin")
|
||||
}
|
||||
|
||||
return c.Render("views/admin/login", fiber.Map{}, "layouts/main")
|
||||
return c.Render("views/admin/login", fiber.Map{})
|
||||
})
|
||||
|
||||
router.Post("/admin/login", func(c fiber.Ctx) error {
|
||||
@@ -844,7 +861,8 @@ func main() {
|
||||
|
||||
return c.Render("views/admin/index", fiber.Map{
|
||||
"Categories": app.CategoryManager.GetCategories(),
|
||||
}, "layouts/admin")
|
||||
"IsAdmin": true,
|
||||
})
|
||||
})
|
||||
|
||||
api := router.Group("/api")
|
||||
|
||||
Reference in New Issue
Block a user