diff --git a/basic/content/layouts/basic.gohtml b/basic/content/layouts/basic.gohtml index 460e033..ae3aaf3 100644 --- a/basic/content/layouts/basic.gohtml +++ b/basic/content/layouts/basic.gohtml @@ -3,7 +3,6 @@ - {{.Meta.Title}} @@ -15,12 +14,8 @@ {{end}} {{define "page"}} -{{template "header" .}} -
- + {{template "header" .}} +

{{.Meta.Title}}

{{.Meta.Content}} -
-{{template "footer" .}} + {{template "footer" .}} {{end}} diff --git a/basic/main.go b/basic/main.go index 6003c25..d636ca7 100644 --- a/basic/main.go +++ b/basic/main.go @@ -6,20 +6,27 @@ import ( "github.com/FooSoft/goldsmith" "github.com/FooSoft/goldsmith-components/devserver" + "github.com/FooSoft/goldsmith-components/filters/condition" "github.com/FooSoft/goldsmith-components/plugins/frontmatter" "github.com/FooSoft/goldsmith-components/plugins/layout" "github.com/FooSoft/goldsmith-components/plugins/markdown" + "github.com/FooSoft/goldsmith-components/plugins/minify" ) -type builder struct{} +type builder struct { + dist bool +} -func (b *builder) Build(contentDir, buildDir, cacheDir string) { - errs := goldsmith.Begin(contentDir). - Cache(cacheDir). - Chain(frontmatter.New()). - Chain(markdown.New()). - Chain(layout.New()). - End(buildDir) +func (b *builder) Build(srcDir, dstDir, cacheDir string) { + errs := goldsmith. + Begin(srcDir). // read files from srcDir + Chain(frontmatter.New()). // extract frontmatter and store it as metadata + Chain(markdown.New()). // convert *.md files to *.html files + Chain(layout.New()). // apply *.gohtml templates to *.html files + FilterPush(condition.New(b.dist)). // push a dist-only conditional filter onto the stack + Chain(minify.New()). // minify *.html, *.css, *.js, etc. files + FilterPop(). // pop off the last filter pushed onto the stack + End(dstDir) // write files to dstDir for _, err := range errs { log.Print(err) @@ -28,7 +35,8 @@ func (b *builder) Build(contentDir, buildDir, cacheDir string) { func main() { port := flag.Int("port", 8080, "server port") + dist := flag.Bool("dist", false, "final dist mode") flag.Parse() - devserver.DevServe(new(builder), *port, "content", "build", "cache") + devserver.DevServe(&builder{*dist}, *port, "content", "build", "cache") }