project

package
v1.2.0 Latest Latest
Warning

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

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

Documentation

Overview

Package project provides the ProjectManager API that bridges the desktop app and CLI to the site engine.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNoProjectOpen      = errors.New("no project open")
	ErrPreviewRunning     = errors.New("preview already running")
	ErrPreviewNotRunning  = errors.New("preview not running")
	ErrPreviewUnavailable = errors.New("preview not available (no preview factory configured)")
)

Sentinel errors for preview lifecycle, so API handlers can map failures to distinct error codes instead of guessing from free-text messages.

Functions

func ScaffoldFile

func ScaffoldFile(projectDir, collection, title, absPath string) error

ScaffoldFile creates a new content file at absPath with archetype/schema-aware frontmatter. It is exported for use by the CLI, which operates outside the ProjectManager.

Types

type CollectionInfo

type CollectionInfo struct {
	Name      string `json:"name"`
	Title     string `json:"title"`
	Layout    string `json:"layout"`
	PageCount int    `json:"pageCount"`
}

CollectionInfo provides metadata about a collection.

type ContentFile

type ContentFile struct {
	Path        string         `json:"path"`
	Title       string         `json:"title"`
	Collection  string         `json:"collection"`
	Frontmatter map[string]any `json:"frontmatter"`
	Body        string         `json:"body"`
	Draft       bool           `json:"draft"`
	Date        time.Time      `json:"date,omitempty"`
	WordCount   int            `json:"wordCount"`
	ReadingTime int            `json:"readingTime"`
}

ContentFile is the full representation of a content file for the API.

type ContentSummary

type ContentSummary struct {
	Path  string    `json:"path"`
	Title string    `json:"title"`
	Draft bool      `json:"draft"`
	Date  time.Time `json:"date,omitempty"`
	Order int       `json:"order"`
}

ContentSummary is a lightweight listing entry for content files.

type CreateOpts

type CreateOpts struct {
	Title string `json:"title"`
}

CreateOpts configures new project creation.

type Event

type Event struct {
	Type string `json:"event"`
	Data any    `json:"data,omitempty"`
}

Event is the generic event envelope sent over WebSocket.

type EventHub

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

EventHub manages WebSocket client connections and broadcasts events.

func NewEventHub

func NewEventHub() *EventHub

NewEventHub creates a new event hub.

func (*EventHub) Broadcast

func (h *EventHub) Broadcast(event Event)

Broadcast sends an event to all connected WebSocket clients.

func (*EventHub) ClientCount

func (h *EventHub) ClientCount() int

ClientCount returns the number of connected clients.

func (*EventHub) HandleWS

func (h *EventHub) HandleWS(w http.ResponseWriter, r *http.Request)

HandleWS upgrades an HTTP connection to WebSocket and registers the client.

type PluginInfo added in v1.0.0

type PluginInfo struct {
	Slug        string                    `json:"slug"`
	Name        string                    `json:"name"`
	Version     string                    `json:"version"`
	Description string                    `json:"description"`
	Author      string                    `json:"author"`
	Kind        string                    `json:"kind"` // always "external" for now
	Premium     bool                      `json:"premium"`
	LicenseOK   bool                      `json:"licenseOk"`
	LicenseMsg  string                    `json:"licenseMsg,omitempty"`
	Enabled     bool                      `json:"enabled"`
	PurchaseURL string                    `json:"purchaseUrl,omitempty"`
	Fields      []external.BlueprintField `json:"fields,omitempty"`
}

PluginInfo describes an installed external plugin for the desktop app. Fields carries blueprint metadata for a future plugin settings UI.

type PreviewFactory

type PreviewFactory func(projectDir, outputDir string, port int, liveReload bool, builderFactory func() *build.SiteBuilder) PreviewServer

PreviewFactory creates a PreviewServer. Set by the caller to break the import cycle.

type PreviewServer

type PreviewServer interface {
	Start() error
	Stop() error
	// Ready reports the actual bound port: sent once after the listener
	// binds, then the channel is closed. Closed without a value if the
	// server fails or is stopped before binding.
	Ready() <-chan int
}

PreviewServer is the interface for the dev server to avoid circular imports.

type ProjectInfo

type ProjectInfo struct {
	Dir         string           `json:"dir"`
	State       string           `json:"state"`
	Title       string           `json:"title"`
	Collections []CollectionInfo `json:"collections"`
}

ProjectInfo is the summary returned when opening or querying a project.

