diff options
Diffstat (limited to 'srv/src/api/render.go')
-rw-r--r-- | srv/src/api/render.go | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/srv/src/api/render.go b/srv/src/api/render.go index 0f45211..8fc2cb6 100644 --- a/srv/src/api/render.go +++ b/srv/src/api/render.go @@ -39,6 +39,10 @@ func (a *api) mustParseTpl(name string) *template.Template { tpl := template.New("").Funcs(template.FuncMap{ "BlogURL": blogURL, + "AssetURL": func(path string) string { + path = filepath.Join("assets", path) + return blogURL(path) + }, }) tpl = template.Must(tpl.Parse(mustRead(name))) @@ -192,3 +196,33 @@ func (a *api) renderDumbHandler(tplName string) http.Handler { } }) } + +func (a *api) renderAdminAssets() http.Handler { + + tpl := a.mustParseTpl("admin/assets.html") + + return http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) { + + ids, err := a.params.PostAssetStore.List() + + if err != nil { + apiutil.InternalServerError( + rw, r, fmt.Errorf("getting list of asset ids: %w", err), + ) + return + } + + tplData := struct { + IDs []string + }{ + IDs: ids, + } + + if err := tpl.Execute(rw, tplData); err != nil { + apiutil.InternalServerError( + rw, r, fmt.Errorf("rendering: %w", err), + ) + return + } + }) +} |