Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
minodisk committed Feb 24, 2016
1 parent 75231b6 commit a5eeced
Show file tree
Hide file tree
Showing 22 changed files with 1,030 additions and 193 deletions.
44 changes: 40 additions & 4 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (
"net/http"
"os"
"path/filepath"
"strings"
"time"

"golang.org/x/net/websocket"
)
Expand Down Expand Up @@ -59,22 +61,56 @@ func socket(ws *websocket.Conn) {
}
websocket.JSON.Send(ws, NewReqRes(req, paths))
}
time.Sleep(time.Second)
}
}

func findMarkdownFiles() (pathes []string, err error) {
err = filepath.Walk(".", func(p string, i os.FileInfo, e error) (err error) {
type Element struct {
ID string `json:"id"`
Name string `json:"name"`
Children []*Element `json:"children"`
}

func findMarkdownFiles() (root Element, err error) {
err = filepath.Walk(".", func(path string, i os.FileInfo, e error) (err error) {
if e != nil {
err = e
return
}
if i.IsDir() {
return
}
if filepath.Ext(p) != ".md" {
if filepath.Ext(path) != ".md" {
return
}
pathes = append(pathes, p)

parent := &root

dir, file := filepath.Split(path)
dir = strings.TrimLeft(dir, "/")
dir = strings.TrimRight(dir, "/")
if dir != "" {
dirs := strings.Split(dir, "/")
for _, name := range dirs {
found := false
for _, c := range parent.Children {
if c.Name == name {
parent = c
found = true
break
}
}

if !found {
e := &Element{Name: name}
parent.Children = append(parent.Children, e)
parent = e
}
}
}

parent.Children = append(parent.Children, &Element{Name: file})

return
})
return
Expand Down
Loading

0 comments on commit a5eeced

Please sign in to comment.