type ProjectManager

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

ProjectManager is the unified API for content CRUD, config management, and build lifecycle. It bridges the desktop app (Tauri) and CLI to the site engine.

func NewProjectManager

func NewProjectManager(hub *EventHub, efs fs.FS, pf PreviewFactory) *ProjectManager

NewProjectManager creates a new ProjectManager.

func (*ProjectManager) AddLanguage added in v1.0.0

func (pm *ProjectManager) AddLanguage(code string, cfg config.LanguageConfig) error

AddLanguage registers a new language in i18n.languages. The first time a second language is configured, default_language is set to the existing site language (or "en") if not already set.

func (*ProjectManager) Build

func (pm *ProjectManager) Build() (*engine.BuildResult, error)

Build runs a full site build and returns the result.

func (*ProjectManager) CloseProject

func (pm *ProjectManager) CloseProject() error

CloseProject closes the current project and stops any running preview.

func (*ProjectManager) ContentDir

func (pm *ProjectManager) ContentDir() string

ContentDir returns the absolute path to the content directory.

func (*ProjectManager) CreateContent

func (pm *ProjectManager) CreateContent(collection, title string) (*ContentFile, error)

CreateContent creates a new content file in the given collection.

func (*ProjectManager) CreateProject

func (pm *ProjectManager) CreateProject(dir string, opts CreateOpts) (*ProjectInfo, error)

CreateProject scaffolds a new project and opens it.

func (*ProjectManager) CreateVersion added in v1.0.0

func (pm *ProjectManager) CreateVersion(collection, versionID, label string) error

CreateVersion cuts a new version for a versioned collection. If a prior last_version already existed, the collection's current root content is copied (not moved) into content/<collection>/<oldLastVersion>/, freezing that version's content while root content continues to represent the new unreleased version. versionID is then registered as the new last_version.

func (*ProjectManager) DeleteContent

func (pm *ProjectManager) DeleteContent(relPath string) error

DeleteContent removes a content file.

func (*ProjectManager) DeleteVersion added in v1.0.0

func (pm *ProjectManager) DeleteVersion(collection, versionID string) error

DeleteVersion removes a version entry and its archived content directory. Rejects deleting the collection's current last_version.

func (*ProjectManager) DisablePlugin added in v1.0.0

func (pm *ProjectManager) DisablePlugin(slug string) error

DisablePlugin adds slug to plugins.disabled in sarde.yaml.

func (*ProjectManager) EnablePlugin added in v1.0.0

func (pm *ProjectManager) EnablePlugin(slug string) error

EnablePlugin removes slug from plugins.disabled in sarde.yaml.

func (*ProjectManager) GetCollections

func (pm *ProjectManager) GetCollections() ([]CollectionInfo, error)

GetCollections returns metadata about all collections.

func (*ProjectManager) GetConfig

func (pm *ProjectManager) GetConfig() *config.SiteConfig

GetConfig returns the current site configuration.

func (*ProjectManager) GetSchema

func (pm *ProjectManager) GetSchema(collection string) (*engine.FrontmatterSchema, error)

GetSchema returns the frontmatter schema for a collection, or nil if none exists.

func (*ProjectManager) InstallPlugin added in v1.0.0

func (pm *ProjectManager) InstallPlugin(source string) (*PluginInfo, error)

InstallPlugin installs an external plugin from source (zip path, URL, GitHub reference, or local directory) and returns its info.

func (*ProjectManager) ListContent

func (pm *ProjectManager) ListContent(collection string) ([]ContentSummary, error)

ListContent returns a list of content files in the given collection.

func (*ProjectManager) ListPlugins added in v1.0.0

func (pm *ProjectManager) ListPlugins() ([]PluginInfo, error)

ListPlugins returns all external plugins found in the project's plugins/ directory, including ones with unreadable manifests (surfaced via LicenseMsg so the UI can show the problem).

func (*ProjectManager) ListRevisions

func (pm *ProjectManager) ListRevisions(relPath string) ([]RevisionSummary, error)

ListRevisions returns the revision history for a content file, newest first.

func (*ProjectManager) OpenProject

func (pm *ProjectManager) OpenProject(dir string) (*ProjectInfo, error)

OpenProject loads an existing project from the given directory.

func (*ProjectManager) ProjectDir

func (pm *ProjectManager) ProjectDir() string

ProjectDir returns the root directory of the currently open project.

func (*ProjectManager) ReadContent

