diff --git a/main.go b/main.go index b550a5d..bc62f5f 100644 --- a/main.go +++ b/main.go @@ -13,9 +13,13 @@ import ( ) func GetRevision(hyphae map[string]*Hypha, hyphaName string, rev string, w http.ResponseWriter) (Revision, bool) { - for name, _ := range hyphae { + log.Println("Getting hypha", hyphaName, rev) + for name, hypha := range hyphae { if name == hyphaName { - for id, r := range hyphae[name].Revisions { + if rev == "0" { + rev = hypha.NewestRevision() + } + for id, r := range hypha.Revisions { if rev == id { return *r, true } @@ -65,7 +69,7 @@ func HandlerRaw(w http.ResponseWriter, r *http.Request) { w.WriteHeader(http.StatusNotFound) return } - w.Header().Set("Content-Type", "text/plain") + w.Header().Set("Content-Type", rev.TextMime) w.WriteHeader(http.StatusOK) w.Write(fileContents) log.Println("Serving text data of", rev.FullName, rev.Id) @@ -160,7 +164,10 @@ func main() { panic(err) } + log.Println("Welcome to MycorrhizaWiki α") + log.Println("Indexing hyphae...") hyphae = recurFindHyphae(rootWikiDir) + log.Println("Indexed", len(hyphae), "hyphae. Ready to accept requests.") // setRelations(hyphae) // Start server code diff --git a/revision.go b/revision.go index 6839991..411a5ad 100644 --- a/revision.go +++ b/revision.go @@ -1,7 +1,6 @@ package main import ( - "errors" "fmt" "github.com/gomarkdown/markdown" "io/ioutil" @@ -11,8 +10,9 @@ import ( type Revision struct { Id int + FullName string Tags []string `json:"tags"` - FullName string `json:"name"` + ShortName string `json:"name"` Comment string `json:"comment"` Author string `json:"author"` Time int `json:"time"` @@ -34,10 +34,11 @@ func (r *Revision) urlOfBinary() string { // TODO: use templates https://github.com/bouncepaw/mycorrhiza/issues/2 func (r *Revision) AsHtml(hyphae map[string]*Hypha) (ret string, err error) { ret += `
+

` + r.FullName + `

` // TODO: support things other than images if r.hasBinaryData() { - ret += fmt.Sprintf(``, r.urlOfBinary()) + ret += fmt.Sprintf(``, r.urlOfBinary()) } contents, err := ioutil.ReadFile(r.TextPath) @@ -48,13 +49,11 @@ func (r *Revision) AsHtml(hyphae map[string]*Hypha) (ret string, err error) { // TODO: support more markups. // TODO: support mycorrhiza extensions like transclusion. switch r.TextMime { - case "text/plain": - ret += fmt.Sprintf(`
%s
`, contents) case "text/markdown": html := markdown.ToHTML(contents, nil, nil) ret += string(html) default: - return "", errors.New("Unsupported mime-type: " + r.TextMime) + ret += fmt.Sprintf(`
%s
`, contents) } ret += ` diff --git a/w/m/Fruit/2.txt b/w/m/Fruit/2.txt index e438aab..80e180f 100644 --- a/w/m/Fruit/2.txt +++ b/w/m/Fruit/2.txt @@ -1,3 +1,2 @@ -# Fruit Many people ask the question: what is fruit exactly? Fruit is a type of fetus. Is tasty so cool coo l ha i love fwriotwsn diff --git a/w/m/Fruit/Apple/meta.json b/w/m/Fruit/Apple/meta.json index be05cac..732f242 100644 --- a/w/m/Fruit/Apple/meta.json +++ b/w/m/Fruit/Apple/meta.json @@ -6,7 +6,7 @@ "author": "bouncepaw", "comment": "add apple pic hehehe", "tags": ["img"], - "text_mime": "plain", + "text_mime": "text/plain", "binary_mime": "image/jpeg" } } diff --git a/w/m/sys/main.css/1.txt b/w/m/sys/main.css/1.txt index 4c868a4..e33571d 100644 --- a/w/m/sys/main.css/1.txt +++ b/w/m/sys/main.css/1.txt @@ -1,3 +1,2 @@ -b { - color: red; -} +b { color: red; } +article { border: 1px black solid; } diff --git a/walk.go b/walk.go index d24257f..a86e611 100644 --- a/walk.go +++ b/walk.go @@ -137,6 +137,7 @@ func recurFindHyphae(fullPath string) map[string]*Hypha { // Fill in every revision paths for id, paths := range revs { if r, ok := h.Revisions[id]; ok { + r.FullName = filepath.Join(h.parentName, r.ShortName) for fType, fPath := range paths { switch fType { case "bin":