mirror of
https://github.com/osmarks/mycorrhiza.git
synced 2025-01-19 07:02:51 +00:00
Check for name collisions of subhyphae when renaming recursively
This commit is contained in:
parent
cbb7a02c84
commit
62ff0f0c01
@ -1,6 +1,11 @@
|
||||
# 🍄 MycorrhizaWiki 0.9
|
||||
# 🍄 MycorrhizaWiki 0.10
|
||||
A wiki engine.
|
||||
|
||||
This is the development branch for version 0.10. Features planned for this version:
|
||||
* [ ] Mycomarkup
|
||||
* [ ] CLI options
|
||||
* [ ] CSS improvements
|
||||
|
||||
## Building
|
||||
```sh
|
||||
git clone --recurse-submodules https://github.com/bouncepaw/mycorrhiza
|
||||
@ -34,4 +39,3 @@ Help is always needed. We have a [tg chat](https://t.me/mycorrhizadev) where som
|
||||
* Tagging system
|
||||
* Authorization
|
||||
* Better history viewing
|
||||
* More markups
|
||||
|
19
hypha.go
19
hypha.go
@ -61,10 +61,13 @@ func findHyphaeToRename(hyphaName string, recursive bool) []string {
|
||||
return hyphae
|
||||
}
|
||||
|
||||
func renamingPairs(hyphaNames []string, replaceName func(string) string) map[string]string {
|
||||
func renamingPairs(hyphaNames []string, replaceName func(string) string) (map[string]string, error) {
|
||||
renameMap := make(map[string]string)
|
||||
for _, hn := range hyphaNames {
|
||||
if hd, ok := HyphaStorage[hn]; ok {
|
||||
if _, nameUsed := HyphaStorage[replaceName(hn)]; nameUsed {
|
||||
return nil, errors.New("Hypha " + replaceName(hn) + " already exists")
|
||||
}
|
||||
if hd.textPath != "" {
|
||||
renameMap[hd.textPath] = replaceName(hd.textPath)
|
||||
}
|
||||
@ -73,7 +76,7 @@ func renamingPairs(hyphaNames []string, replaceName func(string) string) map[str
|
||||
}
|
||||
}
|
||||
}
|
||||
return renameMap
|
||||
return renameMap, nil
|
||||
}
|
||||
|
||||
// word Data is plural here
|
||||
@ -94,11 +97,15 @@ func (hd *HyphaData) RenameHypha(hyphaName, newName string, recursive bool) *his
|
||||
replaceName = func(str string) string {
|
||||
return strings.Replace(str, hyphaName, newName, 1)
|
||||
}
|
||||
hyphaNames = findHyphaeToRename(hyphaName, recursive)
|
||||
renameMap = renamingPairs(hyphaNames, replaceName)
|
||||
renameMsg = "Rename ‘%s’ to ‘%s’"
|
||||
hop = history.Operation(history.TypeRenameHypha)
|
||||
hyphaNames = findHyphaeToRename(hyphaName, recursive)
|
||||
renameMap, err = renamingPairs(hyphaNames, replaceName)
|
||||
renameMsg = "Rename ‘%s’ to ‘%s’"
|
||||
hop = history.Operation(history.TypeRenameHypha)
|
||||
)
|
||||
if err != nil {
|
||||
hop.Errs = append(hop.Errs, err)
|
||||
return hop
|
||||
}
|
||||
if recursive {
|
||||
renameMsg += " recursively"
|
||||
}
|
||||
|
2
main.go
2
main.go
@ -40,7 +40,7 @@ func HttpErr(w http.ResponseWriter, status int, name, title, errMsg string) {
|
||||
w.Header().Set("Content-Type", "text/html;charset=utf-8")
|
||||
w.WriteHeader(status)
|
||||
fmt.Fprint(w, base(title, fmt.Sprintf(
|
||||
`<p>%s. <a href="/page/%s">Go back to the hypha.<a></p>`,
|
||||
`<main><p>%s. <a href="/page/%s">Go back to the hypha.<a></p></main>`,
|
||||
errMsg, name)))
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user