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 ¶
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) CurrentTheme ¶ added in v0.1.1
CurrentTheme re-resolves the current document's theme and reports what the watcher and live logger need: the resolved theme file path ("" for a built-in, so the file watch is dropped), the current non-fatal theme warning ("" when the theme is fine), and docErr — set when the document itself can't be read or parsed (which is fatal for rendering, unlike a theme problem).
func (*Server) PushReload ¶
PushReload notifies the connected client that the underlying document or theme changed and the iframe should be reloaded.
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. onChange receives the path of the file whose change triggered the (debounced) fire, so callers can log what reloaded.
func NewWatcher ¶
NewWatcher creates a watcher and adds each given path. A path that doesn't exist (e.g. a themes/ directory the project never created) is skipped silently — it's a normal, expected case, not an error. Other Add failures are logged but non-fatal.
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).
func (*Watcher) WatchTheme ¶ added in v0.1.1
WatchTheme follows the document's active theme file for content edits. The active theme can change mid-session (the user edits the frontmatter, or fixes a previously-missing theme), so this is called on every reload to keep the watch pointed at the right file. Passing "" — which is what the built-in default theme resolves to — just drops the previous theme watch.
Theme directories are watched separately and statically (see NewWatcher) so that creating or switching theme files is noticed even on platforms where a directory watch doesn't report writes to existing files.