1
0
mirror of https://github.com/osmarks/mycorrhiza.git synced 2024-10-30 03:36:16 +00:00

Fix bugs, it works ok now

This commit is contained in:
Timur Ismagilov 2020-06-17 14:40:51 +05:00
parent 2a3f346034
commit f0da0d7d28
6 changed files with 19 additions and 14 deletions

13
main.go
View File

@ -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

View File

@ -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 += `<article class="page">
<h1 class="page__title">` + r.FullName + `</h1>
`
// TODO: support things other than images
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)
@ -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(`<pre>%s</pre>`, 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(`<pre>%s</pre>`, contents)
}
ret += `

View File

@ -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

View File

@ -6,7 +6,7 @@
"author": "bouncepaw",
"comment": "add apple pic hehehe",
"tags": ["img"],
"text_mime": "plain",
"text_mime": "text/plain",
"binary_mime": "image/jpeg"
}
}

View File

@ -1,3 +1,2 @@
b {
color: red;
}
b { color: red; }
article { border: 1px black solid; }

View File

@ -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":