config

package
v2.0.5 Latest Latest
Warning

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

Go to latest
Published: Jan 19, 2026 License: GPL-3.0 Imports: 0 Imported by: 0

Documentation

Overview

Package config provides common configuration options used across the GoBlog generator and outputter packages.

The package implements the functional options pattern for configuration, allowing packages to accept both required positional parameters and optional configuration via option functions.

Functional Options Pattern

Configuration is applied through Option values that can be passed to constructors. Each option function modifies specific configuration fields:

gen := generator.New(postsFS, config.WithRawOutput())
writer := outputter.NewDirectoryWriter("output/", config.WithRawOutput())

Options are implemented as structs containing functions that modify embedded configuration types. This pattern allows for:

  • Backward compatibility when adding new options
  • Clear, self-documenting API calls
  • Optional parameters without function overloading

Available Options

WithRawOutput() enables raw HTML output mode without template wrapping. When enabled in the generator, markdown is converted to HTML without inserting it into page templates. When enabled in the outputter, the tags directory is not created.

WithTemplatesDir(fs.FS) specifies a custom filesystem containing templates to use for rendering blog pages. This allows you to provide your own template files instead of using the defaults.

Usage Examples

Basic usage with a single option:

fsys := os.DirFS("posts/")
gen := generator.New(fsys, config.WithRawOutput())

Multiple options can be combined:

templateFS := os.DirFS("templates/")
gen := generator.New(fsys,
    config.WithRawOutput(),
    config.WithTemplatesDir(templateFS),
)

Concurrency

Option values are safe to create and use concurrently. Configuration structs that embed RawOutput and TemplatesDir are safe to read concurrently once created, but should not be modified after construction.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Option added in v2.0.5

type Option struct {
	WithRawOutputFunc func(v *RawOutput)
	WithSiteTitleFunc func(v *SiteTitle)
}

Option represents a configuration option that can be applied to generator or outputter instances during construction.

Options use the functional options pattern, where each option function returns an Option struct containing one or more function pointers that modify specific configuration fields.

This type should not be constructed directly by users. Instead, use the provided option functions like WithRawOutput() and WithTemplatesDir().

func WithRawOutput

func WithRawOutput() Option

WithRawOutput returns an Option that enables raw HTML output mode.

When this option is applied to a generator, it will produce HTML content without template wrapping - only the Markdown-to-HTML conversion is performed. When applied to an outputter, it will skip creating the tags directory.

This is useful for scenarios where you want to integrate GoBlog's HTML output into your own templates or existing site structure.

Example usage:

gen := generator.New(fsys, config.WithRawOutput())
writer := outputter.NewDirectoryWriter("output/", config.WithRawOutput())

func WithSiteTitle added in v2.0.5

func WithSiteTitle(title string) Option

type RawOutput added in v2.0.5

type RawOutput struct{ RawOutput bool }

RawOutput is a configuration type that controls whether HTML output is generated with or without template wrapping.

When RawOutput is true:

  • The generator produces only Markdown-to-HTML conversion without templates
  • The outputter skips creating the tags directory
  • Individual post files contain raw HTML fragments

This type is typically embedded in generator and outputter configuration structs and should be set using the WithRawOutput() option function.

type SiteTitle added in v2.0.5

type SiteTitle struct{ SiteTitle string }

Jump to

Keyboard shortcuts

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