htmgo/htmgo-site/pages/markdown.go

42 lines
1 KiB
Go
Raw Normal View History

2024-09-20 16:45:23 +00:00
package pages
import (
2024-09-20 18:25:14 +00:00
"embed"
2024-09-20 16:45:23 +00:00
"github.com/maddalax/htmgo/framework/h"
"github.com/maddalax/htmgo/framework/htmgo/service"
2024-09-21 03:59:07 +00:00
"github.com/maddalax/htmgo/framework/hx"
2024-09-20 16:45:23 +00:00
"htmgo-site/internal/markdown"
"htmgo-site/pages/base"
2024-09-21 03:59:07 +00:00
"htmgo-site/partials"
2024-09-20 16:45:23 +00:00
)
func MarkdownHandler(ctx *h.RequestContext, path string) error {
return h.HtmlView(ctx, h.NewPage(MarkdownPage(ctx, path)))
}
func MarkdownPage(ctx *h.RequestContext, path string) *h.Element {
return base.RootPage(
h.Div(
2024-09-21 03:59:07 +00:00
h.Div(
h.GetPartial(partials.TestPartial, hx.LoadEvent),
),
2024-09-20 20:15:12 +00:00
h.Class("w-full p-4 flex flex-col justify-center items-center"),
2024-09-20 16:45:23 +00:00
MarkdownContent(ctx, path),
h.Div(
h.Class("min-h-12"),
),
),
)
}
func MarkdownContent(ctx *h.RequestContext, path string) *h.Element {
2024-09-20 18:25:14 +00:00
embeddedMd := ctx.Get("embeddedMarkdown").(*embed.FS)
2024-09-20 16:45:23 +00:00
renderer := service.Get[markdown.Renderer](ctx.ServiceLocator())
return h.Div(
h.Article(
2024-09-20 20:15:12 +00:00
h.Class("prose max-w-[95vw] md:max-w-2xl px-4 prose-code:text-black"),
2024-09-20 18:25:14 +00:00
h.Raw(renderer.RenderFile(path, embeddedMd)),
2024-09-20 16:45:23 +00:00
),
)
}