htmgo/htmgo-site/pages/markdown.go

30 lines
743 B
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/service"
2024-09-20 16:45:23 +00:00
"htmgo-site/internal/markdown"
)
2024-09-23 19:41:43 +00:00
func MarkdownPage(ctx *h.RequestContext, path string, id string) *h.Element {
return h.Div(
MarkdownContent(ctx, path, id),
2024-09-20 16:45:23 +00:00
h.Div(
h.Class("min-h-12"),
2024-09-20 16:45:23 +00:00
),
)
}
2024-09-23 19:41:43 +00:00
func MarkdownContent(ctx *h.RequestContext, path string, id 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(
2024-09-23 19:41:43 +00:00
h.If(id != "", h.Id(id)),
h.Div(
h.Class("w-full flex flex-col prose max-w-[95vw] md:max-w-3xl prose-code:text-black prose-p:my-1"),
2024-09-20 18:25:14 +00:00
h.Raw(renderer.RenderFile(path, embeddedMd)),
2024-09-20 16:45:23 +00:00
),
)
}