-zs
-==
-
-[![Build Status](https://travis-ci.org/zserge/zs.svg?branch=master)](https://travis-ci.org/zserge/zs)
+# zs
zs is an extremely minimal static site generator written in Go.
Download the binaries from Github or build it manually:
- $ go get github.com/zserge/zs
+ $ go get git.mills.io/prologic/zs
## Ideology
-Keep your texts in markdown, [amber] or HTML format right in the main directory
+Keep your texts in markdown, or HTML format right in the main directory
of your blog/site.
Keep all service files (extensions, layout pages, deployment scripts etc)
lessc < $ZS_OUTDIR/styles.less > $ZS_OUTDIR/styles.css
rm -f $ZS_OUTDIR/styles.css
-## Syntax sugar
-
-By default, `zs` converts each `.amber` file into `.html`, so you can use lightweight Jade-like syntax instead of bloated HTML.
-
-Also, `zs` converts `.gcss` into `.css`, so you don't really need LESS or SASS. More about GCSS can be found [here][gcss].
-
## Command line usage
`zs build` re-builds your site.
## License
The software is distributed under the MIT license.
-
-[amber]: https://github.com/eknkc/amber/
-[YAML]: https://github.com/go-yaml/yaml
-[gcss]: https://github.com/yosssi/gcss
"text/template"
"time"
- "github.com/eknkc/amber"
"github.com/russross/blackfriday/v2"
- "github.com/yosssi/gcss"
"gopkg.in/yaml.v2"
)
// prepended. Additional variable $ZS contains path to the zs binary. Command
// stderr is printed to zs stderr, command output is returned as a string.
func run(vars Vars, cmd string, args ...string) (string, error) {
- // First check if partial exists (.amber or .html)
- if b, err := ioutil.ReadFile(filepath.Join(ZSDIR, cmd+".amber")); err == nil {
- return string(b), nil
- }
+ // First check if partial exists (.html)
if b, err := ioutil.ReadFile(filepath.Join(ZSDIR, cmd+".html")); err == nil {
return string(b), nil
}
// Add layout if none is specified
if _, ok := v["layout"]; !ok {
- if _, err := os.Stat(filepath.Join(ZSDIR, "layout.amber")); err == nil {
- v["layout"] = "layout.amber"
- } else {
- v["layout"] = "layout.html"
- }
+ v["layout"] = "layout.html"
}
delim := "\n---\n"
defer out.Close()
w = out
}
- if strings.HasSuffix(v["layout"], ".amber") {
- return buildAmber(filepath.Join(ZSDIR, v["layout"]), w, v)
- } else {
- return buildHTML(filepath.Join(ZSDIR, v["layout"]), w, v)
- }
+ return buildHTML(filepath.Join(ZSDIR, v["layout"]), w, v)
}
// Renders text file expanding all variable macros inside it
return tmpl.Execute(w, vars)
}
-// Renders .amber file into .html
-func buildAmber(path string, w io.Writer, vars Vars) error {
- v, body, err := getVars(path, vars)
- if err != nil {
- return err
- }
- a := amber.New()
- if err := a.Parse(body); err != nil {
- fmt.Println(body)
- return err
- }
-
- t, err := a.Compile()
- if err != nil {
- return err
- }
-
- htmlBuf := &bytes.Buffer{}
- if err := t.Execute(htmlBuf, v); err != nil {
- return err
- }
-
- if body, err = render(string(htmlBuf.Bytes()), v); err != nil {
- return err
- }
-
- if w == nil {
- f, err := os.Create(filepath.Join(PUBDIR, renameExt(path, ".amber", ".html")))
- if err != nil {
- return err
- }
- defer f.Close()
- w = f
- }
- _, err = io.WriteString(w, body)
- return err
-}
-
-// Compiles .gcss into .css
-func buildGCSS(path string, w io.Writer) error {
- f, err := os.Open(path)
- if err != nil {
- return err
- }
- defer f.Close()
-
- if w == nil {
- s := strings.TrimSuffix(path, ".gcss") + ".css"
- css, err := os.Create(filepath.Join(PUBDIR, s))
- if err != nil {
- return err
- }
- defer css.Close()
- w = css
- }
- _, err = gcss.Compile(w, f)
- return err
-}
-
// Copies file as is from path to writer
func buildRaw(path string, w io.Writer) error {
in, err := os.Open(path)
return buildMarkdown(path, w, vars)
} else if ext == ".html" || ext == ".xml" {
return buildHTML(path, w, vars)
- } else if ext == ".amber" {
- return buildAmber(path, w, vars)
- } else if ext == ".gcss" {
- return buildGCSS(path, w)
} else {
return buildRaw(path, w)
}