Bootstrapped during the 2026-06-06 BlockNinja consolidation. Was previously an unversioned directory inside ~/src/blockninja-themes/earthen. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
274 lines
8.4 KiB
Plaintext
274 lines
8.4 KiB
Plaintext
package main
|
|
|
|
import (
|
|
"context"
|
|
"git.dev.alexdunmow.com/block/core/templates/bn"
|
|
)
|
|
|
|
// PageData contains the data for a rendered Earthen page.
|
|
type PageData struct {
|
|
Title string
|
|
Slots map[string]string
|
|
ThemeMode string
|
|
ThemeCSS string
|
|
SiteSettings bn.SiteSettingsData
|
|
PageMeta bn.PageMeta
|
|
StructuredData string
|
|
CSSHash string
|
|
PageviewNonce string
|
|
EngagementConfig bn.EngagementConfig
|
|
}
|
|
|
|
func parseEarthenPageData(doc map[string]any) PageData {
|
|
title := "Untitled"
|
|
if t, ok := doc["title"].(string); ok {
|
|
title = t
|
|
}
|
|
|
|
slots := make(map[string]string)
|
|
if s, ok := doc["slots"].(map[string]string); ok {
|
|
slots = s
|
|
}
|
|
|
|
themeCSS := ""
|
|
if tc, ok := doc["theme_css"].(string); ok {
|
|
themeCSS = tc
|
|
}
|
|
|
|
structuredData := ""
|
|
if sd, ok := doc["structured_data"].(string); ok {
|
|
structuredData = sd
|
|
}
|
|
|
|
cssHash := ""
|
|
if ch, ok := doc["css_hash"].(string); ok {
|
|
cssHash = ch
|
|
}
|
|
|
|
pageviewNonce := ""
|
|
if pn, ok := doc["pageview_nonce"].(string); ok {
|
|
pageviewNonce = pn
|
|
}
|
|
|
|
themeMode := "light"
|
|
if tm, ok := doc["theme_mode"].(string); ok && tm != "" {
|
|
themeMode = tm
|
|
}
|
|
|
|
siteSettings := bn.ParseSiteSettings(doc)
|
|
pageMeta := bn.ParsePageMeta(doc)
|
|
engagementConfig := bn.ParseEngagementConfig(doc)
|
|
|
|
return PageData{
|
|
Title: title,
|
|
Slots: slots,
|
|
ThemeMode: themeMode,
|
|
ThemeCSS: themeCSS,
|
|
SiteSettings: siteSettings,
|
|
PageMeta: pageMeta,
|
|
StructuredData: structuredData,
|
|
CSSHash: cssHash,
|
|
PageviewNonce: pageviewNonce,
|
|
EngagementConfig: engagementConfig,
|
|
}
|
|
}
|
|
|
|
// EarthenDefault renders the default Earthen page (header, main, footer).
|
|
templ EarthenDefault(data PageData) {
|
|
<!DOCTYPE html>
|
|
<html lang="en" class="earthen">
|
|
@bn.Head(bn.HeadData{
|
|
Title: data.Title,
|
|
Settings: data.SiteSettings,
|
|
PageMeta: data.PageMeta,
|
|
ThemeMode: data.ThemeMode,
|
|
ThemeCSS: data.ThemeCSS,
|
|
PluginStyles: []string{"/templates/earthen/css/earthen.css"},
|
|
StructuredData: data.StructuredData,
|
|
CSSHash: data.CSSHash,
|
|
PageviewNonce: data.PageviewNonce,
|
|
EngagementConfig: data.EngagementConfig,
|
|
})
|
|
<body
|
|
class="bg-paper-grain earthen-body antialiased min-h-screen flex flex-col"
|
|
style="background-color: hsl(var(--background)); color: hsl(var(--foreground)); font-family: var(--font-body, "Spectral", Georgia, serif);"
|
|
>
|
|
@bn.AdminBypassBanner(data.SiteSettings)
|
|
<header class="w-full">
|
|
@templ.Raw(data.Slots["header"])
|
|
</header>
|
|
<main class="flex-grow w-full max-w-5xl mx-auto px-4 py-10">
|
|
if main, ok := data.Slots["main"]; ok && main != "" {
|
|
@templ.Raw(main)
|
|
} else {
|
|
<div class="py-20 text-center" style="color: hsl(var(--muted-foreground));">
|
|
<p>No content blocks assigned to this page.</p>
|
|
</div>
|
|
}
|
|
</main>
|
|
<footer class="w-full mt-auto">
|
|
@templ.Raw(data.Slots["footer"])
|
|
</footer>
|
|
@bn.BodyEnd(data.SiteSettings)
|
|
</body>
|
|
</html>
|
|
}
|
|
|
|
// EarthenLanding renders the landing template (hero, main, cta, footer).
|
|
templ EarthenLanding(data PageData) {
|
|
<!DOCTYPE html>
|
|
<html lang="en" class="earthen">
|
|
@bn.Head(bn.HeadData{
|
|
Title: data.Title,
|
|
Settings: data.SiteSettings,
|
|
PageMeta: data.PageMeta,
|
|
ThemeMode: data.ThemeMode,
|
|
ThemeCSS: data.ThemeCSS,
|
|
PluginStyles: []string{"/templates/earthen/css/earthen.css"},
|
|
StructuredData: data.StructuredData,
|
|
CSSHash: data.CSSHash,
|
|
PageviewNonce: data.PageviewNonce,
|
|
EngagementConfig: data.EngagementConfig,
|
|
})
|
|
<body
|
|
class="bg-paper-grain earthen-body antialiased min-h-screen flex flex-col"
|
|
style="background-color: hsl(var(--background)); color: hsl(var(--foreground)); font-family: var(--font-body, "Spectral", Georgia, serif);"
|
|
>
|
|
@bn.AdminBypassBanner(data.SiteSettings)
|
|
<section class="w-full">
|
|
@templ.Raw(data.Slots["hero"])
|
|
</section>
|
|
<main class="flex-grow">
|
|
if main, ok := data.Slots["main"]; ok && main != "" {
|
|
<div class="max-w-5xl mx-auto px-4 py-16">
|
|
@templ.Raw(main)
|
|
</div>
|
|
}
|
|
</main>
|
|
<section class="w-full">
|
|
@templ.Raw(data.Slots["cta"])
|
|
</section>
|
|
<footer class="w-full mt-auto">
|
|
@templ.Raw(data.Slots["footer"])
|
|
</footer>
|
|
@bn.BodyEnd(data.SiteSettings)
|
|
</body>
|
|
</html>
|
|
}
|
|
|
|
// EarthenArticle renders the article template (header, lede, main, aside, footer).
|
|
templ EarthenArticle(data PageData) {
|
|
<!DOCTYPE html>
|
|
<html lang="en" class="earthen">
|
|
@bn.Head(bn.HeadData{
|
|
Title: data.Title,
|
|
Settings: data.SiteSettings,
|
|
PageMeta: data.PageMeta,
|
|
ThemeMode: data.ThemeMode,
|
|
ThemeCSS: data.ThemeCSS,
|
|
PluginStyles: []string{"/templates/earthen/css/earthen.css"},
|
|
StructuredData: data.StructuredData,
|
|
CSSHash: data.CSSHash,
|
|
PageviewNonce: data.PageviewNonce,
|
|
EngagementConfig: data.EngagementConfig,
|
|
})
|
|
<body
|
|
class="bg-paper-grain earthen-body antialiased min-h-screen flex flex-col"
|
|
style="background-color: hsl(var(--background)); color: hsl(var(--foreground)); font-family: var(--font-body, "Spectral", Georgia, serif);"
|
|
>
|
|
@bn.AdminBypassBanner(data.SiteSettings)
|
|
<header class="w-full" style="border-bottom: 1px solid hsl(var(--border));">
|
|
<div class="max-w-3xl mx-auto px-4">
|
|
@templ.Raw(data.Slots["header"])
|
|
</div>
|
|
</header>
|
|
if lede, ok := data.Slots["lede"]; ok && lede != "" {
|
|
<section class="w-full max-w-3xl mx-auto px-4 pt-12">
|
|
@templ.Raw(lede)
|
|
</section>
|
|
}
|
|
<div class="flex-grow w-full grid grid-cols-1 lg:grid-cols-[1fr,260px] gap-12 max-w-5xl mx-auto px-4 py-12">
|
|
<main>
|
|
if main, ok := data.Slots["main"]; ok && main != "" {
|
|
<article class="earthen-article">
|
|
@templ.Raw(main)
|
|
</article>
|
|
} else {
|
|
<p style="color: hsl(var(--muted-foreground));">No story body yet.</p>
|
|
}
|
|
</main>
|
|
if aside, ok := data.Slots["aside"]; ok && aside != "" {
|
|
<aside class="earthen-aside text-sm">
|
|
@templ.Raw(aside)
|
|
</aside>
|
|
}
|
|
</div>
|
|
<footer class="w-full mt-auto">
|
|
@templ.Raw(data.Slots["footer"])
|
|
</footer>
|
|
@bn.BodyEnd(data.SiteSettings)
|
|
</body>
|
|
</html>
|
|
}
|
|
|
|
// EarthenFullWidth renders edge-to-edge pages (header, main, footer).
|
|
templ EarthenFullWidth(data PageData) {
|
|
<!DOCTYPE html>
|
|
<html lang="en" class="earthen">
|
|
@bn.Head(bn.HeadData{
|
|
Title: data.Title,
|
|
Settings: data.SiteSettings,
|
|
PageMeta: data.PageMeta,
|
|
ThemeMode: data.ThemeMode,
|
|
ThemeCSS: data.ThemeCSS,
|
|
PluginStyles: []string{"/templates/earthen/css/earthen.css"},
|
|
StructuredData: data.StructuredData,
|
|
CSSHash: data.CSSHash,
|
|
PageviewNonce: data.PageviewNonce,
|
|
EngagementConfig: data.EngagementConfig,
|
|
})
|
|
<body
|
|
class="bg-paper-grain earthen-body antialiased min-h-screen flex flex-col"
|
|
style="background-color: hsl(var(--background)); color: hsl(var(--foreground)); font-family: var(--font-body, "Spectral", Georgia, serif);"
|
|
>
|
|
@bn.AdminBypassBanner(data.SiteSettings)
|
|
<header class="w-full">
|
|
@templ.Raw(data.Slots["header"])
|
|
</header>
|
|
<main class="flex-grow w-full">
|
|
if main, ok := data.Slots["main"]; ok && main != "" {
|
|
@templ.Raw(main)
|
|
} else {
|
|
<div class="max-w-4xl mx-auto py-20 px-4 text-center" style="color: hsl(var(--muted-foreground));">
|
|
<p>No content blocks assigned to this page.</p>
|
|
</div>
|
|
}
|
|
</main>
|
|
<footer class="w-full mt-auto">
|
|
@templ.Raw(data.Slots["footer"])
|
|
</footer>
|
|
@bn.BodyEnd(data.SiteSettings)
|
|
</body>
|
|
</html>
|
|
}
|
|
|
|
// RenderEarthenDefault is the templates.TemplateFunc entry for "default".
|
|
func RenderEarthenDefault(ctx context.Context, doc map[string]any) templ.Component {
|
|
return EarthenDefault(parseEarthenPageData(doc))
|
|
}
|
|
|
|
// RenderEarthenLanding is the templates.TemplateFunc entry for "landing".
|
|
func RenderEarthenLanding(ctx context.Context, doc map[string]any) templ.Component {
|
|
return EarthenLanding(parseEarthenPageData(doc))
|
|
}
|
|
|
|
// RenderEarthenArticle is the templates.TemplateFunc entry for "article".
|
|
func RenderEarthenArticle(ctx context.Context, doc map[string]any) templ.Component {
|
|
return EarthenArticle(parseEarthenPageData(doc))
|
|
}
|
|
|
|
// RenderEarthenFullWidth is the templates.TemplateFunc entry for "full-width".
|
|
func RenderEarthenFullWidth(ctx context.Context, doc map[string]any) templ.Component {
|
|
return EarthenFullWidth(parseEarthenPageData(doc))
|
|
}
|