shared

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Aug 19, 2026 License: AGPL-3.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CONTROLLER_HOME                   = "home"
	CONTROLLER_POST_CREATE            = "post-create"
	CONTROLLER_POST_DELETE            = "post-delete"
	CONTROLLER_POST_MANAGER           = "post-manager"
	CONTROLLER_POST_UPDATE            = "post-update"
	CONTROLLER_POST_UPDATE_V1         = "post-update-v1"
	CONTROLLER_BLOG_SETTINGS          = "blog-settings"
	CONTROLLER_AI_TOOLS               = "ai-tools"
	CONTROLLER_AI_POST_CONTENT_UPDATE = "ai-post-content-update"
	CONTROLLER_AI_POST_GENERATOR      = "ai-post-generator"
	CONTROLLER_AI_TITLE_GENERATOR     = "ai-title-generator"
	CONTROLLER_AI_POST_EDITOR         = "ai-post-editor"
	CONTROLLER_AI_TEST                = "ai-test"
	CONTROLLER_DASHBOARD              = "dashboard"
	CONTROLLER_CATEGORY_MANAGER       = "category-manager"
	CONTROLLER_TAG_MANAGER            = "tag-manager"
)

Controller names used in the ?controller= query parameter

View Source
const CatchAll = "/*"

CatchAll is the catch-all route suffix

View Source
const ERROR_LOGGER_IS_NIL = "logger cannot be nil"
View Source
const ERROR_STORE_IS_NIL = "store cannot be nil"

Error messages

View Source
const KeyAdminHomeURL = "admin_home_url"
View Source
const KeyBlogAdminURL = "blog_admin_url"
View Source
const KeyEndpoint = "endpoint"

Context keys for config values injected by Handle()

View Source
const KeyFileManagerURL = "file_manager_url"

Variables

This section is empty.

Functions

func AdminHomeURL

func AdminHomeURL(r *http.Request) string

AdminHomeURL returns the admin home URL from request context

func BlogAdminURL

func BlogAdminURL(r *http.Request) string

BlogAdminURL returns the blog admin base URL from request context

func Breadcrumbs(breadcrumbs []Breadcrumb) hb.TagInterface

Breadcrumbs renders a breadcrumb navigation from the given items

func Endpoint

func Endpoint(r *http.Request) string

Endpoint returns the request endpoint URL from context

func ErrorAlert

func ErrorAlert(message string) string

ErrorAlert returns an inline HTML error alert for the given message. This replaces the former ToFlashError flash-message pattern, which required a cache store and a /flash route handler that did not exist in the standalone module.

func ErrorPopup

func ErrorPopup(errorMessage string) hb.TagInterface

ErrorPopup returns a SweetAlert2 error popup tag.

func FileManagerURL

func FileManagerURL(r *http.Request) string

FileManagerURL returns the file manager URL from request context

func Header(store blogstore.StoreInterface, logger *slog.Logger, r *http.Request) hb.TagInterface

Header renders the blog admin navigation header. It is nil-safe for both store and logger.

func Layout

func Layout(w http.ResponseWriter, r *http.Request, webpageTitle, webpageHtml string, options struct {
	Styles     []string
	StyleURLs  []string
	Scripts    []string
	ScriptURLs []string
}) string

Layout is the default layout renderer. It builds a complete HTML page using hb.NewWebpage() with Bootstrap + Vue CDN, matching the shopadmin pattern. If a FuncLayout is provided in AdminOptions, it takes precedence over this default.

func PostImageURL

func PostImageURL(ctx context.Context, store blogstore.StoreInterface, post blogstore.PostInterface) string

PostImageURL resolves the image URL for a post. It returns the first media URL (sorted by sequence) if media exists, using the /blog/media/<id>.<ext> route. Otherwise falls back to the post's ImageUrl field.

This replaces the former project/internal/rules.PostImageURL helper, keeping blogadmin decoupled from the host project.

func SuccessPopup

func SuccessPopup(successMessage string) hb.TagInterface

SuccessPopup returns a SweetAlert2 success popup tag.

func SuccessPopupWithRedirect

func SuccessPopupWithRedirect(successMessage string, redirectUrl string, redirectSeconds int) hb.TagInterface

SuccessPopupWithRedirect returns a SweetAlert2 success popup with an optional redirect. If redirectUrl is empty, no redirect is configured.

func URL

func URL(endpoint string, controller string, params map[string]string) string

