1
0
mirror of https://github.com/danog/gojekyll.git synced 2024-11-30 08:39:01 +01:00
gojekyll/plugins/gist.go

40 lines
835 B
Go

package plugins
import (
"fmt"
"github.com/danog/gojekyll/tags"
"github.com/danog/liquid"
"github.com/danog/liquid/render"
)
func init() {
register("jekyll-gist", jekyllGistPlugin{})
}
type jekyllGistPlugin struct{ plugin }
func (p jekyllGistPlugin) ConfigureTemplateEngine(e *liquid.Engine) error {
e.RegisterTag("gist", gistTag)
return nil
}
func gistTag(ctx render.Context) (string, error) {
argsline, err := ctx.ExpandTagArg()
if err != nil {
return "", err
}
args, err := tags.ParseArgs(argsline)
if err != nil {
return "", err
}
if len(args.Args) < 1 {
return "", fmt.Errorf("gist tag: missing argument")
}
url := fmt.Sprintf("https://gist.github.com/%s.js", args.Args[0])
if len(args.Args) >= 2 {
url += fmt.Sprintf("?file=%s", args.Args[1])
}
return `<script src=` + url + `> </script>`, nil
}