diff --git a/README.md b/README.md index ff6b0d9..2ce9f07 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,8 @@ Gojekyll is a clone of the [Jekyll](https://jekyllrb.com) static site generator, written in the [Go](https://golang.org) programming language. It provides `build` and `serve` commands, with directory watch and live reload. +Gojekyll is intended as an homage to Jekyll, and as a possible alternative in situations (such as iterative development of sites that don't use unsupported features) where speed is more important than total compatibility. + |   | Gojekyll | Jekyll | Hugo | |-------------------------|-------------------------------------------|--------|--------------| | Stable | | ✓ | ✓ | @@ -86,8 +88,7 @@ Missing features: - Pagination - Math - Plugin system. ([Some plugins](./docs/plugins.md) are emulated.) -- Liquid tag `tablerow`. -- Liquid filter `scssify` +- Liquid filter `sassify` - Markdown features: [attribute lists](https://kramdown.gettalong.org/syntax.html#attribute-list-definitions), [`markdown=1`](https://kramdown.gettalong.org/syntax.html#html-blocks). - `site.data` is not sorted. - Undefined Liquid tags and filters are errors, not warnings. diff --git a/filters/filters.go b/filters/filters.go index 7217867..42c60cf 100644 --- a/filters/filters.go +++ b/filters/filters.go @@ -18,6 +18,7 @@ import ( "github.com/osteele/liquid/evaluator" "github.com/osteele/liquid/expressions" "github.com/russross/blackfriday" + libsass "github.com/wellington/go-libsass" ) // AddJekyllFilters adds the Jekyll filters to the Liquid engine. @@ -118,7 +119,8 @@ func AddJekyllFilters(e *liquid.Engine, c *config.Config) { // string escapes e.RegisterFilter("cgi_escape", url.QueryEscape) - e.RegisterFilter("scssify", unimplementedFilter("scssify")) + e.RegisterFilter("sassify", unimplementedFilter("sassify")) + e.RegisterFilter("scssify", scssifyFilter) e.RegisterFilter("smartify", smartifyFilter) e.RegisterFilter("uri_escape", func(s string) string { return regexp.MustCompile(`\?(.+?)=([^&]*)(?:\&(.+?)=([^&]*))*`).ReplaceAllStringFunc(s, func(m string) string { @@ -281,3 +283,21 @@ func whereFilter(array []map[string]interface{}, key string, value interface{}) } return result } + +// string filters + +func scssifyFilter(s string) (string, error) { + // this doesn't try to share context or setup with the rendering pipeline, + // and it doesn't minify + buf := new(bytes.Buffer) + comp, err := libsass.New(buf, bytes.NewBufferString(s)) + if err != nil { + return "", err + } + // err = comp.Option(libsass.WithSyntax(libsass.SassSyntax)) + if err != nil { + return "", err + } + err = comp.Run() + return buf.String(), err +} diff --git a/filters/filters_test.go b/filters/filters_test.go index 282a331..acad539 100644 --- a/filters/filters_test.go +++ b/filters/filters_test.go @@ -62,6 +62,9 @@ var filterTests = []struct{ in, expected string }{ {`{{ "The _config.yml file" | slugify: 'default' }}`, "the-config-yml-file"}, {`{{ "The _config.yml file" | slugify: 'pretty' }}`, "the-_config.yml-file"}, + // {`{{ "nav\n\tmargin: 0" | sassify }}`, "nav {\n margin: 0; }"}, + {`{{ "nav {margin: 0}" | scssify }}`, "nav {\n margin: 0; }"}, + {`{{ "smartify single 'quotes' here" | smartify }}`, "smartify single ‘quotes’ here"}, {`{{ 'smartify double "quotes" here' | smartify }}`, "smartify double “quotes” here"}, {"{{ \"smartify ``backticks''\" | smartify }}", "smartify “backticks”"},