generator

package
v0.0.0-...-7635d6e Latest Latest
Warning

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

Go to latest
Published: Apr 27, 2023 License: MIT Imports: 19 Imported by: 0

Documentation

Overview

Package generator implements the static site generator.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrAuthorUnset     = fmt.Errorf("author is unset")
	ErrContentDirUnset = fmt.Errorf("content dir is unset")
	ErrOutputDirUnset  = fmt.Errorf("output dir is unset")
)
View Source
var ErrEmptyName = fmt.Errorf("name must not be empty")

Functions

func DefaultTemplateFS

func DefaultTemplateFS() fs.FS

Types

type Config

type Config struct {
	// Author is the websites' author (required).
	Author string `json:"author"`
	// BaseURL is the base URL that is used when generating absolute/canoncical URLs.
	BaseURL string `json:"base_url"`
	// ContentDir is the path of a directory that contains the websites content (required).
	ContentDir string `json:"content_dir"`
	// StaticDir is the path of a directory that contains static files to include in the generated website.
	StaticDir string `json:"static_dir"`
	// OutputDir is the path of a directory where the generated website will be stored into.
	OutputDir string `json:"output_dir"`
	// TemplatesDir is the path of a directory that contains a set of custom templates used to render the website.
	TemplatesDir string `json:"templates_dir"`
	// EnableUnsafeHTML allow embedding raw HTML snippets into markdown.
	EnableUnsafeHTML bool `json:"unsafe_html"`
}

Config contains generator configuration values.

func ParseConfigFile

func ParseConfigFile(path string) (*Config, error)

ParseConfigFile instantiates a configuration from the given file.

func (*Config) Validate

func (c *Config) Validate() error

Validate returns an error if the configuration is incomplete or invalid.

type FileStorage

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

FileStorage persists to a local file system.

func NewFileStorage

func NewFileStorage(baseDir string) *FileStorage

NewFileStorage returns an initialized FileStorage.

func (*FileStorage) Store

func (s *FileStorage) Store(ctx context.Context, name string, content io.Reader) error

Store implements Storage.

type Generator

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

func New

func New(
	config *Config,
	sourceFS, staticFS fs.FS,
	stor Storage,
	slugifier *slug.Slugifier,
	renderer renderer.Renderer,
) *Generator

New returns a new Generator instance.

func (*Generator) Run

func (g *Generator) Run(ctx context.Context) error

Run generates the website.

type Storage

type Storage interface {
	Store(ctx context.Context, name string, content io.Reader) error
}

Storage provides methods for persisting files of the generated website.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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