38 lines
743 B
Go
Executable File
38 lines
743 B
Go
Executable File
package notes
|
|
|
|
import (
|
|
"fmt"
|
|
"io/ioutil"
|
|
"net/http"
|
|
"path"
|
|
)
|
|
|
|
func notesDir(p Path, w http.ResponseWriter, r *http.Request) {
|
|
dirs, files := lsDir(p)
|
|
content := dirs.List()
|
|
notesDirHead(p, w)
|
|
block(content, w)
|
|
fmt.Fprintln(w, files.List())
|
|
}
|
|
|
|
func notesDirHead(p Path, w http.ResponseWriter) {
|
|
fmt.Fprintf(w, `
|
|
<form action=%q method="get">
|
|
<input type="text" name="base"></input>
|
|
<button type="submit">Create</button>
|
|
</form>
|
|
`, path.Join("/create/", p.BaseHREF))
|
|
}
|
|
|
|
func lsDir(path Path) (Paths, Paths) {
|
|
dirs := newDirs()
|
|
files := newFiles()
|
|
|
|
found, _ := ioutil.ReadDir(path.Local)
|
|
for _, f := range found {
|
|
dirs.Push(path, f)
|
|
files.Push(path, f)
|
|
}
|
|
return Paths(*dirs), Paths(*files)
|
|
}
|