2024-09-20 16:45:23 +00:00
|
|
|
package pages
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"github.com/maddalax/htmgo/framework/h"
|
2024-09-23 01:59:44 +00:00
|
|
|
"github.com/maddalax/htmgo/framework/service"
|
2024-09-20 16:45:23 +00:00
|
|
|
"htmgo-site/internal/markdown"
|
2024-09-25 15:44:43 +00:00
|
|
|
"io/fs"
|
2024-09-20 16:45:23 +00:00
|
|
|
)
|
|
|
|
|
|
2024-09-23 19:41:43 +00:00
|
|
|
func MarkdownPage(ctx *h.RequestContext, path string, id string) *h.Element {
|
2024-09-25 03:41:03 +00:00
|
|
|
return h.Div(
|
|
|
|
|
MarkdownContent(ctx, path, id),
|
2024-09-20 16:45:23 +00:00
|
|
|
h.Div(
|
2024-09-25 03:41:03 +00:00
|
|
|
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-25 15:44:43 +00:00
|
|
|
embeddedMd := ctx.Get("embeddedMarkdown").(fs.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)),
|
2024-09-25 03:41:03 +00:00
|
|
|
h.Div(
|
2024-09-25 04:17:04 +00:00
|
|
|
h.Class("w-full flex flex-col prose max-w-[95vw] md:max-w-3xl prose-code:text-black prose-p:my-1 prose:p-0 prose-li:m-0 prose-ul:m-0 prose-ol:m-0"),
|
2024-09-20 18:25:14 +00:00
|
|
|
h.Raw(renderer.RenderFile(path, embeddedMd)),
|
2024-09-20 16:45:23 +00:00
|
|
|
),
|
|
|
|
|
)
|
|
|
|
|
}
|