themes-magazine-bold/template.templ
Alex Dunmow fe754f634b initial: theme plugin magazine-bold
Bootstrapped during the 2026-06-06 BlockNinja consolidation. Was previously
an unversioned directory inside ~/src/blockninja-themes/magazine-bold.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-06-06 14:11:38 +08:00

247 lines
7.2 KiB
Plaintext

package main
import (
"context"
"git.dev.alexdunmow.com/block/core/templates/bn"
)
// PageData carries the data the Magazine Bold page templates render.
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 parseMagazineBoldPageData(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,
}
}
// mbHead reuses the core head component with the magazine-bold plugin style sheet.
templ mbHead(data PageData) {
@bn.Head(bn.HeadData{
Title: data.Title,
Settings: data.SiteSettings,
PageMeta: data.PageMeta,
ThemeMode: data.ThemeMode,
ThemeCSS: data.ThemeCSS,
PluginStyles: []string{"/templates/magazine-bold/style.css"},
StructuredData: data.StructuredData,
CSSHash: data.CSSHash,
PageviewNonce: data.PageviewNonce,
EngagementConfig: data.EngagementConfig,
})
}
// MagazineBold — default page template.
// Slots: masthead, main, colophon.
templ MagazineBold(data PageData) {
<!DOCTYPE html>
<html lang="en">
@mbHead(data)
<body class="bg-background text-foreground antialiased min-h-screen flex flex-col font-sans">
@bn.AdminBypassBanner(data.SiteSettings)
<header class="w-full mb-hairline-bottom">
<div class="max-w-6xl mx-auto px-6">
@templ.Raw(data.Slots["masthead"])
</div>
</header>
<main class="flex-grow w-full">
<div class="max-w-6xl mx-auto px-6 py-12">
if main, ok := data.Slots["main"]; ok && main != "" {
@templ.Raw(main)
} else {
<div class="py-20 text-center font-mono mb-caption">No content blocks assigned to this page.</div>
}
</div>
</main>
<footer class="w-full mt-auto mb-hairline-top">
<div class="max-w-6xl mx-auto px-6">
@templ.Raw(data.Slots["colophon"])
</div>
</footer>
@bn.BodyEnd(data.SiteSettings)
</body>
</html>
}
// MagazineBoldLanding — issue landing page template.
// Slots: cover, secondary, main, colophon.
templ MagazineBoldLanding(data PageData) {
<!DOCTYPE html>
<html lang="en">
@mbHead(data)
<body class="bg-background text-foreground antialiased min-h-screen flex flex-col font-sans">
@bn.AdminBypassBanner(data.SiteSettings)
<section class="w-full">
@templ.Raw(data.Slots["cover"])
</section>
<section class="w-full border-t border-b mb-hairline">
<div class="max-w-6xl mx-auto px-6 py-10">
@templ.Raw(data.Slots["secondary"])
</div>
</section>
<main class="flex-grow w-full">
<div class="max-w-6xl mx-auto px-6 py-12">
if main, ok := data.Slots["main"]; ok && main != "" {
@templ.Raw(main)
} else {
<div class="py-20 text-center font-mono mb-caption">No content blocks assigned to this page.</div>
}
</div>
</main>
<footer class="w-full mt-auto mb-hairline-top">
<div class="max-w-6xl mx-auto px-6">
@templ.Raw(data.Slots["colophon"])
</div>
</footer>
@bn.BodyEnd(data.SiteSettings)
</body>
</html>
}
// MagazineBoldArticle — long-form feature template with deck and pull-quote gutter.
// Slots: masthead, deck, main, colophon.
templ MagazineBoldArticle(data PageData) {
<!DOCTYPE html>
<html lang="en">
@mbHead(data)
<body class="bg-background text-foreground antialiased min-h-screen flex flex-col font-sans">
@bn.AdminBypassBanner(data.SiteSettings)
<header class="w-full mb-hairline-bottom">
<div class="max-w-6xl mx-auto px-6">
@templ.Raw(data.Slots["masthead"])
</div>
</header>
<section class="w-full">
<div class="max-w-6xl mx-auto px-6 py-10">
@templ.Raw(data.Slots["deck"])
</div>
</section>
<main class="flex-grow w-full">
<div class="max-w-4xl mx-auto px-6 py-12">
if main, ok := data.Slots["main"]; ok && main != "" {
<article class="mb-body">
@templ.Raw(main)
</article>
} else {
<div class="py-20 text-center font-mono mb-caption">No content blocks assigned to this page.</div>
}
</div>
</main>
<footer class="w-full mt-auto mb-hairline-top">
<div class="max-w-6xl mx-auto px-6">
@templ.Raw(data.Slots["colophon"])
</div>
</footer>
@bn.BodyEnd(data.SiteSettings)
</body>
</html>
}
// MagazineBoldFullWidth — edge-to-edge photo-essay template.
// Slots: masthead, main, colophon.
templ MagazineBoldFullWidth(data PageData) {
<!DOCTYPE html>
<html lang="en">
@mbHead(data)
<body class="bg-background text-foreground antialiased min-h-screen flex flex-col font-sans">
@bn.AdminBypassBanner(data.SiteSettings)
<header class="w-full mb-hairline-bottom">
<div class="max-w-6xl mx-auto px-6">
@templ.Raw(data.Slots["masthead"])
</div>
</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-6 text-center font-mono mb-caption">No content blocks assigned to this page.</div>
}
</main>
<footer class="w-full mt-auto mb-hairline-top">
<div class="max-w-6xl mx-auto px-6">
@templ.Raw(data.Slots["colophon"])
</div>
</footer>
@bn.BodyEnd(data.SiteSettings)
</body>
</html>
}
// RenderMagazineBold renders the default page.
func RenderMagazineBold(ctx context.Context, doc map[string]any) templ.Component {
return MagazineBold(parseMagazineBoldPageData(doc))
}
// RenderMagazineBoldLanding renders the issue-landing page.
func RenderMagazineBoldLanding(ctx context.Context, doc map[string]any) templ.Component {
return MagazineBoldLanding(parseMagazineBoldPageData(doc))
}
// RenderMagazineBoldArticle renders the long-form article page.
func RenderMagazineBoldArticle(ctx context.Context, doc map[string]any) templ.Component {
return MagazineBoldArticle(parseMagazineBoldPageData(doc))
}
// RenderMagazineBoldFullWidth renders the edge-to-edge photo-essay page.
func RenderMagazineBoldFullWidth(ctx context.Context, doc map[string]any) templ.Component {
return MagazineBoldFullWidth(parseMagazineBoldPageData(doc))
}