func (pm *ProjectManager) ReadContent(relPath string) (*ContentFile, error)

ReadContent reads a single content file.

func (*ProjectManager) RemoveLanguage added in v1.0.0

func (pm *ProjectManager) RemoveLanguage(code string, deleteContent bool) error

RemoveLanguage removes a language from i18n.languages. Rejects removing the default language. Optionally deletes its content/<code>/ directory.

func (*ProjectManager) RemovePlugin added in v1.0.0

func (pm *ProjectManager) RemovePlugin(slug string) error

RemovePlugin deletes plugins/{slug} from the project. License files are kept: they live outside the plugin directory.

func (*ProjectManager) RenameContent

func (pm *ProjectManager) RenameContent(oldPath, newPath string) error

RenameContent moves a content file to a new path.

func (*ProjectManager) RenderMarkdown

func (pm *ProjectManager) RenderMarkdown(md string) (*RenderResult, error)

RenderMarkdown converts markdown to HTML with heading extraction.

func (*ProjectManager) RestoreRevision

func (pm *ProjectManager) RestoreRevision(relPath, revisionID string) error

RestoreRevision overwrites the content file with the named revision's contents. The current version is snapshotted first so the restore is itself reversible.

func (*ProjectManager) SaveContent

func (pm *ProjectManager) SaveContent(relPath string, fm map[string]any, body string) error

SaveContent writes frontmatter and body to an existing content file.

func (*ProjectManager) ScaffoldLanguageContent added in v1.0.0

func (pm *ProjectManager) ScaffoldLanguageContent(code string) error

ScaffoldLanguageContent creates content/<code>/<collection>/ directories with _index.md stubs mirroring the default language's collections, and seeds i18n/<code>.yaml from the default language's translation file.

func (*ProjectManager) StartPreview

func (pm *ProjectManager) StartPreview(port int) (int, error)

StartPreview starts the dev server and returns the actual bound port.

func (*ProjectManager) State

func (pm *ProjectManager) State() ProjectState

State returns the current project state.

func (*ProjectManager) StopPreview

func (pm *ProjectManager) StopPreview() error

StopPreview stops the dev server.

func (*ProjectManager) TranslationStatus added in v1.0.0

func (pm *ProjectManager) TranslationStatus() (map[string]map[string]TranslationCoverage, error)

TranslationStatus returns, per collection and language, the total number of pages in the default language and how many exist in each language.

func (*ProjectManager) UpdateSettings

func (pm *ProjectManager) UpdateSettings(input SettingsInput) error

UpdateSettings applies partial config updates and re-resolves.

func (*ProjectManager) UpdateVersionEntry added in v1.0.0

func (pm *ProjectManager) UpdateVersionEntry(collection, versionID string, label, banner, redirect *string) error

UpdateVersionEntry updates the label, banner, or redirect of an existing version entry. Each pointer arg is applied only when non-nil, leaving the existing value untouched otherwise.

func (*ProjectManager) Validate

func (pm *ProjectManager) Validate() (*build.ValidateResult, error)

Validate runs phases 1-4 without rendering or writing.

type ProjectState

type ProjectState int

ProjectState represents the current state of the project manager.

const (
	StateClosed     ProjectState = iota
	StateOpen                    // project loaded, ready for operations
	StateBuilding                // build in progress
	StatePreviewing              // dev server running
)

func (ProjectState) String

func (s ProjectState) String() string

type RenderResult

type RenderResult struct {
	HTML        string           `json:"html"`
	Headings    []engine.Heading `json:"headings"`
	WordCount   int              `json:"wordCount"`
	ReadingTime int              `json:"readingTime"`
}

RenderResult holds the output of a markdown render operation.

type RevisionSummary

type RevisionSummary struct {
	ID        string    `json:"id"`
	Timestamp time.Time `json:"timestamp"`
	Size      int64     `json:"size"`
}

RevisionSummary describes one snapshot of a content file.

type SettingsInput

type SettingsInput struct {
	Title       *string `json:"title,omitempty"`
	URL         *string `json:"url,omitempty"`
	Language    *string `json:"language,omitempty"`
	Description *string `json:"description,omitempty"`
}

SettingsInput is a partial update to site configuration. Only non-nil fields are applied.

type TranslationCoverage added in v1.0.0

type TranslationCoverage struct {
	Total      int `json:"total"`
	Translated int `json:"translated"`
}

TranslationCoverage reports content coverage for one collection x language pair.

Jump to

Keyboard shortcuts

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