1
goldsmith-samples/bootstrap/main.go

78 lines
2.2 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"
2023-12-31 03:46:27 +00:00
"git.foosoft.net/alex/goldsmith"
2024-03-10 03:29:09 +00:00
"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"
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",
}
2024-04-07 05:35:56 +00:00
gs := goldsmith.Goldsmith{CacheDir: cacheDir}
2024-03-10 03:29:09 +00:00
errs := gs.Begin(contentDir).
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
}