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
2022-01-09 02:33:05 +00:00
func (self *builder) Build(srcDir, dstDir, cacheDir string) {
2019-04-08 18:28:50 +00:00
errs := goldsmith.
2022-01-09 02:33:05 +00:00
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(self.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
}