mirror of
https://github.com/danog/gojekyll.git
synced 2024-11-26 23:14:40 +01:00
Implement scssify
This commit is contained in:
parent
0a4781e8ef
commit
71d03c3627
@ -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.
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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”"},
|
||||
|
Loading…
Reference in New Issue
Block a user