diff --git a/README.md b/README.md index cc54d61..de66bec 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,4 @@ # ytid simple Go package to extract a Youtube ID from a passed URL -## methods -GetID(url string) string - -GETIDWithError(url string) (string, error) - +Also for flosch/pongo2 and pongo2v3 filter registration methods \ No newline at end of file diff --git a/ytid.go b/ytid.go index 8e5e1e3..427de0d 100644 --- a/ytid.go +++ b/ytid.go @@ -3,6 +3,9 @@ package ytid import ( "fmt" "regexp" + + "github.com/flosch/pongo2" + p2v3 "gopkg.in/flosch/pongo2.v3" ) var ( @@ -16,6 +19,21 @@ var ( } ) +func RegisterPongo2V3() { + p2v3.RegisterFilter("ytid", filterYtid2v3) +} +func filterYtid2v3(in *p2v3.Value, param *p2v3.Value) (*p2v3.Value, *p2v3.Error) { + return p2v3.AsValue(GetID(in.String())), nil +} + +func RegisterPongo() { + pongo2.RegisterFilter("ytid", filterYtid) + +} +func filterYtid(in *pongo2.Value, param *pongo2.Value) (*pongo2.Value, *pongo2.Error) { + return pongo2.AsValue(GetID(in.String())), nil +} + func GetID(url string) string { if !regexpYoutubeDomain.MatchString(url) { return "" @@ -40,6 +58,3 @@ func GetIDWithError(url string) (string, error) { return "", fmt.Errorf("ytid: no match found") } - -/* - */