project

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Jun 27, 2026 License: MIT Imports: 25 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

This section is empty.

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 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) 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) DeleteContent

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

DeleteContent removes a content file.

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) ListContent

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

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

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) 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) 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) UpdateSettings

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

UpdateSettings applies partial config updates and re-resolves.

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.

Jump to

Keyboard shortcuts

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