72 lines
1.6 KiB
Go
72 lines
1.6 KiB
Go
package main
|
|
|
|
import (
|
|
"html/template"
|
|
"net/http"
|
|
|
|
"git.tijl.dev/tijl/tijl.dev/internal/assets"
|
|
"git.tijl.dev/tijl/tijl.dev/internal/config"
|
|
"git.tijl.dev/tijl/tijl.dev/internal/i18n"
|
|
"git.tijl.dev/tijl/tijl.dev/static"
|
|
"git.tijl.dev/tijl/tijl.dev/views"
|
|
"github.com/gofiber/fiber/v2"
|
|
"github.com/gofiber/fiber/v2/middleware/filesystem"
|
|
"github.com/gofiber/template/html/v2"
|
|
"github.com/mikhail-bigun/fiberlogrus"
|
|
log "github.com/sirupsen/logrus"
|
|
)
|
|
|
|
func main() {
|
|
log.SetLevel(log.DebugLevel)
|
|
|
|
config.Load()
|
|
|
|
assets.Load()
|
|
i18n.Load()
|
|
|
|
engine := html.NewFileSystem(http.FS(views.Embed), ".html")
|
|
|
|
engine.AddFunc("icon", assets.Svg)
|
|
|
|
// Todo better language system
|
|
engine.AddFunc("translate", func(key string) template.HTML {
|
|
translations := i18n.GetTranslations()["en"] // for now we just fix it to english
|
|
if translation, ok := translations[key]; ok {
|
|
return template.HTML(translation)
|
|
}
|
|
return ""
|
|
})
|
|
|
|
app := fiber.New(fiber.Config{
|
|
Views: engine,
|
|
DisableStartupMessage: true,
|
|
})
|
|
|
|
app.Use(fiberlogrus.New())
|
|
|
|
app.Get("/", func(c *fiber.Ctx) error {
|
|
return c.Render("index", getCommon(c))
|
|
})
|
|
app.Get("/blog", func(c *fiber.Ctx) error {
|
|
return c.Render("blog", getCommon(c))
|
|
})
|
|
app.Get("/projects", func(c *fiber.Ctx) error {
|
|
return c.Render("projects", getCommon(c))
|
|
})
|
|
app.Get("/about", func(c *fiber.Ctx) error {
|
|
return c.Render("about", getCommon(c))
|
|
})
|
|
|
|
app.Use("/static", filesystem.New(filesystem.Config{
|
|
Root: http.FS(static.Embed),
|
|
}))
|
|
|
|
log.Fatal(app.Listen(":3000"))
|
|
}
|
|
|
|
func getCommon(c *fiber.Ctx) fiber.Map {
|
|
return fiber.Map{
|
|
"Path": c.Path(),
|
|
}
|
|
}
|