mirror of
https://github.com/osmarks/mycorrhiza.git
synced 2025-04-27 13:03:11 +00:00
Fix bugs, it works ok now
This commit is contained in:
parent
2a3f346034
commit
f0da0d7d28
13
main.go
13
main.go
@ -13,9 +13,13 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func GetRevision(hyphae map[string]*Hypha, hyphaName string, rev string, w http.ResponseWriter) (Revision, bool) {
|
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 {
|
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 {
|
if rev == id {
|
||||||
return *r, true
|
return *r, true
|
||||||
}
|
}
|
||||||
@ -65,7 +69,7 @@ func HandlerRaw(w http.ResponseWriter, r *http.Request) {
|
|||||||
w.WriteHeader(http.StatusNotFound)
|
w.WriteHeader(http.StatusNotFound)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
w.Header().Set("Content-Type", "text/plain")
|
w.Header().Set("Content-Type", rev.TextMime)
|
||||||
w.WriteHeader(http.StatusOK)
|
w.WriteHeader(http.StatusOK)
|
||||||
w.Write(fileContents)
|
w.Write(fileContents)
|
||||||
log.Println("Serving text data of", rev.FullName, rev.Id)
|
log.Println("Serving text data of", rev.FullName, rev.Id)
|
||||||
@ -160,7 +164,10 @@ func main() {
|
|||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
log.Println("Welcome to MycorrhizaWiki α")
|
||||||
|
log.Println("Indexing hyphae...")
|
||||||
hyphae = recurFindHyphae(rootWikiDir)
|
hyphae = recurFindHyphae(rootWikiDir)
|
||||||
|
log.Println("Indexed", len(hyphae), "hyphae. Ready to accept requests.")
|
||||||
// setRelations(hyphae)
|
// setRelations(hyphae)
|
||||||
|
|
||||||
// Start server code
|
// Start server code
|
||||||
|
11
revision.go
11
revision.go
@ -1,7 +1,6 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/gomarkdown/markdown"
|
"github.com/gomarkdown/markdown"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
@ -11,8 +10,9 @@ import (
|
|||||||
|
|
||||||
type Revision struct {
|
type Revision struct {
|
||||||
Id int
|
Id int
|
||||||
|
FullName string
|
||||||
Tags []string `json:"tags"`
|
Tags []string `json:"tags"`
|
||||||
FullName string `json:"name"`
|
ShortName string `json:"name"`
|
||||||
Comment string `json:"comment"`
|
Comment string `json:"comment"`
|
||||||
Author string `json:"author"`
|
Author string `json:"author"`
|
||||||
Time int `json:"time"`
|
Time int `json:"time"`
|
||||||
@ -34,10 +34,11 @@ func (r *Revision) urlOfBinary() string {
|
|||||||
// TODO: use templates https://github.com/bouncepaw/mycorrhiza/issues/2
|
// TODO: use templates https://github.com/bouncepaw/mycorrhiza/issues/2
|
||||||
func (r *Revision) AsHtml(hyphae map[string]*Hypha) (ret string, err error) {
|
func (r *Revision) AsHtml(hyphae map[string]*Hypha) (ret string, err error) {
|
||||||
ret += `<article class="page">
|
ret += `<article class="page">
|
||||||
|
<h1 class="page__title">` + r.FullName + `</h1>
|
||||||
`
|
`
|
||||||
// TODO: support things other than images
|
// TODO: support things other than images
|
||||||
if r.hasBinaryData() {
|
if r.hasBinaryData() {
|
||||||
ret += fmt.Sprintf(`<img src="/%s" class="page__image"/>`, r.urlOfBinary())
|
ret += fmt.Sprintf(`<img src="%s" class="page__amnt"/>`, r.urlOfBinary())
|
||||||
}
|
}
|
||||||
|
|
||||||
contents, err := ioutil.ReadFile(r.TextPath)
|
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 more markups.
|
||||||
// TODO: support mycorrhiza extensions like transclusion.
|
// TODO: support mycorrhiza extensions like transclusion.
|
||||||
switch r.TextMime {
|
switch r.TextMime {
|
||||||
case "text/plain":
|
|
||||||
ret += fmt.Sprintf(`<pre>%s</pre>`, contents)
|
|
||||||
case "text/markdown":
|
case "text/markdown":
|
||||||
html := markdown.ToHTML(contents, nil, nil)
|
html := markdown.ToHTML(contents, nil, nil)
|
||||||
ret += string(html)
|
ret += string(html)
|
||||||
default:
|
default:
|
||||||
return "", errors.New("Unsupported mime-type: " + r.TextMime)
|
ret += fmt.Sprintf(`<pre>%s</pre>`, contents)
|
||||||
}
|
}
|
||||||
|
|
||||||
ret += `
|
ret += `
|
||||||
|
@ -1,3 +1,2 @@
|
|||||||
# Fruit
|
|
||||||
Many people ask the question: what is fruit exactly?
|
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
|
Fruit is a type of fetus. Is tasty so cool coo l ha i love fwriotwsn
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
"author": "bouncepaw",
|
"author": "bouncepaw",
|
||||||
"comment": "add apple pic hehehe",
|
"comment": "add apple pic hehehe",
|
||||||
"tags": ["img"],
|
"tags": ["img"],
|
||||||
"text_mime": "plain",
|
"text_mime": "text/plain",
|
||||||
"binary_mime": "image/jpeg"
|
"binary_mime": "image/jpeg"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,3 +1,2 @@
|
|||||||
b {
|
b { color: red; }
|
||||||
color: red;
|
article { border: 1px black solid; }
|
||||||
}
|
|
||||||
|
1
walk.go
1
walk.go
@ -137,6 +137,7 @@ func recurFindHyphae(fullPath string) map[string]*Hypha {
|
|||||||
// Fill in every revision paths
|
// Fill in every revision paths
|
||||||
for id, paths := range revs {
|
for id, paths := range revs {
|
||||||
if r, ok := h.Revisions[id]; ok {
|
if r, ok := h.Revisions[id]; ok {
|
||||||
|
r.FullName = filepath.Join(h.parentName, r.ShortName)
|
||||||
for fType, fPath := range paths {
|
for fType, fPath := range paths {
|
||||||
switch fType {
|
switch fType {
|
||||||
case "bin":
|
case "bin":
|
||||||
|
Loading…
x
Reference in New Issue
Block a user