1
0
mirror of https://github.com/danog/gojekyll.git synced 2024-12-12 12:37:21 +01:00
gojekyll/plugins/gist.go

35 lines
723 B
Go
Raw Normal View History

2017-07-02 05:06:47 +02:00
package plugins
import (
"fmt"
"github.com/osteele/gojekyll/tags"
2017-07-04 23:13:47 +02:00
"github.com/osteele/liquid/render"
2017-07-02 05:06:47 +02:00
)
func init() {
registerPlugin("jekyll-gist", func(_ PluginContext, h pluginHelper) error {
h.tag("gist", gistTag)
return nil
})
}
2017-07-04 23:13:47 +02:00
func gistTag(ctx render.Context) (string, error) {
2017-07-02 05:06:47 +02:00
argsline, err := ctx.ParseTagArgs()
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
}