belbo

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Dec 19, 2021 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DateLayout        = "2006-01-02"
	DefaultBaseLayout = `{{ define "base_layout" }}{{ template "content" . }}{{ end }}`
)
View Source
const PluginsFilename = "plugins.so"

Variables

This section is empty.

Functions

func Copy

func Copy(srcFile, dstFile string) error

func CopyDirectory

func CopyDirectory(scrDir, dest string) error
func CopySymLink(source, dest string) error

func CreateIfNotExists

func CreateIfNotExists(dir string, perm os.FileMode) error

func EnableParallelContent

func EnableParallelContent(content string) string

func Exists

func Exists(filePath string) bool

func LoadFuncsAsPlugins added in v0.2.1

func LoadFuncsAsPlugins(pluginsPath string) map[string]interface{}

func Replace

func Replace(content string, replacements []*Replaceable) string

Replace replaces replaceables in the content with <span> elements

Types

type Belbo added in v0.2.0

type Belbo struct {
	Fsys         fs.FS
	Config       *Config
	ContentDir   []string
	TemplatesDir string
	Templates    []string
	BuildDir     string
	PluginsDir   string
	Plugins      map[string]interface{}
	Pages        []*Page
}

Belbo takes as input a file system and a configuration file to transform a bunch of MD and html templates into html

func NewBelbo added in v0.2.0

func NewBelbo(cfg *Config, fsys fs.FS, funcs map[string]interface{}) *Belbo

func (*Belbo) BuildPages added in v0.2.0

func (b *Belbo) BuildPages()

func (*Belbo) IsContentDir added in v0.2.0

func (b *Belbo) IsContentDir(dirname string) bool

type Config added in v0.2.0

type Config map[string]interface{}

Config represents a toml snippet

func NewConfig added in v0.2.0

func NewConfig(tomlConfig string, defaultCfg *Config) (*Config, error)

func (Config) Get added in v0.2.0

func (cfg Config) Get(key string) interface{}

func (Config) GetString added in v0.2.0

func (cfg Config) GetString(key string) string

func (Config) GetStringSlice added in v0.2.0

func (cfg Config) GetStringSlice(key string) []string

func (Config) MergeWith added in v0.2.0

func (cfg Config) MergeWith(b Config) Config

type Location

type Location struct {
	InitPos  int
	FinalPos int
}

Location defines a location in the text content

func NonReplaceableAreas

func NonReplaceableAreas(c string) []Location

NonReplaceableAreas are places in the text that should be kept untouched. For now, take into account only text within <code> elements

type Page

type Page struct {
	// Front-matter
	Config Config

	RawContent string

	// Html representation of the page
	Html template.HTML

	// Path before page is processed (e.g., posts/2020-01-12-example.md)
	RelativePath string

	// e.g., /posts/2020/01/example/index.html
	Url string

	Title string

	// Pointer to all the other pages
	AllPages []*Page

	// CreationDate for pages whose name includes a date
	CreatedAt time.Time

	BuildDir []string
}

Page represents anything that may be written out as html

func NewPage added in v0.2.0

func NewPage(pagePath string, rd io.Reader, cfg *Config) *Page

func (*Page) ToHtml

func (p *Page) ToHtml(b *Belbo) template.HTML

type Replaceable

type Replaceable struct {
	InitPos  int
	FinalPos int
	Original string
}

Replaceable represents a snippet of text that will be replaced by <span> elements

func FindReplaceablesSnippets

func FindReplaceablesSnippets(content string) []*Replaceable

FindReplaceablesSnippets finds snippets in the form @{C1||C2||...||Cn}@ that will be replaced later by <span> elements.

Jump to

Keyboard shortcuts

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