Documentation ¶
Index ¶
- Variables
- func GenerateStyles(dist io.Writer, theme string, opts ...chromahtml.Option) error
- func NormalizeMdName(s string) string
- type Engine
- func (e Engine) DistDir() string
- func (e Engine) DocsDir() string
- func (e Engine) ExtraAssetsDir() string
- func (e Engine) FuncMap() template.FuncMap
- func (e Engine) MakeLayout(name string) (*template.Template, error)
- func (e Engine) Meta() map[string]any
- func (e Engine) MetaPath() string
- func (e Engine) Run() error
- func (e Engine) SourceDir() string
- func (e Engine) ThemeAssetsDir() string
- func (e Engine) ThemeTemplatesDir() string
- type Errors
- type FuncMapClosure
- func (fmc *FuncMapClosure) Excerpt() func(b []byte) string
- func (fmc *FuncMapClosure) FuncMap() template.FuncMap
- func (fmc *FuncMapClosure) Link() func(href, rel string) string
- func (fmc *FuncMapClosure) Meta() func() map[string]any
- func (fmc *FuncMapClosure) Render() func(b []byte) string
- func (fmc *FuncMapClosure) Toc() func(b []byte) string
- type Option
- type Options
- type SortDirection
- type TreeNode
- func (n *TreeNode) Author() string
- func (n *TreeNode) Content() []byte
- func (n *TreeNode) Date() time.Time
- func (n *TreeNode) FirstChild() *TreeNode
- func (n *TreeNode) HasChildren() bool
- func (n *TreeNode) HasSiblings() bool
- func (n *TreeNode) Name() string
- func (n *TreeNode) NextSibling() *TreeNode
- func (n *TreeNode) Path() string
- func (n *TreeNode) PreviousSibling() *TreeNode
- func (n *TreeNode) Siblings() TreeNodeList
- func (n *TreeNode) SortDate(direction SortDirection) *TreeNode
- func (n *TreeNode) Title() string
- type TreeNodeList
- type TreeWalker
Constants ¶
This section is empty.
Variables ¶
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 ¶
generates CSS styles with the given theme or fallback and write them to the writer
func NormalizeMdName ¶
normalize the string by stripping the date prefix and .md suffix
Types ¶
type Engine ¶
type Engine struct {
// contains filtered or unexported fields
}
func (Engine) ExtraAssetsDir ¶
func (Engine) ThemeAssetsDir ¶
func (Engine) ThemeTemplatesDir ¶
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 (*FuncMapClosure) Link ¶
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 WithChromaStyle ¶
func WithContextPath ¶
func WithSource ¶
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 ¶
return the author of the node this is currently set to a static value since we do not use front matter
func (*TreeNode) Content ¶
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 ¶
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 ¶
get the first child of this node. Returns nil of node has no children
func (*TreeNode) HasChildren ¶
return true if node has children
func (*TreeNode) HasSiblings ¶
return true if node has siblings
func (*TreeNode) Name ¶
Return the normalized name as its used on a web page. this will strip the date prefix and .md suffix
func (*TreeNode) NextSibling ¶
get the next sibling. Panics if called on the root node returns nil of node has no next sibling
func (*TreeNode) Path ¶
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 ¶
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
type TreeNodeList ¶
type TreeNodeList []*TreeNode
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