engine

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jan 28, 2023 License: 0BSD Imports: 32 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// the context path can be used if the page is not hosted at the domain root
	CONTEXT_PATH = "/"
	// the post author is used globally for all posts
	POST_AUTHOR = "Anonymous"
)

Functions

func GenerateStyles

func GenerateStyles(dist io.Writer, theme string, opts ...chromahtml.Option) error

generates CSS styles with the given theme or fallback and write them to the writer

func NormalizeMdName

func NormalizeMdName(s string) string

normalize the string by stripping the date prefix and .md suffix

Types

type Engine

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

func New

func New(options ...Option) Engine

func (Engine) DistDir

func (e Engine) DistDir() string

func (Engine) DocsDir

func (e Engine) DocsDir() string

func (Engine) ExtraAssetsDir

func (e Engine) ExtraAssetsDir() string

func (Engine) FuncMap

func (e Engine) FuncMap() template.FuncMap

create a funcmap to be used by the templates

func (Engine) MakeLayout

func (e Engine) MakeLayout(name string) (*template.Template, error)

func (Engine) Meta

func (e Engine) Meta() map[string]any

func (Engine) MetaPath

func (e Engine) MetaPath() string

func (Engine) Run

func (e Engine) Run() error

func (Engine) SourceDir

func (e Engine) SourceDir() string

func (Engine) ThemeAssetsDir

func (e Engine) ThemeAssetsDir() string

func (Engine) ThemeTemplatesDir

func (e Engine) ThemeTemplatesDir() string

type Errors

type Errors []error

func (Errors) Error

func (ee Errors) Error() string

type FuncMapClosure

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

closes over the engine to provide specialized functions that can be used inside the templates. The methods of this struct are available as lowercase functions inside the funcmap

func NewFuncMapClosure

func NewFuncMapClosure(e *Engine) *FuncMapClosure

create a new closure funcmap instance

func (*FuncMapClosure) Excerpt

func (fmc *FuncMapClosure) Excerpt() func(b []byte) string

generate an expert in form of an html paragraph. the paragraph will be the first paragraph of the raw markdown. if the markdown has no paragraphs, the returned string is empty

func (*FuncMapClosure) FuncMap

func (fmc *FuncMapClosure) FuncMap() template.FuncMap

generate the funcmap to be used by the templates

func (fmc *FuncMapClosure) Link() func(href, rel string) string

create an html link tag resolving to the assets dir. This is useful because it takes the context path into consideration. When the context path is changed the generated links will change accordingly. Use this to link local assets in your templates

func (*FuncMapClosure) Meta

func (fmc *FuncMapClosure) Meta() func() map[string]any

retrieve the structured content of the meta.yaml

func (*FuncMapClosure) Render

func (fmc *FuncMapClosure) Render() func(b []byte) string

convert the given raw markdown bytes to html

func (*FuncMapClosure) Toc

func (fmc *FuncMapClosure) Toc() func(b []byte) string

generate a table of contents from the raw markdown bytes. the toc is returned as html ul element

type Option

type Option func(opts *Options)

func WithAuthor

func WithAuthor(author string) Option

func WithChromaStyle

func WithChromaStyle(style string) Option

func WithContextPath

func WithContextPath(path string) Option

func WithDist

func WithDist(dist string) Option

func WithSource

func WithSource(src string) Option

func WithTheme

func WithTheme(theme string) Option

type Options

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

type SortDirection

type SortDirection string
const (
	SortDirectionAscending  SortDirection = "asc"
	SortDirectionDescending SortDirection = "desc"
)

type TreeNode

type TreeNode struct {

	// the path withing the source fs
	SourcePath string
	// the raw entry
	Entry fs.DirEntry
	// true if its the top level root node
	IsRoot bool
	// true if node does not have children aka is a file and not a dir
	IsLeaf bool
	// pointer to the parent node. Is nil for the root node
	Parent *TreeNode
	// slice of children. Always empty for leave nodes
	Children TreeNodeList
	// pointer to root node. will point to itself for the treeRoot
	// this makes it more easy to use it in templates
	Root *TreeNode
	// contains filtered or unexported fields
}

func (*TreeNode) Author

func (n *TreeNode) Author() string

return the author of the node this is currently set to a static value since we do not use front matter

func (*TreeNode) Content

func (n *TreeNode) Content() []byte

get the content for this node by reading the source file this is done in this method so we don't need to read all files into memory, at once. Each piece of content can be read lazily when its actually needed because a given template wants to use it. if its not a leaf note, the content of the index.md in the given dir is returned if possible. Otherwise the byte slice will have len 0

func (*TreeNode) Date

func (n *TreeNode) Date() time.Time

return the creation date of the node. For leafs the date will be inferred from the date-suffix of the source file i.e. 2022-03-05-myfile.md. for non-leafs (folders) the date of the oldest children will be used. if the node is non-leaf and has no children, using oldest is not possible in that case it will fallback to using the sourceFiles modtime.

func (*TreeNode) FirstChild

func (n *TreeNode) FirstChild() *TreeNode

get the first child of this node. Returns nil of node has no children

func (*TreeNode) HasChildren

func (n *TreeNode) HasChildren() bool

return true if node has children

func (*TreeNode) HasSiblings

func (n *TreeNode) HasSiblings() bool

return true if node has siblings

func (*TreeNode) Name

func (n *TreeNode) Name() string

Return the normalized name as its used on a web page. this will strip the date prefix and .md suffix

func (*TreeNode) NextSibling

func (n *TreeNode) NextSibling() *TreeNode

get the next sibling. Panics if called on the root node returns nil of node has no next sibling

func (*TreeNode) Path

func (n *TreeNode) Path() string

return the normalized path as its used on the web page. Meaning it does not point to the nodes source and it will always point to a directory because even leaf nodes are created as index.html under a directory with the leaf nodes name

func (*TreeNode) PreviousSibling

func (n *TreeNode) PreviousSibling() *TreeNode

get the previous sibling. Panics if called on the root node returns nil of node has no previous sibling

func (*TreeNode) Siblings

func (n *TreeNode) Siblings() TreeNodeList

convenience function to get a nodes siblings this is the same as getting the parents children, filtering itself out will panic when called on the root node, since a root has no parent and therefore no siblings

func (*TreeNode) SortDate

func (n *TreeNode) SortDate(direction SortDirection) *TreeNode

traverse the tree starting from this node to all leafs, and sort the children of each node

func (*TreeNode) Title

func (n *TreeNode) Title() string

return the normalized name as human readable title. dashes are replaced with spaces and the word tokens are title cased

type TreeNodeList

type TreeNodeList []*TreeNode

func (TreeNodeList) Leafs

func (tc TreeNodeList) Leafs() TreeNodeList

get all leafs

func (TreeNodeList) Oldest

func (tc TreeNodeList) Oldest() *TreeNode

get the oldest (Date) child. Since this is calling Date on each children, and the Date function calls oldest, for non-leaf nodes, this will recurse the tree until leafs hare found and propagate their date upwards to the parent

func (TreeNodeList) SortDate

func (tc TreeNodeList) SortDate(direction SortDirection) TreeNodeList

sorts the child list in place. Making the sort permanent

type TreeWalker

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

func (TreeWalker) RenderWalk

func (tw TreeWalker) RenderWalk(node *TreeNode) error

Jump to

Keyboard shortcuts

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