frontend

package
v1.14.0 Latest Latest
Warning

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

Go to latest
Published: Mar 26, 2026 License: AGPL-3.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BlockRenderer added in v1.14.0

type BlockRenderer interface {
	// Render renders the block content and returns the HTML
	Render(ctx context.Context, block cmsstore.BlockInterface) (string, error)
}

BlockRenderer interface defines how different block types are rendered.

Custom block renderers must implement this interface to integrate with the block rendering system. Each renderer is responsible for converting a block's content into HTML output.

Example implementation:

type GalleryRenderer struct {
    store FrontendStore
}

func (r *GalleryRenderer) Render(ctx context.Context, block cmsstore.BlockInterface) (string, error) {
    // Parse block content and metadata
    images := parseGalleryImages(block.Content())
    layout := block.Meta("layout")

    // Generate HTML
    return renderGalleryHTML(images, layout), nil
}

To register a custom renderer:

frontend := cmsstore.NewFrontend(...)
frontend.BlockRegistry().Register("gallery", &GalleryRenderer{store: frontend})

See frontend/blocks/README.md for detailed examples and best practices.

type BlockRendererRegistry added in v1.14.0

type BlockRendererRegistry struct {
	// contains filtered or unexported fields
}

BlockRendererRegistry manages all registered block renderers.

The registry is thread-safe and can be accessed concurrently. It maps block types (strings) to their corresponding BlockRenderer implementations.

Built-in block types:

  • cmsstore.BLOCK_TYPE_HTML: Renders raw HTML content
  • cmsstore.BLOCK_TYPE_MENU: Renders navigation menus

Custom block types can be registered after frontend initialization:

frontend.BlockRegistry().Register("custom_type", customRenderer)

func NewBlockRendererRegistry added in v1.14.0

func NewBlockRendererRegistry() *BlockRendererRegistry

NewBlockRendererRegistry creates a new registry for block renderers. This is typically called internally during frontend initialization.

func (*BlockRendererRegistry) GetRenderer added in v1.14.0

func (r *BlockRendererRegistry) GetRenderer(blockType string) BlockRenderer

GetRenderer returns the renderer for the given block type

func (*BlockRendererRegistry) Register added in v1.14.0

func (r *BlockRendererRegistry) Register(blockType string, renderer BlockRenderer)

Register registers a renderer for a specific block type.

The blockType should match the value stored in the block's Type() field. If a renderer already exists for the given type, it will be replaced.

This method is thread-safe and can be called after frontend initialization to add custom block types.

Example:

frontend.BlockRegistry().Register("video", &VideoRenderer{})
frontend.BlockRegistry().Register("carousel", &CarouselRenderer{store: frontend})

func (*BlockRendererRegistry) RenderBlock added in v1.14.0

RenderBlock renders a block using the appropriate renderer.

Lookup priority:

  1. Global BlockType registry (cmsstore.GetBlockType)
  2. Local BlockRenderer registry (this registry)
  3. Fallback to NoOpRenderer

type Config

type Config struct {
	BlockEditorRenderer func(blocks []ui.BlockInterface) string
	Logger              *slog.Logger
	Shortcodes          []cmsstore.ShortcodeInterface
	Store               cmsstore.StoreInterface
	CacheEnabled        bool
	CacheExpireSeconds  int
}

type FrontendInterface

type FrontendInterface interface {
	// Handler renders the frontend
	Handler(w http.ResponseWriter, r *http.Request)

	// StringHandler return the frontend as a HTML string
	StringHandler(w http.ResponseWriter, r *http.Request) string

	// TemplateRenderHtmlByID builds the HTML of a template based on its ID
	TemplateRenderHtmlByID(r *http.Request, templateID string, options TemplateRenderHtmlByIDOptions) (string, error)
}

func New

func New(config Config) FrontendInterface

type LanguageKey

type LanguageKey struct{}

type NoOpRenderer added in v1.14.0

type NoOpRenderer struct{}

NoOpRenderer is a fallback renderer that returns empty content

func (*NoOpRenderer) Render added in v1.14.0

func (r *NoOpRenderer) Render(ctx context.Context, block cmsstore.BlockInterface) (string, error)

Render implements BlockRenderer interface

type TemplateRenderHtmlByIDOptions

type TemplateRenderHtmlByIDOptions struct {
	PageContent         string
	PageCanonicalURL    string
	PageMetaDescription string
	PageMetaKeywords    string
	PageMetaRobots      string
	PageTitle           string
	Language            string
}

Directories

Path Synopsis
blocks

Jump to

Keyboard shortcuts

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