Documentation ¶
Index ¶
Constants ¶
const ( // Name is the application name shown for "dumblog version" Name string = "dumblog" // Version is the current version shown for "dumblog version" Version string = "0.1.7" )
Variables ¶
var TemplateFuncs = text.FuncMap{ "atomdate": func(t time.Time) string { return t.UTC().Format(time.RFC3339) }, "shortdate": func(t time.Time) string { return t.UTC().Format("2006-01-02") }, "prettydate": func(t time.Time) string { return t.UTC().Format("Monday, 02 January 2006") }, "prettyduration": func(d time.Duration) string { s, m, h := int(d.Seconds()), int(d.Minutes()), int(d.Hours()) if s < 1 { return "instant" } else if s == 1 { return "1 second" } else if s < 60 { return fmt.Sprintf("%d seconds", s) } else if m == 1 { return "1 minute" } else if m < 60 { return fmt.Sprintf("%d minutes", m) } else if h == 1 { return "1 hour" } return fmt.Sprintf("%d hours", h) }, "safehtml": func(s string) html.HTML { return html.HTML(s) }, "postslimit": func(max int, posts []Post) []Post { l := len(posts) if l > max { l = max } return posts[:l] }, "postsbydir": func(dir string, posts []Post) []Post { var list []Post for _, p := range posts { if firstDir(p.rel) == dir { list = append(list, p) } } return list }, "slugify": func(s string) string { return url.PathEscape(strings.ReplaceAll(strings.ToLower(s), " ", "_")) }, "isset": func(field string, v interface{}) bool { rv := reflect.ValueOf(v) if rv.Kind() == reflect.Ptr { rv = rv.Elem() } if rv.Kind() != reflect.Struct { return false } return rv.FieldByName(field).IsValid() }, }
TemplateFuncs contains helper functions for the templates
Functions ¶
Types ¶
type Generator ¶
type Generator struct {
// contains filtered or unexported fields
}
Generator is loads & parses templates and then execs & writes them to a directory.
func (*Generator) ExecuteTemplate ¶
ExecuteTemplate executes the templates and write the resulting files to dir. It also copy over any other plain files. ReadTemplate must have been called before.
func (*Generator) ReadTemplate ¶
ReadTemplate loads and parses the template files from `dir`. Optionally tries to load a `.meta.yaml` file, used for providing global meta data to the templates.
type Meta ¶
Meta is a map of strings that allows you to insert custom data into your templates, like links and titles. See example/.meta.yaml and the example html templates for usage.
type Params ¶ added in v0.1.7
type Params struct { // Time is the current date and time Time time.Time // Meta contains user defined meta data, see Meta Meta Meta // Posts is a list of parsed Post Posts []Post // Tags is a list of parsed Tag Tags []Tag // Pages is a list of all html pages that will be written Pages []string }
Params is a struct holding all available meta data you can use in a template.
type Post ¶
type Post struct { Meta struct { // Title is the title of the post Title string // Published is the publishing date Published time.Time // Short is a short description for the post Short string // Tags is a list of optional string tags Tags []string } // contains filtered or unexported fields }
Post contains the meta data header from a `post.md`.
type PostParams ¶ added in v0.1.7
type PostParams struct { Params // Current is the active post being written, otherwise it's nil Current Post }
PostParams is struct similar to Params, but it also holds the currently active post.