Documentation
¶
Overview ¶
Package zas implements the Zas static site generator: it loads configuration and translations, walks a site's source tree, and renders Markdown and HTML pages through a shared layout.
Index ¶
- Variables
- func NewI18n(mainlang string) (i18n gt.Strings, err error)
- type ConfigSection
- type Generator
- func (gen *Generator) BuildDeployPath(path string) string
- func (gen *Generator) Generate(_ string, data *ZasData) (err error)
- func (gen *Generator) GetDeployPath() string
- func (gen *Generator) Html(e *goquery.Selection, _ *goquery.Document, data *ZasData) (err error)
- func (gen *Generator) Markdown(e *goquery.Selection, _ *goquery.Document, data *ZasData) (err error)
- func (gen *Generator) Plain(e *goquery.Selection, _ *goquery.Document, data *ZasData) (err error)
- func (gen *Generator) Run() error
- type Init
- type Subcommand
- type ZasData
- func (zd *ZasData) E(s string, a ...interface{}) (t string, err error)
- func (zd *ZasData) Extra(keypath string) (value string, err error)
- func (zd *ZasData) H(s string, a ...interface{}) (h thtml.HTML, err error)
- func (zd *ZasData) IsHome() (bool, error)
- func (zd *ZasData) Language() (string, error)
- func (zd *ZasData) Resolve(id string) (string, error)
- func (zd *ZasData) Title() (title string)
- func (zd *ZasData) URL() string
- type ZasSiteData
Constants ¶
This section is empty.
Variables ¶
var ( ZAS = "zas" ZAS_PREFIX = "zs" ZAS_NAME = cases.Title(language.English).String(ZAS) ZAS_DIR = "." + ZAS ZAS_CONF_FILE = filepath.Join(ZAS_DIR, "config.yml") ZAS_I18N_FILE = filepath.Join(ZAS_DIR, "i18n.yml") ZAS_DIR_CONF_FILE = fmt.Sprintf(".%s.yml", ZAS) ZAS_DEFAULT_DIR_PERM = 0o755 ZAS_DEFAULT_FILE_PERM = 0o644 ZAS_DEFAULT_CONF = ConfigSection{ ZAS: ConfigSection{ "layout": filepath.Join(ZAS_DIR, "layout.html"), "deploy": filepath.Join(ZAS_DIR, "deploy"), }, "site": ConfigSection{ "baseurl": "http://example.com", "language": "en", }, "mimetypes": ConfigSection{ "text/markdown": "markdown", "text/plain": "plain", "text/html": "html", }, } )
ZAS and the other identifiers below are exported mutable configuration used by both the zas library and the cmd/zas CLI.
Functions ¶
Types ¶
type ConfigSection ¶
type ConfigSection map[interface{}]interface{}
ConfigSection aliases goyaml's default map type.
func NewConfig ¶
func NewConfig() (ConfigSection, error)
NewConfig loads ZAS_CONF_FILE (as defined in constants.go). It must be a YAML file.
func (ConfigSection) GetSection ¶
func (cs ConfigSection) GetSection(key string) (value ConfigSection)
GetSection returns a subsection from current section, or nil if key is missing or not a section.
func (ConfigSection) GetString ¶
func (cs ConfigSection) GetString(key string) (value string)
GetString returns a string value from current section.
func (ConfigSection) GetZString ¶
func (cs ConfigSection) GetZString(key string) string
GetZString returns a string value from default Zas section.
type Generator ¶
type Generator struct {
// Verbose output.
Verbose bool
// Full generation (non-incremental mode).
Full bool
// Config from ZAS_CONF_FILE.
Config ConfigSection
// Default layout from Config[ZAS]["layout"].
Layout *thtml.Template
// i18n helper.
I18n *gt.Build
// contains filtered or unexported fields
}
Generator groups relevant rendering info.
func (*Generator) BuildDeployPath ¶
BuildDeployPath builds deployment path for specific file pointed by path.
func (*Generator) Generate ¶
Generate renders and writes the file at data.Path using the given template context.
func (*Generator) GetDeployPath ¶
GetDeployPath returns deployment base path in config.
func (*Generator) Markdown ¶
func (gen *Generator) Markdown(e *goquery.Selection, _ *goquery.Document, data *ZasData) (err error)
Markdown embeds a Markdown file.
type Init ¶
type Init struct{}
Init implements the "init" subcommand, which scaffolds a new Zas repository in the current directory.
type Subcommand ¶
type Subcommand struct {
// Runs the subcommand
// The args are the arguments after the subcommand name.
Run func() error
// UsageLine is the one-line usage message.
// The first word in the line is taken to be the subcommand name.
UsageLine string
// Name is the name of the subcommand.
Name string
// Flag is a set of flags specific to this command.
Flag flag.FlagSet
}
Subcommand is a Zas internal subcommand, inspired by the go command.
func NewSubcommand ¶
func NewSubcommand(usageLine string, run func() error) *Subcommand
NewSubcommand builds a Subcommand from a usage line and its run function.
type ZasData ¶
type ZasData struct {
// Template used as body from current file.
Body thtml.HTML
// Current path (usable in URLs).
Path string
// Title from first level header (H1).
FirstTitle string
// Site configuration, as found in ZAS_CONF_FILE.
Site ZasSiteData
// In-page configuration, from first HTML comment (expected as YAML map).
Page map[interface{}]interface{}
// Current directory configuration, from ZAS_DIR_CONF_FILE.
Directory ConfigSection
// contains filtered or unexported fields
}
ZasData is the context data store used in templates.
func NewZasData ¶
NewZasData builds a ZasData for the page at filepath.
func (*ZasData) E ¶
E translates s for the page's resolved language, falling back to "**s**" when no translation is found.
func (*ZasData) Extra ¶
Extra is a helper template method to get any value from ZasData.config using paths.
func (*ZasData) Resolve ¶
Resolve resolves id from Page, then Directory, then site-wide Extra config, in that order. It returns an error only when id is present in Page or Directory but isn't a string (e.g. a page-config typo like "language:" with no value, or a numeric value) — a genuinely absent key still falls back to Extra's own lenient "" default.
type ZasSiteData ¶
ZasSiteData is the site configuration.
They are required fields in order to complete social/semantic meta tags.
