Bootstrapped during the 2026-06-06 BlockNinja consolidation. Was previously an unversioned directory inside ~/src/blockninja-themes/scifi-clean. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
55 lines
1.4 KiB
Go
55 lines
1.4 KiB
Go
package main
|
|
|
|
import (
|
|
"bytes"
|
|
"context"
|
|
|
|
"git.dev.alexdunmow.com/block/core/blocks"
|
|
)
|
|
|
|
// MissionStatBlockMeta defines metadata for the mission-stat block.
|
|
var MissionStatBlockMeta = blocks.BlockMeta{
|
|
Key: "mission_stat",
|
|
Title: "Mission Stat",
|
|
Description: "Headline metric in mono numerals with a signal-orange delta arrow.",
|
|
Source: "scifi-clean",
|
|
Category: blocks.CategoryContent,
|
|
}
|
|
|
|
// MissionStatData drives the templ render.
|
|
type MissionStatData struct {
|
|
Metric string
|
|
Value string
|
|
Unit string
|
|
Delta string
|
|
Trend string // "up", "down", "flat"
|
|
}
|
|
|
|
// MissionStatBlock renders the mission-stat block.
|
|
// Content shape: {"metric": "...", "value": "...", "unit": "...", "delta": "...", "trend": "up|down|flat"}
|
|
func MissionStatBlock(ctx context.Context, content map[string]any) string {
|
|
data := MissionStatData{
|
|
Metric: getString(content, "metric"),
|
|
Value: getString(content, "value"),
|
|
Unit: getString(content, "unit"),
|
|
Delta: getString(content, "delta"),
|
|
Trend: normalizeTrend(getString(content, "trend")),
|
|
}
|
|
|
|
var buf bytes.Buffer
|
|
_ = missionStatComponent(data).Render(ctx, &buf)
|
|
return buf.String()
|
|
}
|
|
|
|
// trendGlyph returns the arrow character for a given trend.
|
|
func trendGlyph(trend string) string {
|
|
switch trend {
|
|
case "up":
|
|
return "↑" // ↑
|
|
case "down":
|
|
return "↓" // ↓
|
|
default:
|
|
return "→" // →
|
|
}
|
|
}
|