Make hypha names case and space insensitive (testing to be done)
@ -38,12 +38,10 @@ func InitConfig(wd string) bool {
|
||||
|
||||
if _, err := os.Stat(configJsonPath); os.IsNotExist(err) {
|
||||
log.Println("config.json not found, using default values")
|
||||
} else {
|
||||
log.Println("config.json found, overriding default values...")
|
||||
return readConfig()
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
log.Println("config.json found, overriding default values...")
|
||||
return readConfig()
|
||||
}
|
||||
|
||||
func readConfig() bool {
|
||||
|
@ -10,6 +10,7 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/bouncepaw/mycorrhiza/cfg"
|
||||
"github.com/bouncepaw/mycorrhiza/util"
|
||||
)
|
||||
|
||||
func (h *Hypha) MetaJsonPath() string {
|
||||
@ -17,7 +18,7 @@ func (h *Hypha) MetaJsonPath() string {
|
||||
}
|
||||
|
||||
func (h *Hypha) Path() string {
|
||||
return filepath.Join(cfg.WikiDir, h.FullName)
|
||||
return filepath.Join(cfg.WikiDir, util.UrlToCanonical(h.FullName))
|
||||
}
|
||||
|
||||
func (h *Hypha) TextPath() string {
|
||||
@ -25,7 +26,7 @@ func (h *Hypha) TextPath() string {
|
||||
}
|
||||
|
||||
func (h *Hypha) parentName() string {
|
||||
return filepath.Dir(h.FullName)
|
||||
return filepath.Dir(util.UrlToCanonical(h.FullName))
|
||||
}
|
||||
|
||||
// hasBinaryData returns true if the revision has any binary data associated.
|
||||
|
3
fs/fs.go
@ -54,6 +54,3 @@ func (s *Storage) indexHyphae(path string) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (h *Hypha) Close() {
|
||||
}
|
||||
|
@ -6,6 +6,8 @@ import (
|
||||
"path/filepath"
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
"github.com/bouncepaw/mycorrhiza/util"
|
||||
)
|
||||
|
||||
func (s *Storage) RenderHypha(h *Hypha) {
|
||||
@ -24,6 +26,7 @@ type Tree struct {
|
||||
// It can also generate trees for non-existent hyphae, that's why we use `name string` instead of making it a method on `Hypha`.
|
||||
// In `root` is `false`, siblings will not be fetched.
|
||||
func (s *Storage) GetTree(name string, root bool) *Tree {
|
||||
name = util.UrlToCanonical(name)
|
||||
t := &Tree{Name: name, Root: root}
|
||||
for hyphaName, _ := range s.paths {
|
||||
s.compareNamesAndAppend(t, hyphaName)
|
||||
@ -65,14 +68,14 @@ func (t *Tree) AsHtml() (html string) {
|
||||
html += `<ul class="navitree__node">`
|
||||
if t.Root {
|
||||
for _, ancestor := range t.Ancestors {
|
||||
html += navitreeEntry(ancestor, "navitree__ancestor")
|
||||
html += navitreeEntry(util.CanonicalToDisplay(ancestor), "navitree__ancestor")
|
||||
}
|
||||
for _, siblingName := range t.Siblings {
|
||||
html += navitreeEntry(siblingName, "navitree__sibling")
|
||||
html += navitreeEntry(util.CanonicalToDisplay(siblingName), "navitree__sibling")
|
||||
}
|
||||
html += navitreeEntry(t.Name, "navitree__pagename")
|
||||
html += navitreeEntry(util.CanonicalToDisplay(t.Name), "navitree__pagename")
|
||||
} else {
|
||||
html += navitreeEntry(t.Name, "navitree__name")
|
||||
html += navitreeEntry(util.CanonicalToDisplay(t.Name), "navitree__name")
|
||||
}
|
||||
|
||||
for _, subtree := range t.Descendants {
|
||||
@ -89,5 +92,5 @@ func navitreeEntry(name, class string) string {
|
||||
return fmt.Sprintf(`<li class="navitree__entry %s">
|
||||
<a class="navitree__link" href="/%s">%s</a>
|
||||
</li>
|
||||
`, class, name, filepath.Base(name))
|
||||
`, class, util.DisplayToCanonical(name), filepath.Base(name))
|
||||
}
|
||||
|
@ -6,6 +6,7 @@ import (
|
||||
"io/ioutil"
|
||||
"log"
|
||||
|
||||
"github.com/bouncepaw/mycorrhiza/util"
|
||||
"gopkg.in/russross/blackfriday.v2"
|
||||
)
|
||||
|
||||
@ -20,7 +21,7 @@ func (h *Hypha) asHtml() (string, error) {
|
||||
`
|
||||
// What about using <figure>?
|
||||
if h.hasBinaryData() {
|
||||
ret += fmt.Sprintf(`<img src="/%s?action=binary&rev=%d" class="page__amnt"/>`, rev.FullName, rev.Id)
|
||||
ret += fmt.Sprintf(`<img src="/%s?action=binary&rev=%d" class="page__amnt"/>`, util.DisplayToCanonical(rev.FullName), rev.Id)
|
||||
}
|
||||
|
||||
contents, err := ioutil.ReadFile(rev.TextPath)
|
||||
|
@ -13,6 +13,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/bouncepaw/mycorrhiza/cfg"
|
||||
"github.com/bouncepaw/mycorrhiza/util"
|
||||
)
|
||||
|
||||
type Hypha struct {
|
||||
@ -33,9 +34,10 @@ func (h *Hypha) Invalidate(err error) *Hypha {
|
||||
}
|
||||
|
||||
func (s *Storage) Open(name string) *Hypha {
|
||||
name = util.UrlToCanonical(name)
|
||||
h := &Hypha{
|
||||
Exists: true,
|
||||
FullName: name,
|
||||
FullName: util.CanonicalToDisplay(name),
|
||||
}
|
||||
path, ok := s.paths[name]
|
||||
// This hypha does not exist yet
|
||||
|
@ -29,7 +29,7 @@ func HyphaEdit(h *fs.Hypha) []byte { //
|
||||
|
||||
// HyphaUpdateOk is used to inform that update was successful.
|
||||
func HyphaUpdateOk(h *fs.Hypha) []byte { //
|
||||
return layout("updateOk").
|
||||
return layout("update_ok").
|
||||
withMap(map[string]string{"Name": h.FullName}).
|
||||
Bytes()
|
||||
}
|
||||
@ -56,6 +56,9 @@ func hyphaGeneric(name, content, templateName string) []byte {
|
||||
|
||||
// wrapInBase is used to wrap layouts in things that are present on all pages.
|
||||
func (lyt *Layout) wrapInBase(keys map[string]string) []byte {
|
||||
if lyt.invalid {
|
||||
return lyt.Bytes()
|
||||
}
|
||||
page := map[string]string{
|
||||
"Title": cfg.SiteTitle,
|
||||
"Main": "",
|
||||
|
33
util/util.go
Normal file
@ -0,0 +1,33 @@
|
||||
package util
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"unicode"
|
||||
)
|
||||
|
||||
func UrlToCanonical(name string) string {
|
||||
return strings.ToLower(strings.ReplaceAll(name, " ", "_"))
|
||||
}
|
||||
|
||||
func DisplayToCanonical(name string) string {
|
||||
return strings.ToLower(strings.ReplaceAll(name, " ", "_"))
|
||||
}
|
||||
|
||||
func CanonicalToDisplay(name string) (res string) {
|
||||
tmp := strings.Title(name)
|
||||
var afterPoint bool
|
||||
for _, ch := range tmp {
|
||||
if afterPoint {
|
||||
afterPoint = false
|
||||
ch = unicode.ToLower(ch)
|
||||
}
|
||||
switch ch {
|
||||
case '.':
|
||||
afterPoint = true
|
||||
case '_':
|
||||
ch = ' '
|
||||
}
|
||||
res += string(ch)
|
||||
}
|
||||
return res
|
||||
}
|
@ -1,11 +0,0 @@
|
||||
<div class="naviwrapper">
|
||||
<form class="naviwrapper__edit edit-box"
|
||||
method="POST"
|
||||
enctype="multipart/form-data"
|
||||
action="?action=update">
|
||||
<h4>Edit box</h4>
|
||||
<!-- It is important that there is no indent ↓ -->
|
||||
<textarea class="edit-box__text" name="text">
|
||||
{{ .Text }}</textarea>
|
||||
</form>
|
||||
</div>
|
@ -1,21 +0,0 @@
|
||||
<div style=""><h4>Text MIME-type</h4>
|
||||
<p>Good types are <code>text/markdown</code> and <code>text/plain</code></p>
|
||||
<input type="text" name="text_mime" value="{{ .TextMime }}" form="edit-form"/>
|
||||
|
||||
<h4>Revision comment</h4>
|
||||
<p>Please make your comment helpful</p>
|
||||
<input type="text" name="comment" value="Update {{ .Name }}" form="edit-form"/>
|
||||
|
||||
<h4>Edit tags</h4>
|
||||
<p>Tags are separated by commas, whitespace is ignored</p>
|
||||
<input type="text" name="tags" value="{{ .Tags }}" form="edit-form"/>
|
||||
|
||||
<h4>Upload file</h4>
|
||||
<p>If this hypha has a file like that, the text above is meant to be a description of it</p>
|
||||
<input type="file" name="binary" form="edit-form"/>
|
||||
|
||||
<p>
|
||||
<input type="submit" value="update" form="edit-form"/>
|
||||
<a href="?">Cancel</a>
|
||||
</p>
|
||||
</div>
|
Before Width: | Height: | Size: 43 KiB After Width: | Height: | Size: 43 KiB |
Before Width: | Height: | Size: 34 KiB After Width: | Height: | Size: 34 KiB |
Before Width: | Height: | Size: 427 KiB After Width: | Height: | Size: 427 KiB |
Before Width: | Height: | Size: 608 KiB After Width: | Height: | Size: 608 KiB |
1
w/m/help/1.markdown
Normal file
@ -0,0 +1 @@
|
||||
# Help
|
21
w/m/help/meta.json
Normal file
@ -0,0 +1,21 @@
|
||||
{
|
||||
"views": 0,
|
||||
"deleted": false,
|
||||
"revisions": {
|
||||
"1": {
|
||||
"tags": [
|
||||
""
|
||||
],
|
||||
"name": "Help",
|
||||
"comment": "Update Help",
|
||||
"author": "",
|
||||
"time": 1593540573,
|
||||
"text_mime": "text/markdown",
|
||||
"binary_mime": "",
|
||||
"text_name": "1.markdown",
|
||||
"binary_name": ""
|
||||
}
|
||||
},
|
||||
"Invalid": false,
|
||||
"Err": null
|
||||
}
|
11
w/m/templates/default-light/edit/index.html/1.html
Normal file
@ -0,0 +1,11 @@
|
||||
<form class="edit-box"
|
||||
method="POST"
|
||||
enctype="multipart/form-data"
|
||||
action="?action=update"
|
||||
id="edit-form">
|
||||
<h4>Edit box</h4>
|
||||
<!-- It is important that there is no indent ↓ -->
|
||||
<textarea class="edit-box__text" name="text">
|
||||
{{ .Text }}</textarea>
|
||||
</form>
|
||||
|
22
w/m/templates/default-light/edit/sidebar.html/1.html
Normal file
@ -0,0 +1,22 @@
|
||||
<div>
|
||||
<h4>Text MIME-type</h4>
|
||||
<p>Good types are <code>text/markdown</code> and <code>text/plain</code></p>
|
||||
<input type="text" name="text_mime" value="{{ .TextMime }}" form="edit-form"/>
|
||||
|
||||
<h4>Revision comment</h4>
|
||||
<p>Please make your comment helpful</p>
|
||||
<input type="text" name="comment" value="Update {{ .Name }}" form="edit-form"/>
|
||||
|
||||
<h4>Edit tags</h4>
|
||||
<p>Tags are separated by commas, whitespace is ignored</p>
|
||||
<input type="text" name="tags" value="{{ .Tags }}" form="edit-form"/>
|
||||
|
||||
<h4>Upload file</h4>
|
||||
<p>If this hypha has a file like that, the text above is meant to be a description of it</p>
|
||||
<input type="file" name="binary" form="edit-form"/>
|
||||
|
||||
<p>
|
||||
<input type="submit" value="update" form="edit-form"/>
|
||||
<a href="?">Cancel</a>
|
||||
</p>
|
||||
</div>
|
@ -4,7 +4,7 @@
|
||||
"revisions": {
|
||||
"1": {
|
||||
"tags": null,
|
||||
"name": "updateOk.html",
|
||||
"name": "update_ok.html",
|
||||
"comment": "Create Templates/default-light/updateOk.html",
|
||||
"author": "",
|
||||
"time": 1592996644,
|
@ -1,7 +1,7 @@
|
||||
<div class="hypha-actions">
|
||||
<ul>
|
||||
<li><a href="?action=edit">Edit</a></li>
|
||||
<li><a href="?action=getBinary">Download</a></li>
|
||||
<li><a href="?action=binary">Download</a></li>
|
||||
<li><a href="?action=zen">Zen mode</a></li>
|
||||
<li><a href="?action=raw">View raw</a></li>
|
||||
</ul>
|