diff options
| author | tjpcc <tjp@ctrl-c.club> | 2023-10-10 17:02:49 -0600 |
|---|---|---|
| committer | tjpcc <tjp@ctrl-c.club> | 2023-10-10 18:13:59 -0600 |
| commit | f5478f396d6a15f29dee3915132af99e84716f4a (patch) | |
| tree | dff518257813e2071f6e58875ace0e65b7f00779 /parse.go | |
| parent | 365b6bd5319cde40b5cf34b73d01e0fe5755d92e (diff) | |
support showyourwork template override directories on git directives
fixes #5
Diffstat (limited to 'parse.go')
| -rw-r--r-- | parse.go | 26 |
1 files changed, 26 insertions, 0 deletions
@@ -8,8 +8,10 @@ import ( "io" "net" "os/user" + "path/filepath" "strconv" "strings" + "text/template" "github.com/go-kit/log/level" "tildegit.org/tjp/sliderule/gemini" @@ -448,12 +450,36 @@ func parseModifiers(text string) (Modifiers, string, error) { mod.titanName = text[0:idx] text = text[idx+1:] } + case "templates": + if sep != " " { + return mod, "", errors.New("invalid 'templates' clause") + } + text = strings.TrimLeft(text, " \t") + idx = strings.IndexAny(text, " \t,") + var err error + if idx == 0 { + return mod, "", errors.New("invalid 'templates' clause") + } else if idx < 0 { + mod.Templates, err = loadTemplates(text) + text = "" + } else { + mod.Templates, err = loadTemplates(text[0:idx]) + text = text[idx+1:] + } + + if err != nil { + return mod, "", err + } default: return mod, text, nil } } } +func loadTemplates(dirpath string) (*template.Template, error) { + return template.ParseGlob(filepath.Join(dirpath, "*")) +} + func parseAuth(text string) (string, string, error) { spl := strings.SplitN(text, " ", 2) switch len(spl) { |
