2017-07-02 05:06:47 +02:00
|
|
|
package plugins
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"github.com/osteele/gojekyll/tags"
|
2017-07-09 04:47:50 +02:00
|
|
|
"github.com/osteele/liquid"
|
2017-07-04 23:13:47 +02:00
|
|
|
"github.com/osteele/liquid/render"
|
2017-07-02 05:06:47 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
2017-07-09 04:47:50 +02:00
|
|
|
register("jekyll-gist", jekyllGistPlugin{})
|
|
|
|
}
|
|
|
|
|
|
|
|
type jekyllGistPlugin struct{ plugin }
|
|
|
|
|
2017-07-10 15:17:31 +02:00
|
|
|
func (p jekyllGistPlugin) ConfigureTemplateEngine(e *liquid.Engine) error {
|
2017-07-09 04:47:50 +02:00
|
|
|
e.RegisterTag("gist", gistTag)
|
|
|
|
return nil
|
2017-07-02 05:06:47 +02:00
|
|
|
}
|
|
|
|
|
2017-07-04 23:13:47 +02:00
|
|
|
func gistTag(ctx render.Context) (string, error) {
|
2017-07-06 05:26:47 +02:00
|
|
|
argsline, err := ctx.ExpandTagArg()
|
2017-07-02 05:06:47 +02:00
|
|
|
if err != nil {
|
2017-07-04 14:06:34 +02:00
|
|
|
return "", err
|
2017-07-02 05:06:47 +02:00
|
|
|
}
|
|
|
|
args, err := tags.ParseArgs(argsline)
|
|
|
|
if err != nil {
|
2017-07-04 14:06:34 +02:00
|
|
|
return "", err
|
2017-07-02 05:06:47 +02:00
|
|
|
}
|
|
|
|
if len(args.Args) < 1 {
|
2017-07-04 14:06:34 +02:00
|
|
|
return "", fmt.Errorf("gist tag: missing argument")
|
2017-07-02 05:06:47 +02:00
|
|
|
}
|
|
|
|
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])
|
|
|
|
}
|
2017-07-04 14:06:34 +02:00
|
|
|
return `<script src=` + url + `> </script>`, nil
|
2017-07-02 05:06:47 +02:00
|
|
|
}
|