Documentation
¶
Overview ¶
Pacakge medusa is a very simple static site generator that works by chaining functions together. When Builder.Build is called, It reads all the files in the source directory and represents them all as a slice of File. A pointer to this slice, along with a pointer to the global Store, is passed to every Transformer sequencially. At the end of the chain, it writes the state of the File slice to the destination.
Each file also has a Frontmatter field where yaml/toml/json frontmatter is parsed and stored. The builder returns ErrFrontmatter if it failes to parse fronmatter of a file. Frontmatter parsing can be skipped via Config.
Configuration defaults generally rely on Go's zero values (e.g., false for booleans, nil for pointers, "" for strings), with specific overrides in NewBuilder for fields like WorkingDir (defaults to "./") and Logger (defaults to a discard logger).
Example Usage ¶
package main import ( "log" "log/slog" "os" "git.sr.ht/~relay/medusa" ) func main() { // Example with custom configuration config := medusa.Config{ Logger: slog.New(slog.NewTextHandler(os.Stderr, &slog.HandlerOptions{ Level: slog.LevelDebug, })), AllowOverwrite: true, // Skip overwrite prompts } b := medusa.NewBuilder(config) // Example with default configuration // b := medusa.NewBuilder() b.Source("./src") b.Destination("./build") // Add transformers if needed // b.Use(...) err := b.Build() if err != nil { panic(err) } }
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrDestinationExists = errors.New("destination directory exists and overwrite not permitted")
ErrDestinationExists indicates that the destination directory exists and overwriting was not explicitly allowed via Config.AllowOverwrite.
Functions ¶
This section is empty.
Types ¶
type Builder ¶
type Builder struct {
// contains filtered or unexported fields
}
func NewBuilder ¶
Creates a new builder struct. The config parameter is optional. If more than one config is passed, it uses the first one. Defaults are applied based on Go's zero values where applicable: - WorkingDir: Defaults to "./" if empty. - AllowOverwrite: Defaults to false. If true, allows overwriting the destination. - Logger: Defaults to a discard logger if nil. - SkipFrontmatterParsing: Defaults to false.
func (*Builder) Build ¶
Build applies the transformers in the stack to the contents of every file in the source directory, and writes them to the destination. It returns ErrDestinationExists if the destination directory exists and Config.AllowOverwrite is false.
func (*Builder) Destination ¶
Defines the destination directory, relative to WorkingDir as specified in Config.
func (*Builder) Source ¶
Defines the source directory, relative to WorkingDir as specified in Config.
func (*Builder) Use ¶
func (b *Builder) Use(transformer Transformer)
Adds a transformer function to the stack.
type Config ¶
type Config struct { // Defines the working directory. // It is used to find the source and // destination directory. // // Optional. Defaults to the current directory ("./") if empty. WorkingDir string // Whether prompts like // "overwrite warnings" should be skipped. // // Optional. Defaults to false. AllowOverwrite bool // Defines which logger to use. // // Optional. Defaults to a discard logger if nil. Logger *slog.Logger // Whether frontmatter parsing should be skipped. // // Optional. Defaults to false. SkipFrontmatterParsing bool }
type ErrFrontmatter ¶
type ErrFrontmatter struct {
// contains filtered or unexported fields
}
func (ErrFrontmatter) Error ¶
func (e ErrFrontmatter) Error() string
type File ¶
type Transformer ¶
A function that change files and a global store as a part of a larger chain.
func ErrTransformer ¶
func ErrTransformer(err error) Transformer
Returns empty transformer with error
Directories
¶
Path | Synopsis |
---|---|
transformers
|
|
collections
Package collections is a medusa transformer that group files together in collections.
|
Package collections is a medusa transformer that group files together in collections. |
layouts
Package layouts provides a Medusa transformer for applying Go html/template layouts and partials to content files.
|
Package layouts provides a Medusa transformer for applying Go html/template layouts and partials to content files. |