diff --git a/README.md b/README.md index 7a7d6d8..d96bdff 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,6 @@ # mycorrhiza wiki -Simple wiki engine inspired by fungi. +A wiki engine inspired by fungi. + +Current version: 0.5. + +Not production-ready. diff --git a/cfg/config.go b/cfg/config.go index f5e6251..0a40da1 100644 --- a/cfg/config.go +++ b/cfg/config.go @@ -8,17 +8,23 @@ import ( "path/filepath" ) +type MyceliumConfig struct { + Names []string `json:"names"` + Type string `json:"type"` +} + const ( HyphaPattern = `[^\s\d:/?&\\][^:?&\\]*` HyphaUrl = `/{hypha:` + HyphaPattern + `}` RevisionPattern = `[\d]+` RevQuery = `{rev:` + RevisionPattern + `}` + MyceliumPattern = `[^\s\d:/?&\\][^:?&\\/]*` + MyceliumUrl = `/:{mycelium:` + MyceliumPattern + `}` ) var ( DescribeHyphaHerePattern = "Describe %s here" WikiDir string - TemplatesDir string configJsonPath string // Default values that can be overriden in config.json @@ -28,22 +34,23 @@ var ( GenericErrorMsg = `Sorry, something went wrong` SiteTitle = `MycorrhizaWiki` Theme = `default-light` + Mycelia = []MyceliumConfig{ + {[]string{"main"}, "main"}, + {[]string{"sys", "system"}, "system"}, + } ) func InitConfig(wd string) bool { log.Println("WikiDir is", wd) WikiDir = wd - TemplatesDir = "Templates" - configJsonPath = filepath.Join(filepath.Dir(WikiDir), "config.json") + configJsonPath = filepath.Join(WikiDir, "config.json") 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 { @@ -54,9 +61,10 @@ func readConfig() bool { } cfg := struct { - Address string `json:"address"` - Theme string `json:"theme"` - SiteTitle string `json:"site-title"` + Address string `json:"address"` + Theme string `json:"theme"` + SiteTitle string `json:"site-title"` + Mycelia []MyceliumConfig `json:"mycelia"` TitleTemplates struct { EditHypha string `json:"edit-hypha"` ViewHypha string `json:"view-hypha"` @@ -74,6 +82,7 @@ func readConfig() bool { SiteTitle = cfg.SiteTitle TitleEditTemplate = cfg.TitleTemplates.EditHypha TitleTemplate = cfg.TitleTemplates.ViewHypha + Mycelia = cfg.Mycelia return true } diff --git a/fs/data.go b/fs/data.go index 0eb142d..58b7264 100644 --- a/fs/data.go +++ b/fs/data.go @@ -10,14 +10,19 @@ import ( "strings" "github.com/bouncepaw/mycorrhiza/cfg" + "github.com/bouncepaw/mycorrhiza/util" ) func (h *Hypha) MetaJsonPath() string { return filepath.Join(h.Path(), "meta.json") } +func (h *Hypha) CanonicalName() string { + return util.UrlToCanonical(h.FullName) +} + func (h *Hypha) Path() string { - return filepath.Join(cfg.WikiDir, h.FullName) + return filepath.Join(cfg.WikiDir, h.CanonicalName()) } func (h *Hypha) TextPath() string { @@ -25,7 +30,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. diff --git a/fs/fs.go b/fs/fs.go index b10dc74..3d1488a 100644 --- a/fs/fs.go +++ b/fs/fs.go @@ -54,6 +54,3 @@ func (s *Storage) indexHyphae(path string) { } } } - -func (h *Hypha) Close() { -} diff --git a/fs/genealogy.go b/fs/genealogy.go index 1bc3adb..5d63c37 100644 --- a/fs/genealogy.go +++ b/fs/genealogy.go @@ -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 += `