forked from kashifshah-mirrors/zs
Forked project
This commit is contained in:
parent
6f878ed98e
commit
25c14c56ab
19
README.md
19
README.md
@ -1,7 +1,4 @@
|
||||
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.
|
||||
|
||||
@ -22,11 +19,11 @@ The name stands for 'zen static' as well as it's my initials.
|
||||
|
||||
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)
|
||||
@ -92,12 +89,6 @@ content generation, or additional commands, like LESS to CSS conversion:
|
||||
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.
|
||||
@ -113,7 +104,3 @@ it's an empty string).
|
||||
## 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
|
||||
|
4
go.mod
4
go.mod
@ -1,10 +1,8 @@
|
||||
module github.com/zserge/zs
|
||||
module git.mills.io/prologic/zs
|
||||
|
||||
go 1.17
|
||||
|
||||
require (
|
||||
github.com/eknkc/amber v0.0.0-20171010120322-cdade1c07385
|
||||
github.com/russross/blackfriday/v2 v2.1.0
|
||||
github.com/yosssi/gcss v0.1.0
|
||||
gopkg.in/yaml.v2 v2.4.0
|
||||
)
|
||||
|
4
go.sum
4
go.sum
@ -1,9 +1,5 @@
|
||||
github.com/eknkc/amber v0.0.0-20171010120322-cdade1c07385 h1:clC1lXBpe2kTj2VHdaIu9ajZQe4kcEY9j0NsnDDBZ3o=
|
||||
github.com/eknkc/amber v0.0.0-20171010120322-cdade1c07385/go.mod h1:0vRUJqYpeSZifjYj7uP3BG/gKcuzL9xWVV/Y+cK33KM=
|
||||
github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk=
|
||||
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
|
||||
github.com/yosssi/gcss v0.1.0 h1:jRuino7qq7kqntBIhT+0xSUI5/sBgCA/zCQ1Tuzd6Gg=
|
||||
github.com/yosssi/gcss v0.1.0/go.mod h1:M3mTPOWZWjVROkXKZ2AiDzOBOXu2MqQeDXF/nKO44sI=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
|
||||
|
@ -13,9 +13,7 @@ import (
|
||||
"text/template"
|
||||
"time"
|
||||
|
||||
"github.com/eknkc/amber"
|
||||
"github.com/russross/blackfriday/v2"
|
||||
"github.com/yosssi/gcss"
|
||||
"gopkg.in/yaml.v2"
|
||||
)
|
||||
|
||||
@ -58,10 +56,7 @@ func globals() Vars {
|
||||
// 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
|
||||
}
|
||||
@ -115,11 +110,7 @@ func getVars(path string, globals Vars) (Vars, string, error) {
|
||||
|
||||
// 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"
|
||||
@ -200,11 +191,7 @@ func buildMarkdown(path string, w io.Writer, vars Vars) error {
|
||||
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
|
||||
@ -231,65 +218,6 @@ func buildHTML(path string, w io.Writer, vars Vars) error {
|
||||
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)
|
||||
@ -315,10 +243,6 @@ func build(path string, w io.Writer, vars Vars) error {
|
||||
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)
|
||||
}
|
Loading…
Reference in New Issue
Block a user