cmd

package
v0.6.8 Latest Latest
Warning

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

Go to latest
Published: Mar 28, 2026 License: MIT Imports: 53 Imported by: 0

Documentation

Overview

build.go implements the core mdpress build command. It loads config, resolves sources, and dispatches document generation. Both local directories and GitHub repositories are supported, including zero-config discovery mode.

completion.go implements the shell completion command for mdpress. It generates shell completion scripts for bash, zsh, fish, and powershell.

init_cmd.go implements the init subcommand. It scans Markdown files, extracts structure and titles, and generates book.yaml. When the target directory is empty it creates starter files. Interactive mode collects project metadata, with sensible defaults for non-interactive terminals.

migrate.go implements the `mdpress migrate` command.

It detects a GitBook / HonKit project in the given directory, converts book.json to book.yaml, rewrites GitBook-specific template tags in Markdown files, and prints a migration report.

quickstart.go implements the quickstart subcommand. It creates a complete sample book project so users can see results quickly. The command generates book.yaml, README.md, sample chapters, image placeholders, and next-step instructions.

serve.go implements the local live preview server. It watches files, rebuilds HTML on change, and pushes reload events over WebSocket.

upgrade.go implements the upgrade subcommand. It checks for newer versions of mdpress from GitHub releases and optionally installs them.

validate.go implements the validate subcommand. It checks the book config, referenced files, and image paths, then prints a readable validation report.

Index

Constants

This section is empty.

Variables

View Source
var (
	// Version is overridden at build time via -ldflags.
	Version = "0.6.8"
	// BuildTime is overridden at build time via -ldflags.
	BuildTime = "unknown"
)

Functions

func ComputeCSSHash added in v0.4.0

func ComputeCSSHash(content string) string

ComputeCSSHash computes the SHA-256 hash of CSS content.

func ComputeChapterHash added in v0.4.0

func ComputeChapterHash(filePath string) (string, error)

ComputeChapterHash computes the SHA-256 hash of a chapter file.

func ComputeConfigHash added in v0.4.0

func ComputeConfigHash(filePath string) (string, error)

ComputeConfigHash computes the SHA-256 hash of the config file.

func Execute

func Execute() error

Execute runs the root command.

func SaveManifest added in v0.4.0

func SaveManifest(cacheDir string, manifest *BuildManifest) error

SaveManifest writes the manifest to disk atomically.

Types

type BuildContext

type BuildContext struct {
	Config             *config.BookConfig
	Theme              *theme.Theme
	SinglePageParts    *renderer.RenderParts
	PDFSinglePageParts *renderer.RenderParts
	ChaptersHTML       []renderer.ChapterHTML
	ChapterFiles       []string
	ChapterMarkdown    []string
	CustomCSS          string
	Logger             *slog.Logger
}

BuildContext carries all data needed by format builders.

type BuildManifest added in v0.4.0

type BuildManifest struct {
	Version  string                   `json:"version"`
	AppVer   string                   `json:"app_version"`
	ConfigSH string                   `json:"config_sha256"`
	CSSHash  string                   `json:"css_hash"`
	Chapters map[string]manifestEntry `json:"chapters"`
}

BuildManifest stores chapter compilation state for incremental builds.

func LoadManifest added in v0.4.0

func LoadManifest(cacheDir string) (*BuildManifest, error)

LoadManifest loads the build manifest from the cache directory. Returns an empty manifest if the file doesn't exist.

func NewBuildManifest added in v0.4.0

func NewBuildManifest(appVer string) *BuildManifest

NewBuildManifest creates a fresh manifest with the current app version.

func (*BuildManifest) GetEntry added in v0.4.0

func (m *BuildManifest) GetEntry(chapterPath string) (manifestEntry, bool)

GetEntry retrieves a manifest entry for a chapter.

func (*BuildManifest) IsStale added in v0.4.0

func (m *BuildManifest) IsStale(currentAppVer, currentConfigHash, currentCSSHash string) bool

IsStale checks if the manifest should be invalidated due to: - Version change - Config file change - CSS/theme change

func (*BuildManifest) UpdateEntry added in v0.4.0

func (m *BuildManifest) UpdateEntry(chapterPath, hash, htmlPath string, headingTexts []string, modTime time.Time)

UpdateEntry updates a manifest entry for a chapter.

type BuildOrchestrator

type BuildOrchestrator struct {
	Config *config.BookConfig
	Theme  *theme.Theme
	Parser *markdown.Parser
	Gloss  *glossary.Glossary
	Logger *slog.Logger
	// PluginManager manages loaded plugins and dispatches hook calls throughout the
	// build pipeline.  It is an empty (no-op) Manager when no plugins are configured.
	PluginManager *plugin.Manager
}

BuildOrchestrator encapsulates the shared build initialization workflow used by both `build` and `serve` commands.

func NewBuildOrchestrator

func NewBuildOrchestrator(cfg *config.BookConfig, logger *slog.Logger) (*BuildOrchestrator, error)

NewBuildOrchestrator creates a fully initialized orchestrator from config. It loads the theme (with fallback), creates the parser, and loads the glossary.

func (*BuildOrchestrator) LoadCustomCSS

func (o *BuildOrchestrator) LoadCustomCSS() string

LoadCustomCSS loads user-provided CSS.

func (*BuildOrchestrator) ProcessChapters

