-
Notifications
You must be signed in to change notification settings - Fork 13
/
gist.go
39 lines (33 loc) · 841 Bytes
/
gist.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package plugins
import (
"fmt"
"github.com/osteele/gojekyll/tags"
"github.com/osteele/liquid"
"github.com/osteele/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
}