1
goldsmith-samples/basic/main.go

43 lines
1.4 KiB
Go
Raw Normal View History

2016-11-02 02:37:42 +00:00
package main
import (
2018-01-08 21:35:02 +00:00
"flag"
2016-11-02 02:37:42 +00:00
"log"
"github.com/FooSoft/goldsmith"
2018-01-08 17:24:26 +00:00
"github.com/FooSoft/goldsmith-components/devserver"
2019-04-08 18:28:50 +00:00
"github.com/FooSoft/goldsmith-components/filters/condition"
2018-01-08 17:24:26 +00:00
"github.com/FooSoft/goldsmith-components/plugins/frontmatter"
"github.com/FooSoft/goldsmith-components/plugins/layout"
"github.com/FooSoft/goldsmith-components/plugins/markdown"
2019-04-08 18:28:50 +00:00
"github.com/FooSoft/goldsmith-components/plugins/minify"
2016-11-02 02:37:42 +00:00
)
2019-04-08 18:28:50 +00:00
type builder struct {
dist bool
}
2016-11-02 02:37:42 +00:00
2019-04-08 18:28:50 +00:00
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
2016-11-02 02:37:42 +00:00
for _, err := range errs {
log.Print(err)
}
}
func main() {
2019-02-01 15:40:18 +00:00
port := flag.Int("port", 8080, "server port")
2019-04-08 18:28:50 +00:00
dist := flag.Bool("dist", false, "final dist mode")
2018-01-08 21:35:02 +00:00
flag.Parse()
2019-02-01 15:40:18 +00:00
2019-04-08 18:28:50 +00:00
devserver.DevServe(&builder{*dist}, *port, "content", "build", "cache")
2016-11-02 02:37:42 +00:00
}