diff --git a/server/.notes/create.go b/server/.notes/create.go deleted file mode 100755 index ebf6ec1..0000000 --- a/server/.notes/create.go +++ /dev/null @@ -1,24 +0,0 @@ -package notes - -import ( - "html" - "local/notes-server/filetree" - "net/http" - "path" - "strings" -) - -func (n *Notes) Create(w http.ResponseWriter, r *http.Request) { - content := r.FormValue("base") - content = html.UnescapeString(content) - content = strings.ReplaceAll(content, "\r", "") - urlPath := path.Join(r.URL.Path, content) - p := filetree.NewPathFromURL(urlPath) - if p.IsDir() { - w.WriteHeader(http.StatusBadRequest) - return - } - url := *r.URL - url.Path = path.Join("/edit/", p.BaseHREF) - http.Redirect(w, r, url.String(), http.StatusSeeOther) -} diff --git a/server/.notes/create_test.go b/server/.notes/create_test.go deleted file mode 100755 index 6e8cef9..0000000 --- a/server/.notes/create_test.go +++ /dev/null @@ -1 +0,0 @@ -package notes diff --git a/server/.notes/dir.go b/server/.notes/dir.go deleted file mode 100755 index 9812e0c..0000000 --- a/server/.notes/dir.go +++ /dev/null @@ -1,37 +0,0 @@ -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, ` -
- `, 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) -} diff --git a/server/.notes/dir_test.go b/server/.notes/dir_test.go deleted file mode 100755 index 867b686..0000000 --- a/server/.notes/dir_test.go +++ /dev/null @@ -1,26 +0,0 @@ -package notes - -import ( - "net/http/httptest" - "testing" -) - -func TestLsDir(t *testing.T) { - p := Path{Local: "/usr/local"} - dirs, files := lsDir(p) - if len(dirs) == 0 { - t.Fatal(len(dirs)) - } - if len(files) == 0 { - t.Fatal(len(files)) - } - t.Log(dirs) - t.Log(files) -} - -func TestNotesDir(t *testing.T) { - path := Path{Local: "/usr/local"} - w := httptest.NewRecorder() - notesDir(path, w, nil) - t.Logf("%s", w.Body.Bytes()) -} diff --git a/server/.notes/edit.go b/server/.notes/edit.go deleted file mode 100755 index 794bbdd..0000000 --- a/server/.notes/edit.go +++ /dev/null @@ -1,43 +0,0 @@ -package notes - -import ( - "fmt" - "io/ioutil" - "net/http" - "strings" -) - -func (s *Server) edit(w http.ResponseWriter, r *http.Request) { - p := NewPathFromURL(r.URL.Path) - if p.IsDir() { - http.NotFound(w, r) - return - } - head(w, r) - editHead(w, p) - editFile(w, p) - foot(w, r) -} - -func editHead(w http.ResponseWriter, p Path) { - fmt.Fprintln(w, h2(p.MultiLink())) -} - -func editFile(w http.ResponseWriter, p Path) { - href := p.HREF - href = strings.TrimPrefix(href, "/") - hrefs := strings.SplitN(href, "/", 2) - href = hrefs[0] - if len(hrefs) > 1 { - href = hrefs[1] - } - b, _ := ioutil.ReadFile(p.Local) - fmt.Fprintf(w, ` - - `, href, b) -} diff --git a/server/.notes/edit_test.go b/server/.notes/edit_test.go deleted file mode 100755 index 6e8cef9..0000000 --- a/server/.notes/edit_test.go +++ /dev/null @@ -1 +0,0 @@ -package notes diff --git a/server/.notes/file.go b/server/.notes/file.go deleted file mode 100755 index c372640..0000000 --- a/server/.notes/file.go +++ /dev/null @@ -1,29 +0,0 @@ -package notes - -import ( - "fmt" - "io/ioutil" - "net/http" - "path" - - "github.com/gomarkdown/markdown" - "github.com/gomarkdown/markdown/html" - "github.com/gomarkdown/markdown/parser" -) - -func notesFile(p Path, w http.ResponseWriter, r *http.Request) { - b, _ := ioutil.ReadFile(p.Local) - notesFileHead(p, w) - renderer := html.NewRenderer(html.RendererOptions{ - Flags: html.CommonFlags | html.TOC, - }) - parser := parser.NewWithExtensions(parser.CommonExtensions | parser.HeadingIDs | parser.AutoHeadingIDs | parser.Titleblock) - content := markdown.ToHTML(b, parser, renderer) - fmt.Fprintf(w, "%s\n", content) -} - -func notesFileHead(p Path, w http.ResponseWriter) { - fmt.Fprintf(w, ` - - `, path.Join("/edit/", p.BaseHREF)) -} diff --git a/server/.notes/file_test.go b/server/.notes/file_test.go deleted file mode 100755 index 3d22e3e..0000000 --- a/server/.notes/file_test.go +++ /dev/null @@ -1,46 +0,0 @@ -package notes - -import ( - "fmt" - "io/ioutil" - "net/http/httptest" - "os" - "strings" - "testing" -) - -func TestNotesFile(t *testing.T) { - f, err := ioutil.TempFile(os.TempDir(), "until*") - if err != nil { - t.Fatal(err) - } - defer os.Remove(f.Name()) - fmt.Fprintln(f, ` -# Hello -## World -* This -* is -* bullets - -| My | table | goes | -|----|-------|------| -| h | e | n | - - `) - f.Close() - w := httptest.NewRecorder() - p := Path{Local: f.Name()} - notesFile(p, w, nil) - s := string(w.Body.Bytes()) - shouldContain := []string{ - "tbody", - "h1", - "h2", - } - for _, should := range shouldContain { - if !strings.Contains(s, should) { - t.Fatalf("%s: %s", should, s) - } - } - t.Logf("%s", s) -} diff --git a/server/.notes/notes.go b/server/.notes/notes.go deleted file mode 100755 index 7a676ab..0000000 --- a/server/.notes/notes.go +++ /dev/null @@ -1,13 +0,0 @@ -package notes - -import "local/notes-server/config" - -type Notes struct { - root string -} - -func New() *Notes { - return &Notes{ - root: config.Root, - } -} diff --git a/server/.notes/rnotes.go b/server/.notes/rnotes.go deleted file mode 100755 index 7518bfd..0000000 --- a/server/.notes/rnotes.go +++ /dev/null @@ -1,27 +0,0 @@ -package notes - -import ( - "fmt" - "net/http" -) - -func (s *Server) notes(w http.ResponseWriter, r *http.Request) { - p := NewPathFromURL(r.URL.Path) - if p.IsDir() { - head(w, r) - notesHead(w, p) - notesDir(p, w, r) - foot(w, r) - } else if p.IsFile() { - head(w, r) - notesHead(w, p) - notesFile(p, w, r) - foot(w, r) - } else { - http.NotFound(w, r) - } -} - -func notesHead(w http.ResponseWriter, p Path) { - fmt.Fprintln(w, h2(p.MultiLink())) -} diff --git a/server/.notes/rnotes_test.go b/server/.notes/rnotes_test.go deleted file mode 100755 index 6e8cef9..0000000 --- a/server/.notes/rnotes_test.go +++ /dev/null @@ -1 +0,0 @@ -package notes diff --git a/server/.notes/submit.go b/server/.notes/submit.go deleted file mode 100755 index fc53014..0000000 --- a/server/.notes/submit.go +++ /dev/null @@ -1,31 +0,0 @@ -package notes - -import ( - "fmt" - "html" - "io/ioutil" - "net/http" - "os" - "path" - "strings" -) - -func (s *Server) submit(w http.ResponseWriter, r *http.Request) { - if r.Method != "POST" { - http.NotFound(w, r) - return - } - content := r.FormValue("content") - content = html.UnescapeString(content) - content = strings.ReplaceAll(content, "\r", "") - p := NewPathFromURL(r.URL.Path) - os.MkdirAll(path.Dir(p.Local), os.ModePerm) - if err := ioutil.WriteFile(p.Local, []byte(content), os.ModePerm); err != nil { - w.WriteHeader(http.StatusInternalServerError) - fmt.Fprintln(w, err) - } else { - url := *r.URL - url.Path = path.Join("/notes/", p.BaseHREF) - http.Redirect(w, r, url.String(), http.StatusSeeOther) - } -} diff --git a/server/.notes/submit_test.go b/server/.notes/submit_test.go deleted file mode 100755 index 6e8cef9..0000000 --- a/server/.notes/submit_test.go +++ /dev/null @@ -1 +0,0 @@ -package notes