preview

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: May 28, 2026 License: MIT Imports: 23 Imported by: 0

Documentation

Overview

Package preview runs the live-preview HTTP server: serves the SPA, an iframe-hosted paged.js view of the document, pushes a reload signal over WebSocket on file changes, and exposes /print to trigger PDF generation.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Server

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

Server is a single-client live-preview server bound to one source document.

func New

func New(docPath, version string) *Server

New returns a server for the given document. The document is re-read from disk on every render so edits in any external editor are picked up.

func (*Server) CurrentThemePath

func (s *Server) CurrentThemePath() (string, error)

CurrentThemePath returns the resolved theme path of the current document. Used by callers to wire up a file watcher on it.

func (*Server) DocPath

func (s *Server) DocPath() string

DocPath is the absolute path of the document this server is serving.

func (*Server) Port

func (s *Server) Port() int

Port returns the port the server is listening on. Only valid after Start.

func (*Server) PushReload

func (s *Server) PushReload() error

PushReload notifies the connected client that the underlying document or theme changed and the iframe should be reloaded.

func (*Server) Shutdown

func (s *Server) Shutdown() error

Shutdown stops the HTTP server.

func (*Server) Start

func (s *Server) Start(port int) error

Start binds the server (port 0 = auto-pick) and serves in the background.

func (*Server) URL

func (s *Server) URL() string

URL returns the preview origin (no path).

type Watcher

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

Watcher watches a set of files and invokes onChange (debounced) when any of them is written.

func NewWatcher

func NewWatcher(onChange func(), paths ...string) (*Watcher, error)

NewWatcher creates a watcher and adds each given path. Missing paths are skipped with a warning rather than treated as fatal — themes may be inlined into the document, in which case there's nothing to watch.

func (*Watcher) Close

func (w *Watcher) Close() error

Close stops the watcher.

func (*Watcher) Run

func (w *Watcher) Run()

Run blocks until Close is called. A 100ms debounce coalesces editor save bursts (some editors emit several writes in quick succession).

Jump to

Keyboard shortcuts

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