2024-09-20 16:45:23 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"github.com/maddalax/htmgo/framework/h"
|
2024-09-23 01:59:44 +00:00
|
|
|
"github.com/maddalax/htmgo/framework/service"
|
2024-09-23 02:15:53 +00:00
|
|
|
"htmgo-site/__htmgo"
|
2024-09-20 16:45:23 +00:00
|
|
|
"htmgo-site/internal/markdown"
|
2024-09-20 18:25:14 +00:00
|
|
|
"io/fs"
|
2024-09-26 19:15:57 +00:00
|
|
|
"net/http"
|
2024-09-20 16:45:23 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
|
locator := service.NewLocator()
|
2024-09-25 15:44:43 +00:00
|
|
|
staticAssets := GetStaticAssets()
|
|
|
|
|
markdownAssets := GetMarkdownAssets()
|
2024-09-20 16:45:23 +00:00
|
|
|
|
|
|
|
|
service.Set(locator, service.Singleton, markdown.NewRenderer)
|
|
|
|
|
|
|
|
|
|
h.Start(h.AppOpts{
|
|
|
|
|
ServiceLocator: locator,
|
|
|
|
|
LiveReload: true,
|
2024-09-26 19:15:57 +00:00
|
|
|
Register: func(app *h.App) {
|
|
|
|
|
|
|
|
|
|
app.UseWithContext(func(w http.ResponseWriter, r *http.Request, context map[string]any) {
|
|
|
|
|
context["embeddedMarkdown"] = markdownAssets
|
|
|
|
|
})
|
|
|
|
|
|
2024-09-25 15:44:43 +00:00
|
|
|
sub, err := fs.Sub(staticAssets, "assets/dist")
|
2024-09-26 19:15:57 +00:00
|
|
|
|
2024-09-25 15:44:43 +00:00
|
|
|
if err != nil {
|
|
|
|
|
panic(err)
|
|
|
|
|
}
|
2024-09-20 18:25:14 +00:00
|
|
|
|
2024-09-26 19:15:57 +00:00
|
|
|
http.FileServerFS(sub)
|
|
|
|
|
|
|
|
|
|
app.Router.Handle("/public/*", http.StripPrefix("/public", http.FileServerFS(sub)))
|
2024-09-20 18:25:14 +00:00
|
|
|
|
2024-09-26 19:15:57 +00:00
|
|
|
__htmgo.Register(app.Router)
|
2024-09-20 16:45:23 +00:00
|
|
|
},
|
|
|
|
|
})
|
|
|
|
|
}
|