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 40 41 42 43 44 45 46 47 48 49 50 51 52 53
| {% import ( "path/filepath" "strings"
"{{{ .Package }}}/app" "{{{ .Package }}}/app/controller/cutil" "{{{ .Package }}}/app/lib/filesystem" "{{{ .Package }}}/views/components" "{{{ .Package }}}/views/layout" "{{{ .Package }}}/views/vfile" ) %}
{% code type Files struct { layout.Basic FS filesystem.FileLoader Path []string } %}
{% func (p *Files) Body(as *app.State, ps *cutil.PageState) %} {%- code u := "/notebook/files" editPath := filepath.Join(p.Path...) hasView := strings.HasSuffix(editPath, ".md") isDir := p.FS.IsDir(filepath.Join(p.Path...)) -%} <div class="card"> {%- if !isDir -%} <div class="right"> {%- if hasView -%} <a href="/notebook/view/{%s= strings.TrimSuffix(editPath, `.md`) %}"><button type="button">View</button></a> {%- endif -%} <a href="/notebook/edit/{%s= editPath %}"><button type="button">Edit</button></a> </div> {%- endif -%} <h3>{%= components.SVGRefIcon(`notebook`, ps) %}Notebook Files</h3> </div> {%- if isDir -%} {%- code files := p.FS.ListFiles(editPath, nil, ps.Logger) -%} <div class="card"> {%= vfile.List(p.Path, files, p.FS, u, as, ps) %} </div> {%- else -%} {%- code b, err := p.FS.ReadFile(filepath.Join(p.Path...)) if err != nil { panic(err) } -%} <div class="card"> {%= vfile.Detail(p.Path, b, u, nil, as, ps) %} </div> {%- endif -%} {% endfunc %}
|