URL builds a URL for the given endpoint and controller with params. The controller is placed in the params map under the "controller" key. The params map is copied before mutation (does not modify caller's map).

func URLR

func URLR(r *http.Request, controller string, params map[string]string) string

URLR builds a URL using the endpoint from the request context.

Types

type Breadcrumb struct {
	Name string
	URL  string
}

Breadcrumb represents a single breadcrumb navigation item

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

Links provides URL helpers for blogadmin controllers. The base URL is read from request context (injected by Handle()), not hardcoded. This follows the shopadmin pattern.

func NewLinks(baseURL string) *Links

NewLinks creates a Links helper with the given base URL. If baseURL is empty, defaults to "/admin/blog".

func NewLinksFromRequest

func NewLinksFromRequest(r *http.Request) *Links

NewLinksFromRequest creates a Links helper using the blog admin URL from the request context.

func (*Links) AiPostContentUpdate

func (l *Links) AiPostContentUpdate(params map[string]string) string

AiPostContentUpdate builds the URL for the AI post content update controller

func (*Links) AiPostEditor

func (l *Links) AiPostEditor(params map[string]string) string

AiPostEditor builds the URL for the AI post editor controller

func (*Links) AiPostGenerator

func (l *Links) AiPostGenerator(params map[string]string) string

AiPostGenerator builds the URL for the AI post generator controller

func (*Links) AiTest

func (l *Links) AiTest(params map[string]string) string

AiTest builds the URL for the AI test controller

func (*Links) AiTitleGenerator

func (l *Links) AiTitleGenerator(params map[string]string) string

AiTitleGenerator builds the URL for the AI title generator controller

func (*Links) AiTools

func (l *Links) AiTools(params map[string]string) string

AiTools builds the URL for the AI tools controller

func (*Links) BlogSettings

func (l *Links) BlogSettings(params map[string]string) string

BlogSettings builds the URL for the blog settings controller

func (*Links) CategoryManager

func (l *Links) CategoryManager(params map[string]string) string

CategoryManager builds the URL for the category manager controller

func (*Links) Dashboard

func (l *Links) Dashboard(params map[string]string) string

Dashboard builds the URL for the dashboard controller

func (*Links) Home

func (l *Links) Home(params map[string]string) string

Home builds the URL for the home/post-manager controller

func (*Links) PostCreate

func (l *Links) PostCreate(params map[string]string) string

PostCreate builds the URL for the post create controller

func (*Links) PostDelete

func (l *Links) PostDelete(params map[string]string) string

PostDelete builds the URL for the post delete controller

func (*Links) PostManager

func (l *Links) PostManager(params map[string]string) string

PostManager builds the URL for the post manager controller

func (*Links) PostUpdate

func (l *Links) PostUpdate(params map[string]string) string

PostUpdate builds the URL for the post update controller

func (*Links) PostUpdateV1

func (l *Links) PostUpdateV1(params map[string]string) string

PostUpdateV1 builds the URL for the post update v1 controller

func (*Links) TagManager

func (l *Links) TagManager(params map[string]string) string

TagManager builds the URL for the tag manager controller

type LlmFactoryFunc

type LlmFactoryFunc func() (llm.LlmInterface, error)

LlmFactoryFunc creates an LLM engine instance. The host project provides this so blogadmin does not depend on any specific config/auth package. Called by the AI controllers (ai_tools, ai_test, ai_post_generator, ai_title_generator, ai_post_editor, ai_post_content_update, and the regenerate-image flow in post_update).

If nil, AI controllers return an error to the user instead of panicking.

type UiBase

type UiBase struct {
	StoreField        blogstore.StoreInterface
	LoggerField       *slog.Logger
	CustomStoreField  customstore.StoreInterface
	SettingStoreField settingstore.StoreInterface
	LlmFactoryField   LlmFactoryFunc
	LayoutField       func(w http.ResponseWriter, r *http.Request, webpageTitle, webpageHtml string, options struct {
		Styles     []string
		StyleURLs  []string
		Scripts    []string
		ScriptURLs []string
	}) string
}

UiBase is a base struct that implements shared.UiInterface. Subcontroller ui structs can embed this to get the Store(), Logger(), CustomStore(), SettingStore(), LlmFactory(), and Layout() methods for free, following the shopadmin pattern.

func NewUiBase

func NewUiBase(config UiConfig) UiBase

NewUiBase creates a UiBase from a UiConfig

func (UiBase) CustomStore

func (u UiBase) CustomStore() customstore.StoreInterface

func (UiBase) Layout

func (u UiBase) Layout(w http.ResponseWriter, r *http.Request, webpageTitle, webpageHtml string, options struct {
	Styles     []string
	StyleURLs  []string
	Scripts    []string
	ScriptURLs []string
}) string

func (UiBase) LlmEngine

func (u UiBase) LlmEngine() (llm.LlmInterface, error)

func (UiBase) LlmFactory

func (u UiBase) LlmFactory() LlmFactoryFunc

func (UiBase) Logger

func (u UiBase) Logger() *slog.Logger

func (UiBase) SettingStore

func (u UiBase) SettingStore() settingstore.StoreInterface

func (UiBase) Store

func (u UiBase) Store() blogstore.StoreInterface

type UiConfig

type UiConfig struct {
	Store        blogstore.StoreInterface
	Logger       *slog.Logger
	CustomStore  customstore.StoreInterface
	SettingStore settingstore.StoreInterface
	LlmFactory   LlmFactoryFunc
	Layout       func(w http.ResponseWriter, r *http.Request, webpageTitle, webpageHtml string, options struct {
		Styles     []string
		StyleURLs  []string
		Scripts    []string
		ScriptURLs []string
	}) string
}

UiConfig holds the dependencies passed to subcontroller UI factories. The Layout function uses an anonymous struct for options to match cmsstore/admin and shopadmin exactly, allowing consumers to reuse their existing layout function for blogadmin.

AI controllers require CustomStore, SettingStore, and LlmFactory. Core controllers only need Store and Logger. Nil AI dependencies are safe — AI controllers return an error to the user instead of panicking.

type UiInterface

type UiInterface interface {
	Store() blogstore.StoreInterface
	Logger() *slog.Logger
	CustomStore() customstore.StoreInterface
	SettingStore() settingstore.StoreInterface
	LlmEngine() (llm.LlmInterface, error)

	Layout(w http.ResponseWriter, r *http.Request, webpageTitle, webpageHtml string, options struct {
		Styles     []string
		StyleURLs  []string
		Scripts    []string
		ScriptURLs []string
	}) string
}

UiInterface defines the methods every subcontroller UI must implement. This follows the shopadmin pattern.

AI controllers additionally use CustomStore(), SettingStore(), and LlmEngine(); core controllers only use Store(), Logger(), and Layout().

Jump to

Keyboard shortcuts

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