{%s= lc.Get("ui.diff_title", &l18n.Replacements{"name": beautifulLink(h.Name), "rev": hash}) %}
+{%s= lc.Get("ui.diff_title", &l18n.Replacements{"name": beautifulLink(h.CanonicalName()), "rev": hash}) %}
{%s text %}
diff --git a/hyphae/backlinks/backlinks.go b/hyphae/backlinks/backlinks.go index 9f0ca7a..3390bf7 100644 --- a/hyphae/backlinks/backlinks.go +++ b/hyphae/backlinks/backlinks.go @@ -53,9 +53,9 @@ func IndexBacklinks() { } // BacklinksCount returns the amount of backlinks to the hypha. -func BacklinksCount(h *hyphae.Hypha) int { - if _, exists := backlinkIndex[h.Name]; exists { - return len(backlinkIndex[h.Name]) +func BacklinksCount(h hyphae.Hypher) int { + if links, exists := backlinkIndex[h.CanonicalName()]; exists { + return len(links) } return 0 } diff --git a/hyphae/backlinks/hooks.go b/hyphae/backlinks/hooks.go index eb3fa77..b5e8a39 100644 --- a/hyphae/backlinks/hooks.go +++ b/hyphae/backlinks/hooks.go @@ -9,27 +9,27 @@ import ( ) // UpdateBacklinksAfterEdit is a creation/editing hook for backlinks index -func UpdateBacklinksAfterEdit(h *hyphae.Hypha, oldText string) { - oldLinks := extractHyphaLinksFromContent(h.Name, oldText) +func UpdateBacklinksAfterEdit(h hyphae.Hypher, oldText string) { + oldLinks := extractHyphaLinksFromContent(h.CanonicalName(), oldText) newLinks := extractHyphaLinks(h) - backlinkConveyor <- backlinkIndexEdit{h.Name, oldLinks, newLinks} + backlinkConveyor <- backlinkIndexEdit{h.CanonicalName(), oldLinks, newLinks} } // UpdateBacklinksAfterDelete is a deletion hook for backlinks index -func UpdateBacklinksAfterDelete(h *hyphae.Hypha, oldText string) { - oldLinks := extractHyphaLinksFromContent(h.Name, oldText) - backlinkConveyor <- backlinkIndexDeletion{h.Name, oldLinks} +func UpdateBacklinksAfterDelete(h hyphae.Hypher, oldText string) { + oldLinks := extractHyphaLinksFromContent(h.CanonicalName(), oldText) + backlinkConveyor <- backlinkIndexDeletion{h.CanonicalName(), oldLinks} } // UpdateBacklinksAfterRename is a renaming hook for backlinks index -func UpdateBacklinksAfterRename(h *hyphae.Hypha, oldName string) { +func UpdateBacklinksAfterRename(h hyphae.Hypher, oldName string) { actualLinks := extractHyphaLinks(h) - backlinkConveyor <- backlinkIndexRenaming{oldName, h.Name, actualLinks} + backlinkConveyor <- backlinkIndexRenaming{oldName, h.CanonicalName(), actualLinks} } // extractHyphaLinks extracts hypha links from a desired hypha -func extractHyphaLinks(h *hyphae.Hypha) []string { - return extractHyphaLinksFromContent(h.Name, fetchText(h)) +func extractHyphaLinks(h hyphae.Hypher) []string { + return extractHyphaLinksFromContent(h.CanonicalName(), fetchText(h)) } // extractHyphaLinksFromContent extracts local hypha links from the provided text. diff --git a/hyphae/files.go b/hyphae/files.go index 131d5ac..55e7f7e 100644 --- a/hyphae/files.go +++ b/hyphae/files.go @@ -20,7 +20,7 @@ func Index(path string) { for h := range ch { // It's safe to ignore the mutex because there is a single worker right now. - if oh := ByName(h.Name); oh.Exists { + if oh := ByName(h.name); oh.Exists { oh.mergeIn(h) } else { h.insert() @@ -51,7 +51,7 @@ func indexHelper(path string, nestLevel uint, ch chan *Hypha) { var ( hyphaPartPath = filepath.Join(path, node.Name()) hyphaName, isText, skip = mimetype.DataFromFilename(hyphaPartPath) - hypha = &Hypha{Name: hyphaName, Exists: true} + hypha = &Hypha{name: hyphaName, Exists: true} ) if !skip { if isText { diff --git a/hyphae/hyphae.go b/hyphae/hyphae.go index f1a8d74..1d95c2c 100644 --- a/hyphae/hyphae.go +++ b/hyphae/hyphae.go @@ -31,17 +31,19 @@ func IsValidName(hyphaName string) bool { type Hypha struct { sync.RWMutex - Name string // Canonical name + name string // Canonical name Exists bool TextPath string // == "" => no text part binaryPath string // == "" => no attachment } +func (h *Hypha) SetName(s string) { h.name = s } + func (h *Hypha) BinaryPath() string { return h.binaryPath } func (h *Hypha) SetBinaryPath(s string) { h.binaryPath = s } func (h *Hypha) CanonicalName() string { - return h.Name + return h.name } func (h *Hypha) Kind() HyphaKind { @@ -65,7 +67,7 @@ func (h *Hypha) HasTextPart() bool { // TextPartPath returns rooted path to the file where the text part should be. func (h *Hypha) TextPartPath() string { if h.TextPath == "" { - return filepath.Join(files.HyphaeDir(), h.Name+".myco") + return filepath.Join(files.HyphaeDir(), h.name+".myco") } return h.TextPath } @@ -81,7 +83,7 @@ var byNamesMutex = sync.Mutex{} // EmptyHypha returns an empty hypha struct with given name. func EmptyHypha(hyphaName string) *Hypha { return &Hypha{ - Name: hyphaName, + name: hyphaName, Exists: false, TextPath: "", binaryPath: "", @@ -99,7 +101,7 @@ func ByName(hyphaName string) (h *Hypha) { func storeHypha(h *Hypha) { byNamesMutex.Lock() - byNames[h.Name] = h + byNames[h.name] = h byNamesMutex.Unlock() h.Lock() @@ -108,8 +110,8 @@ func storeHypha(h *Hypha) { } // insert inserts the hypha into the storage. A previous record is used if possible. Count incrementation is done if needed. -func (h *Hypha) insert() (justRecorded bool) { - hp, recorded := byNames[h.Name] +func (h *Hypha) insert() (madeNewRecord bool) { + hp, recorded := byNames[h.name] if recorded { hp.mergeIn(h) } else { @@ -121,20 +123,20 @@ func (h *Hypha) insert() (justRecorded bool) { } // InsertIfNew checks whether hypha exists and returns `true` if it didn't and has been created. -func (h *Hypha) InsertIfNew() (justRecorded bool) { - if !h.Exists { - return h.insert() +func (h *Hypha) InsertIfNew() (madeNewRecord bool) { + if h.DoesExist() { + return false } - return false + return h.insert() } // RenameTo renames a hypha and performs respective changes in the storage. func (h *Hypha) RenameTo(newName string) { byNamesMutex.Lock() h.Lock() - delete(byNames, h.Name) - h.Name = newName - byNames[h.Name] = h + delete(byNames, h.CanonicalName()) + h.SetName(newName) + byNames[h.CanonicalName()] = h byNamesMutex.Unlock() h.Unlock() } diff --git a/shroom/delete.go b/shroom/delete.go index ecf4939..98c3de8 100644 --- a/shroom/delete.go +++ b/shroom/delete.go @@ -22,7 +22,7 @@ func DeleteHypha(u *user.User, h *hyphae.Hypha, lc *l18n.Localizer) (hop *histor originalText, _ := FetchTextPart(h) hop. WithFilesRemoved(h.TextPath, h.BinaryPath()). - WithMsg(fmt.Sprintf("Delete ‘%s’", h.Name)). + WithMsg(fmt.Sprintf("Delete ‘%s’", h.CanonicalName())). WithUser(u). Apply() if !hop.HasErrors() { diff --git a/shroom/unattach.go b/shroom/unattach.go index fcc09ab..9d71b8c 100644 --- a/shroom/unattach.go +++ b/shroom/unattach.go @@ -20,7 +20,7 @@ func UnattachHypha(u *user.User, h *hyphae.Hypha, lc *l18n.Localizer) (hop *hist hop. WithFilesRemoved(h.BinaryPath()). - WithMsg(fmt.Sprintf("Unattach ‘%s’", h.Name)). + WithMsg(fmt.Sprintf("Unattach ‘%s’", h.CanonicalName())). WithUser(u). Apply() diff --git a/shroom/upload.go b/shroom/upload.go index 41d6b79..6ffdd3a 100644 --- a/shroom/upload.go +++ b/shroom/upload.go @@ -31,9 +31,9 @@ func UploadText(h *hyphae.Hypha, data []byte, message string, u *user.User, lc * } if message == "" { - hop.WithMsg(fmt.Sprintf("%s ‘%s’", action, h.Name)) + hop.WithMsg(fmt.Sprintf("%s ‘%s’", action, h.CanonicalName())) } else { - hop.WithMsg(fmt.Sprintf("%s ‘%s’: %s", action, h.Name, message)) + hop.WithMsg(fmt.Sprintf("%s ‘%s’: %s", action, h.CanonicalName(), message)) } if errtitle, err := CanEdit(u, h, lc); err != nil { @@ -49,7 +49,7 @@ func UploadText(h *hyphae.Hypha, data []byte, message string, u *user.User, lc * // UploadBinary edits a hypha' attachment and makes a history record about that. func UploadBinary(h *hyphae.Hypha, mime string, file multipart.File, u *user.User, lc *l18n.Localizer) (*history.Op, string) { var ( - hop = history.Operation(history.TypeEditBinary).WithMsg(fmt.Sprintf("Upload attachment for ‘%s’ with type ‘%s’", h.Name, mime)) + hop = history.Operation(history.TypeEditBinary).WithMsg(fmt.Sprintf("Upload attachment for ‘%s’ with type ‘%s’", h.CanonicalName(), mime)) data, err = io.ReadAll(file) ) @@ -69,11 +69,11 @@ func UploadBinary(h *hyphae.Hypha, mime string, file multipart.File, u *user.Use // uploadHelp is a helper function for UploadText and UploadBinary func uploadHelp(h *hyphae.Hypha, hop *history.Op, ext string, data []byte, u *user.User) (*history.Op, string) { var ( - fullPath = filepath.Join(files.HyphaeDir(), h.Name+ext) + fullPath = filepath.Join(files.HyphaeDir(), h.CanonicalName()+ext) sourceFullPath = h.TextPartPath() originalText = "" // for backlink update ) - if !isValidPath(fullPath) || !hyphae.IsValidName(h.Name) { + if !isValidPath(fullPath) || !hyphae.IsValidName(h.CanonicalName()) { err := errors.New("bad path") return hop.WithErrAbort(err), err.Error() } diff --git a/views/history.qtpl b/views/history.qtpl index 2c5b162..b02ccbc 100644 --- a/views/history.qtpl +++ b/views/history.qtpl @@ -20,7 +20,7 @@ if err != nil {
{%s text %}
`)
diff --git a/views/hypha.qtpl b/views/hypha.qtpl
index 265e513..350ca03 100644
--- a/views/hypha.qtpl
+++ b/views/hypha.qtpl
@@ -27,13 +27,13 @@
📝 {%s lc.Get("ui.notexist_write") %}
{%s= lc.Get("ui.notexist_write_tip1", &l18n.Replacements{"myco": mycoLink(lc)}) %}
{%s lc.Get("ui.notexist_write_tip2") %}
- {%s lc.Get("ui.notexist_write_button") %}
+ {%s lc.Get("ui.notexist_write_button") %}
🖼 {%s lc.Get("ui.notexist_media") %}
{%s lc.Get("ui.notexist_media_tip1") %}
-