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.
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.
validate.go implements the validate subcommand. It checks the book config, referenced files, and image paths, then prints a readable validation report.
Index ¶
- Variables
- func ComputeCSSHash(content string) string
- func ComputeChapterHash(filePath string) (string, error)
- func ComputeConfigHash(filePath string) (string, error)
- func Execute() error
- func SaveManifest(cacheDir string, manifest *BuildManifest) error
- type BuildContext
- type BuildManifest
- type BuildOrchestrator
- type CacheStatistics
- type ChapterPipeline
- type ChapterPipelineOptions
- type ChapterPipelineResult
- type EpubBuilder
- type FormatBuilder
- type FormatBuilderRegistry
- type HTMLBuilder
- type ManifestEntry
- type PDFBuilder
- type ServeOptions
- type SiteBuilder
- type Theme
- type ThemeColors
- type TypstBuilder
Constants ¶
This section is empty.
Variables ¶
var ( // Version is overridden at build time via -ldflags. Version = "0.4.2" // BuildTime is overridden at build time via -ldflags. BuildTime = "unknown" )
Functions ¶
func ComputeCSSHash ¶ added in v0.4.0
ComputeCSSHash computes the SHA-256 hash of CSS content.
func ComputeChapterHash ¶ added in v0.4.0
ComputeChapterHash computes the SHA-256 hash of a chapter file.
func ComputeConfigHash ¶ added in v0.4.0
ComputeConfigHash computes the SHA-256 hash of the config file.
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
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 CacheStatistics ¶ added in v0.4.0
CacheStatistics tracks cache hit/miss counts.
func NewCacheStatistics ¶ added in v0.4.0
func NewCacheStatistics() *CacheStatistics
NewCacheStatistics creates a new stats tracker.
func (*CacheStatistics) RecordHit ¶ added in v0.4.0
func (s *CacheStatistics) RecordHit()
RecordHit increments hit counter.
func (*CacheStatistics) RecordMiss ¶ added in v0.4.0
func (s *CacheStatistics) RecordMiss()
RecordMiss increments miss counter.
func (*CacheStatistics) String ¶ added in v0.4.0
func (s *CacheStatistics) String() string
String returns a human-readable summary.
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 ¶
func (p *ChapterPipeline) Process(ctx context.Context) (*ChapterPipelineResult, error)
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
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 ¶
func (r *FormatBuilderRegistry) Get(name string) FormatBuilder
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 ManifestEntry ¶ added in v0.4.0
type ManifestEntry struct {
SHA256 string `json:"sha256"`
HTMLPath string `json:"html_path"`
Headings []string `json:"headings"` // List of heading texts for TOC
ModTime time.Time `json:"mod_time"` // Chapter file modification time
}
ManifestEntry represents cached metadata for a single chapter.
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 ServeOptions ¶
ServeOptions encapsulates configuration for the serve command.
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 ThemeColors ¶
type ThemeColors struct {
Primary string
Secondary string
Accent string
Text string
Background string
CodeBg string
}
ThemeColors stores theme color values.
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