transform

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Sep 6, 2021 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Dir

func Dir(ctx context.Context, logger log.Logger, config []byte) error

Dir transforms directory using given configuration file.

Types

type Config

type Config struct {
	Version int

	// InputDir is a relative (to PWD) path that assumes input directory for markdown files and assets.
	InputDir string `yaml:"inputDir"`
	// OutputDir is a relative (to PWD) output directory that we expect all files to land in. Typically that can be `content` dir
	// which hugo uses as an input.
	OutputDir string `yaml:"outputDir"`

	// ExtraInputGlobs allows to bring files from outside of input dir.
	ExtraInputGlobs []string `yaml:"extraInputGlobs"`

	// LinkPrefixForNonMarkdownResources specifies link to be glued onto relative links which don't point to markdown or image files.
	LinkPrefixForNonMarkdownResources string `yaml:"linkPrefixForNonMarkdownResources"`

	// Transformations to apply for any file.
	Transformations []*TransformationConfig

	// GitIgnored specifies if output dir should be git ignored or not.
	GitIgnored bool `yaml:"gitIgnored"`

	// LocalLinksStyle sets linking style to be applied. If empty, we assume default style.
	LocalLinksStyle LocalLinksStyle `yaml:"localLinksStyle"`
}

func ParseConfig

func ParseConfig(c []byte) (Config, error)

type HugoLocalLinksStyle

type HugoLocalLinksStyle struct {
	// e.g for google/docsy it is "_index.md"
	IndexFileName string `yaml:"indexFileName"`
}

type LocalLinksStyle

type LocalLinksStyle struct {
	// Hugo make sure mdox converts the links to work on Hugo-like website so:
	// * Adds `slug: {{ FileName }}` to make sure filename extension is part of path, if slug is not added.
	// * Local links are lower cased (hugo does that by default).
	// * All links are expected to be paths e.g ../ is added if they target local, non directory links.
	Hugo *HugoLocalLinksStyle
}

type MatterConfig

type MatterConfig struct {

	// Template represents Go template that will be rendered as matter.
	// This will override any existing matter.
	// TODO(bwplotka): Add add only option?
	Template string
	// contains filtered or unexported fields
}

type MatterOrigin

type MatterOrigin struct {
	Filename    string
	FirstHeader string
	LastMod     string
	Path        string
}

type MatterTarget

type MatterTarget struct {
	FileName string
}

type TransformationConfig

type TransformationConfig struct {

	// Glob matches files using https://github.com/gobwas/glob.
	// Glob is matched against the relative path of the file in the input directory in
	// relation to the input directory. For example:
	// InputDir: dir1, File found in dir1/a/b/c/file.md, the given glob will be matched
	// against a/b/c/file.md.
	// After first match, file is no longer matching other elements.
	Glob string

	// Path is an optional different path for the file to be moved.
	// If not specified, file will be moved to the exact same position as in input directory.
	// Use absolute path to point the absolute structure where `/` means output directory.
	// If relative path is used, it will start in the directory the file is in the input directory.
	// NOTE: All relative links will be moved accordingly inside such file.
	// TODO(bwplotka): Explain ** and * suffixes and ability to specify "invalid" paths like "/../".
	Path string

	PopHeader *bool `yaml:"popHeader"`

	// FrontMatter holds front matter transformations.
	FrontMatter *MatterConfig `yaml:"frontMatter"`

	// BackMatter holds back matter transformations.
	BackMatter *MatterConfig `yaml:"backMatter"`
	// contains filtered or unexported fields
}

Jump to

Keyboard shortcuts

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