Bootstrapped during the 2026-06-06 BlockNinja consolidation. Was previously an unversioned directory inside ~/src/blockninja-themes/editorial. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
57 lines
1.5 KiB
Go
57 lines
1.5 KiB
Go
package main
|
|
|
|
import (
|
|
"bytes"
|
|
"context"
|
|
|
|
"git.dev.alexdunmow.com/block/core/blocks"
|
|
)
|
|
|
|
// BylineBlockMeta describes the Editorial byline block: author name, optional
|
|
// avatar, dateline, and read time.
|
|
// Registered as "editorial:byline" at runtime.
|
|
var BylineBlockMeta = blocks.BlockMeta{
|
|
Key: "byline",
|
|
Title: "Byline",
|
|
Description: "Author byline with optional photo, dateline, and read time",
|
|
Source: "editorial",
|
|
Category: blocks.CategoryTheme,
|
|
}
|
|
|
|
// BylineData carries parsed byline content.
|
|
//
|
|
// Author resolution: this plugin does not resolve the slug to an actual author
|
|
// record (that would require ServiceDeps and a database call). Instead the
|
|
// authorSlug is rendered verbatim in the byline label. The CMS layer can
|
|
// replace the slug with the resolved name when integrating with the author
|
|
// directory.
|
|
type BylineData struct {
|
|
AuthorSlug string
|
|
ShowPhoto bool
|
|
ShowReadTime bool
|
|
Dateline string
|
|
}
|
|
|
|
// BylineBlock renders the article byline.
|
|
//
|
|
// Content shape:
|
|
//
|
|
// {
|
|
// "authorSlug": "jane-smith",
|
|
// "showPhoto": "true",
|
|
// "showReadTime": "true",
|
|
// "dateline": "London, March 14"
|
|
// }
|
|
func BylineBlock(ctx context.Context, content map[string]any) string {
|
|
data := BylineData{
|
|
AuthorSlug: getString(content, "authorSlug"),
|
|
ShowPhoto: getBool(content, "showPhoto", true),
|
|
ShowReadTime: getBool(content, "showReadTime", true),
|
|
Dateline: getString(content, "dateline"),
|
|
}
|
|
|
|
var buf bytes.Buffer
|
|
_ = bylineComponent(data).Render(ctx, &buf)
|
|
return buf.String()
|
|
}
|