2024-09-20 16:45:23 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
|
|
import (
|
2024-09-20 18:25:14 +00:00
|
|
|
"embed"
|
2024-09-21 17:23:47 +00:00
|
|
|
"fmt"
|
2024-09-20 16:45:23 +00:00
|
|
|
"github.com/labstack/echo/v4"
|
|
|
|
|
"github.com/maddalax/htmgo/framework/h"
|
|
|
|
|
"github.com/maddalax/htmgo/framework/htmgo/service"
|
|
|
|
|
_ "github.com/mattn/go-sqlite3"
|
|
|
|
|
"htmgo-site/internal/markdown"
|
|
|
|
|
"htmgo-site/pages"
|
|
|
|
|
"htmgo-site/partials/load"
|
2024-09-20 18:25:14 +00:00
|
|
|
"io/fs"
|
2024-09-20 16:45:23 +00:00
|
|
|
)
|
|
|
|
|
|
2024-09-20 18:25:14 +00:00
|
|
|
//go:embed assets/dist/*
|
|
|
|
|
var StaticAssets embed.FS
|
|
|
|
|
|
|
|
|
|
//go:embed md/*
|
|
|
|
|
var MarkdownAssets embed.FS
|
|
|
|
|
|
2024-09-20 16:45:23 +00:00
|
|
|
func main() {
|
|
|
|
|
locator := service.NewLocator()
|
|
|
|
|
|
|
|
|
|
service.Set(locator, service.Singleton, markdown.NewRenderer)
|
|
|
|
|
|
2024-09-20 18:25:14 +00:00
|
|
|
sub, err := fs.Sub(StaticAssets, "assets/dist")
|
|
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
panic(err)
|
|
|
|
|
}
|
|
|
|
|
|
2024-09-21 17:23:47 +00:00
|
|
|
fmt.Println("test")
|
|
|
|
|
|
2024-09-20 16:45:23 +00:00
|
|
|
h.Start(h.AppOpts{
|
|
|
|
|
ServiceLocator: locator,
|
|
|
|
|
LiveReload: true,
|
|
|
|
|
Register: func(e *echo.Echo) {
|
2024-09-20 18:25:14 +00:00
|
|
|
e.StaticFS("/public", sub)
|
|
|
|
|
|
|
|
|
|
e.Use(func(next echo.HandlerFunc) echo.HandlerFunc {
|
|
|
|
|
return func(c echo.Context) error {
|
|
|
|
|
c.Set("embeddedMarkdown", &MarkdownAssets)
|
|
|
|
|
return next(c)
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
|
2024-09-20 16:45:23 +00:00
|
|
|
load.RegisterPartials(e)
|
|
|
|
|
pages.RegisterPages(e)
|
2024-09-20 18:25:14 +00:00
|
|
|
pages.RegisterMarkdown(e, "md", MarkdownAssets, func(ctx echo.Context, path string) error {
|
2024-09-20 16:45:23 +00:00
|
|
|
return pages.MarkdownHandler(ctx.(*h.RequestContext), path)
|
|
|
|
|
})
|
|
|
|
|
},
|
|
|
|
|
})
|
|
|
|
|
}
|