func (o *BuildOrchestrator) ProcessChapters(ctxOpts ...context.Context) (*ChapterPipelineResult, error)

ProcessChapters runs the ChapterPipeline and returns results.

func (*BuildOrchestrator) ProcessChaptersWithOptions added in v0.3.1

func (o *BuildOrchestrator) ProcessChaptersWithOptions(ctx context.Context, options ChapterPipelineOptions) (*ChapterPipelineResult, error)

ProcessChaptersWithOptions runs the ChapterPipeline with caller-provided options.

type ChapterPipeline

type ChapterPipeline struct {
	Config   *config.BookConfig
	Theme    *theme.Theme
	Parser   *markdown.Parser
	Glossary *glossary.Glossary
	Logger   *slog.Logger
	// PluginManager is invoked at the AfterParse hook, allowing plugins to
	// transform the HTML of each chapter after Markdown parsing.
	PluginManager *plugin.Manager
}

ChapterPipeline orchestrates the complete chapter processing workflow.

func NewChapterPipeline

func NewChapterPipeline(cfg *config.BookConfig, thm *theme.Theme, parser *markdown.Parser, gloss *glossary.Glossary, logger *slog.Logger, mgr *plugin.Manager) *ChapterPipeline

NewChapterPipeline creates a new chapter pipeline with the given configuration.

func (*ChapterPipeline) Process

Process executes the complete chapter processing pipeline. It returns processed chapters, chapter file paths, validation issues, and any error encountered. Always uses ParseWithDiagnostics regardless of caller preference.

func (*ChapterPipeline) ProcessWithOptions added in v0.3.1

func (p *ChapterPipeline) ProcessWithOptions(ctx context.Context, options ChapterPipelineOptions) (*ChapterPipelineResult, error)

ProcessWithOptions executes the complete chapter processing pipeline with caller-controlled image processing behavior.

type ChapterPipelineOptions added in v0.3.1

type ChapterPipelineOptions struct {
	ImageOptions *utils.ImageProcessingOptions
	// MaxConcurrency controls how many chapters are parsed in parallel.
	// If 0, defaults to runtime.NumCPU() (capped at 8).
	// If negative, sequential processing (concurrency = 1).
	MaxConcurrency int
}

ChapterPipelineOptions controls expensive per-chapter processing behavior.

type ChapterPipelineResult

type ChapterPipelineResult struct {
	Chapters        []renderer.ChapterHTML
	ChapterFiles    []string
	ChapterMarkdown []string
	Issues          []projectIssue
	AllHeadings     []toc.HeadingInfo
	Resolver        *crossref.Resolver
	HeadingRecords  []chapterHeadingRecord
}

ChapterPipelineResult encapsulates the output of chapter processing.

type EpubBuilder

type EpubBuilder struct{}

EpubBuilder generates an EPUB 3 ebook.

func (*EpubBuilder) Build

func (b *EpubBuilder) Build(ctx *BuildContext, baseName string) error

func (*EpubBuilder) Name

func (b *EpubBuilder) Name() string

type FormatBuilder

type FormatBuilder interface {
	// Name returns the format name (e.g. "pdf", "html", "site", "epub").
	Name() string
	// Build generates the output file(s) at the given base path.
	Build(ctx *BuildContext, baseName string) error
}

FormatBuilder generates output in a specific format.

type FormatBuilderRegistry

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

FormatBuilderRegistry manages registered format builders.

func NewFormatBuilderRegistry

func NewFormatBuilderRegistry() *FormatBuilderRegistry

NewFormatBuilderRegistry creates a registry pre-populated with all built-in formats.

func (*FormatBuilderRegistry) Get

Get returns a builder by format name, or nil if not found.

func (*FormatBuilderRegistry) Register

func (r *FormatBuilderRegistry) Register(b FormatBuilder)

Register adds a format builder.

type HTMLBuilder

type HTMLBuilder struct{}

HTMLBuilder generates a self-contained single-page HTML document.

func (*HTMLBuilder) Build

func (b *HTMLBuilder) Build(ctx *BuildContext, baseName string) error

func (*HTMLBuilder) Name

func (b *HTMLBuilder) Name() string

type PDFBuilder

type PDFBuilder struct{}

PDFBuilder generates PDF output via Chromium.

func (*PDFBuilder) Build

func (b *PDFBuilder) Build(ctx *BuildContext, baseName string) error

func (*PDFBuilder) Name

func (b *PDFBuilder) Name() string

type SiteBuilder

type SiteBuilder struct{}

SiteBuilder generates a multi-page HTML site.

func (*SiteBuilder) Build

func (b *SiteBuilder) Build(ctx *BuildContext, baseName string) error

func (*SiteBuilder) Name

func (b *SiteBuilder) Name() string

type Theme

type Theme struct {
	Name        string
	DisplayName string
	Description string
	Author      string
	Version     string
	License     string
	Features    []string
	Colors      themeColors
}

Theme describes a built-in theme.

type TypstBuilder added in v0.4.0

type TypstBuilder struct{}

TypstBuilder generates PDF output via Typst (proof-of-concept).

func (*TypstBuilder) Build added in v0.4.0

func (b *TypstBuilder) Build(ctx *BuildContext, baseName string) error

func (*TypstBuilder) Name added in v0.4.0

func (b *TypstBuilder) Name() string

Jump to

Keyboard shortcuts

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