theme

package
v0.1.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 15, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package theme 负责加载与渲染主题. 主题目录结构: theme.json, layouts/, assets/. 优先加载 Space 中的 themes/<name>, 缺失时回退到内嵌默认主题.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CopyTo

func CopyTo(dst string) error

CopyTo 将内嵌主题复制到目标目录. 用于 plainship new 生成 themes/default.

Types

type Theme

type Theme struct {
	Name     string
	Version  string
	Layouts  map[string]*template.Template
	Assets   map[string][]byte // 相对路径 -> 内容
	HasOwnFS bool              // 是否来自 Space 目录
}

Theme 表示一个已加载的主题.

func Load

func Load(spaceRoot, name string, lang i18n.Lang, baseURL string) (*Theme, error)

Load 从 Space 的 themes/<name> 目录加载主题. 如果目录不存在, 回退到内嵌默认主题. lang 决定模板函数 (t / formatDate) 的语言, baseURL 决定链接基础路径 (url 函数).

func LoadEmbedded

func LoadEmbedded(lang i18n.Lang, baseURL string) (*Theme, error)

LoadEmbedded 加载内嵌的默认主题. 内嵌主题版本跟随产品版本 (由 internal/version 提供), 用于构建指纹.

func (*Theme) HasLayout

func (t *Theme) HasLayout(layout string) bool

HasLayout 判断主题是否提供指定布局.

func (*Theme) Render

func (t *Theme) Render(layout string, data any) (string, error)

Render 使用指定布局渲染页面.

func (*Theme) WriteAssets

func (t *Theme) WriteAssets(dst string) (int, error)

WriteAssets 将主题资源写入目标目录.

Directories

Path Synopsis
Package embed 使用 go:embed 内嵌默认主题, 保证即使 themes 目录缺失也能构建.
Package embed 使用 go:embed 内嵌默认主题, 保证即使 themes 目录缺失也能构建.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL