1
goldsmith-samples/bootstrap/main.go

78 lines
2.3 KiB
Go
Raw Normal View History

2017-10-15 16:44:36 +00:00
package main
import (
2018-01-08 21:25:54 +00:00
"flag"
2017-10-15 16:44:36 +00:00
"log"
"github.com/FooSoft/goldsmith"
2018-01-08 17:24:26 +00:00
"github.com/FooSoft/goldsmith-components/devserver"
2019-02-02 02:46:23 +00:00
"github.com/FooSoft/goldsmith-components/plugins/absolute"
2018-01-08 17:24:26 +00:00
"github.com/FooSoft/goldsmith-components/plugins/breadcrumbs"
"github.com/FooSoft/goldsmith-components/plugins/collection"
2019-02-02 02:46:23 +00:00
"github.com/FooSoft/goldsmith-components/plugins/document"
2018-01-08 17:24:26 +00:00
"github.com/FooSoft/goldsmith-components/plugins/frontmatter"
"github.com/FooSoft/goldsmith-components/plugins/index"
"github.com/FooSoft/goldsmith-components/plugins/layout"
"github.com/FooSoft/goldsmith-components/plugins/markdown"
2018-08-11 20:14:50 +00:00
"github.com/FooSoft/goldsmith-components/plugins/summary"
2018-01-08 17:24:26 +00:00
"github.com/FooSoft/goldsmith-components/plugins/syntax"
"github.com/FooSoft/goldsmith-components/plugins/tags"
"github.com/FooSoft/goldsmith-components/plugins/thumbnail"
2017-10-15 16:44:36 +00:00
"github.com/PuerkitoBio/goquery"
)
2022-01-09 02:33:05 +00:00
func fixup(file *goldsmith.File, doc *goquery.Document) error {
2019-04-05 19:56:50 +00:00
doc.Find("table").AddClass("table").Find("thead").AddClass("thead-light")
2017-10-15 16:44:36 +00:00
doc.Find("blockquote").AddClass("blockquote")
doc.Find("img[src*='thumb']").Each(func(i int, s *goquery.Selection) {
thumbLink := s.ParentFiltered("a")
thumbLink.AddClass("img-thumbnail", "img-thumbnail-inline")
thumbLink.SetAttr("data-title", s.AttrOr("alt", ""))
thumbLink.SetAttr("data-toggle", "lightbox")
thumbLink.SetAttr("data-gallery", "gallery")
})
return nil
}
2019-02-27 17:18:28 +00:00
type builder struct{}
2017-10-15 16:44:36 +00:00
2022-01-09 02:33:05 +00:00
func (self *builder) Build(contentDir, buildDir, cacheDir string) {
2017-10-15 16:44:36 +00:00
tagMeta := map[string]interface{}{
"Area": "tags",
"CrumbParent": "tags",
"Layout": "tag",
}
indexMeta := map[string]interface{}{
"Layout": "index",
}
2019-02-02 02:46:23 +00:00
errs := goldsmith.Begin(contentDir).
Cache(cacheDir).
2017-10-15 16:44:36 +00:00
Chain(frontmatter.New()).
2018-01-27 21:43:42 +00:00
Chain(markdown.New()).
Chain(summary.New()).
2017-12-10 17:50:36 +00:00
Chain(collection.New()).
2017-10-15 16:44:36 +00:00
Chain(index.New(indexMeta)).
Chain(tags.New().IndexMeta(tagMeta)).
Chain(breadcrumbs.New()).
2019-02-02 02:46:23 +00:00
Chain(layout.New()).
2017-10-15 16:44:36 +00:00
Chain(syntax.New().Placement(syntax.PlaceInline)).
2019-02-02 02:46:23 +00:00
Chain(document.New(fixup)).
2017-10-15 16:44:36 +00:00
Chain(thumbnail.New()).
2019-02-27 17:18:28 +00:00
Chain(absolute.New()).
2019-02-02 02:46:23 +00:00
End(buildDir)
2017-10-15 16:44:36 +00:00
for _, err := range errs {
log.Print(err)
}
}
func main() {
2019-02-02 02:46:23 +00:00
port := flag.Int("port", 8080, "server port")
2018-01-08 21:25:54 +00:00
flag.Parse()
2019-02-02 02:46:23 +00:00
2019-02-27 17:18:28 +00:00
devserver.DevServe(new(builder), *port, "content", "build", "cache")
2017-10-15 16:44:36 +00:00
}