1
Fork 0
goldsmith-samples/bootstrap/main.go

78 lines
2.2 KiB
Go

package main
import (
"flag"
"log"
"git.foosoft.net/alex/goldsmith"
"git.foosoft.net/alex/goldsmith/devserver"
"git.foosoft.net/alex/goldsmith/plugins/absolute"
"git.foosoft.net/alex/goldsmith/plugins/breadcrumbs"
"git.foosoft.net/alex/goldsmith/plugins/collection"
"git.foosoft.net/alex/goldsmith/plugins/document"
"git.foosoft.net/alex/goldsmith/plugins/frontmatter"
"git.foosoft.net/alex/goldsmith/plugins/index"
"git.foosoft.net/alex/goldsmith/plugins/layout"
"git.foosoft.net/alex/goldsmith/plugins/markdown"
"git.foosoft.net/alex/goldsmith/plugins/summary"
"git.foosoft.net/alex/goldsmith/plugins/syntax"
"git.foosoft.net/alex/goldsmith/plugins/tags"
"git.foosoft.net/alex/goldsmith/plugins/thumbnail"
"github.com/PuerkitoBio/goquery"
)
func fixup(file *goldsmith.File, doc *goquery.Document) error {
doc.Find("table").AddClass("table").Find("thead").AddClass("thead-light")
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
}
type builder struct{}
func (self *builder) Build(contentDir, buildDir, cacheDir string) {
tagMeta := map[string]interface{}{
"Area": "tags",
"CrumbParent": "tags",
"Layout": "tag",
}
indexMeta := map[string]interface{}{
"Layout": "index",
}
gs := goldsmith.Goldsmith{CacheDir: cacheDir}
errs := gs.Begin(contentDir).
Chain(frontmatter.New()).
Chain(markdown.New()).
Chain(summary.New()).
Chain(collection.New()).
Chain(index.New(indexMeta)).
Chain(tags.New().IndexMeta(tagMeta)).
Chain(breadcrumbs.New()).
Chain(layout.New()).
Chain(syntax.New().Placement(syntax.PlaceInline)).
Chain(document.New(fixup)).
Chain(thumbnail.New()).
Chain(absolute.New()).
End(buildDir)
for _, err := range errs {
log.Print(err)
}
}
func main() {
port := flag.Int("port", 8080, "server port")
flag.Parse()
devserver.DevServe(new(builder), *port, "content", "build", "cache")
}