2017-10-15 16:44:36 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2015 Alex Yatskov <alex@foosoft.net>
|
|
|
|
* Author: Alex Yatskov <alex@foosoft.net>
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
|
|
* this software and associated documentation files (the "Software"), to deal in
|
|
|
|
* the Software without restriction, including without limitation the rights to
|
|
|
|
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
|
|
|
* the Software, and to permit persons to whom the Software is furnished to do so,
|
|
|
|
* subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included in all
|
|
|
|
* copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
|
|
|
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
|
|
|
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
|
|
|
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
|
|
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
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"
|
2018-01-08 21:35:02 +00:00
|
|
|
"github.com/FooSoft/goldsmith-components/filters/condition"
|
2018-01-27 21:43:42 +00:00
|
|
|
"github.com/FooSoft/goldsmith-components/filters/summary"
|
2018-01-08 21:25:54 +00:00
|
|
|
"github.com/FooSoft/goldsmith-components/plugins/abs"
|
2018-01-08 17:24:26 +00:00
|
|
|
"github.com/FooSoft/goldsmith-components/plugins/breadcrumbs"
|
|
|
|
"github.com/FooSoft/goldsmith-components/plugins/collection"
|
|
|
|
"github.com/FooSoft/goldsmith-components/plugins/dom"
|
|
|
|
"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"
|
|
|
|
"github.com/FooSoft/goldsmith-components/plugins/paginate"
|
|
|
|
"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"
|
|
|
|
)
|
|
|
|
|
2017-12-29 18:20:10 +00:00
|
|
|
func fixup(doc *goquery.Document) error {
|
2017-10-15 16:44:36 +00:00
|
|
|
doc.Find("table").AddClass("table")
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2018-01-08 21:25:54 +00:00
|
|
|
type builder struct {
|
|
|
|
root string
|
|
|
|
}
|
2017-10-15 16:44:36 +00:00
|
|
|
|
|
|
|
func (b *builder) Build(srcDir, dstDir string) {
|
|
|
|
tagMeta := map[string]interface{}{
|
|
|
|
"Area": "tags",
|
|
|
|
"CrumbParent": "tags",
|
|
|
|
"Layout": "tag",
|
|
|
|
}
|
|
|
|
|
|
|
|
indexMeta := map[string]interface{}{
|
|
|
|
"Layout": "index",
|
|
|
|
}
|
|
|
|
|
|
|
|
errs := goldsmith.Begin(srcDir).
|
|
|
|
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()).
|
2018-01-27 21:43:42 +00:00
|
|
|
Chain(paginate.New("Groups.Blog").InheritKeys("Layout").ItemsPerPage(4)).
|
2017-10-15 16:44:36 +00:00
|
|
|
Chain(index.New(indexMeta)).
|
|
|
|
Chain(tags.New().IndexMeta(tagMeta)).
|
|
|
|
Chain(breadcrumbs.New()).
|
|
|
|
Chain(layout.New("layouts/*.html")).
|
|
|
|
Chain(syntax.New().Placement(syntax.PlaceInline)).
|
2017-12-29 18:20:10 +00:00
|
|
|
Chain(dom.New(fixup)).
|
2017-10-15 16:44:36 +00:00
|
|
|
Chain(thumbnail.New()).
|
2018-01-08 23:27:39 +00:00
|
|
|
FilterPush(condition.New(len(b.root) > 0)).
|
2018-01-08 21:35:02 +00:00
|
|
|
Chain(abs.New().BaseUrl(b.root)).
|
|
|
|
FilterPop().
|
2017-10-15 16:44:36 +00:00
|
|
|
End(dstDir)
|
|
|
|
|
|
|
|
for _, err := range errs {
|
|
|
|
log.Print(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func main() {
|
2018-01-08 21:25:54 +00:00
|
|
|
var (
|
2018-01-09 02:08:50 +00:00
|
|
|
dst = flag.String("dst", "dst", "destination directory")
|
2018-01-08 21:25:54 +00:00
|
|
|
root = flag.String("root", "", "root directory")
|
|
|
|
port = flag.Int("port", 8080, "server port")
|
|
|
|
)
|
|
|
|
flag.Parse()
|
2018-01-09 02:08:50 +00:00
|
|
|
devserver.DevServe(&builder{*root}, *port, "src", *dst, "layouts")
|
2017-10-15 16:44:36 +00:00
|
|
|
}
|