diff --git a/tree.go b/tree.go index a574b4f..c7469dc 100644 --- a/tree.go +++ b/tree.go @@ -37,7 +37,7 @@ type Tree struct { var readableFormats = []string{".md"} -const attachmentDirName = "__a" +const AttachmentDirName = "__a" func (t Tree) FileById(id string) (File, error) { for _, f := range t.Files { @@ -188,7 +188,7 @@ func moveAttachments(dir string) (map[string]string, error) { } var clearDir = strings.TrimPrefix(dir, "./") - if info.Mode().IsRegular() && !slices.Contains(readableFormats, path.Ext(fullPath)) && !strings.HasPrefix(fullPath, fmt.Sprintf("%s/%s", clearDir, attachmentDirName)) { + if info.Mode().IsRegular() && !slices.Contains(readableFormats, path.Ext(fullPath)) && !strings.HasPrefix(fullPath, fmt.Sprintf("%s/%s", clearDir, AttachmentDirName)) { f, err := os.Open(fullPath) if err != nil { return err @@ -200,10 +200,10 @@ func moveAttachments(dir string) (map[string]string, error) { return err } - _ = os.Mkdir(fmt.Sprintf("%s/%s", dir, attachmentDirName), 0755) + _ = os.Mkdir(fmt.Sprintf("%s/%s", dir, AttachmentDirName), 0755) - attachmentRegistry[fullPath] = fmt.Sprintf("%s/%x%s", attachmentDirName, h.Sum(nil), path.Ext(fullPath)) - newPath := fmt.Sprintf("%s/%s/%x%s", dir, attachmentDirName, h.Sum(nil), path.Ext(fullPath)) + attachmentRegistry[fullPath] = fmt.Sprintf("%s/%x%s", AttachmentDirName, h.Sum(nil), path.Ext(fullPath)) + newPath := fmt.Sprintf("%s/%s/%x%s", dir, AttachmentDirName, h.Sum(nil), path.Ext(fullPath)) err = os.Rename(fullPath, newPath) if err != nil { return err @@ -434,7 +434,7 @@ func readPath(dirPath string, category []string, meta []string) (Tree, error) { for _, file := range files { fullPath := path.Join(dirPath, file.Name()) if file.IsDir() { - if strings.HasPrefix(fullPath, fmt.Sprintf("%s/%s", clearDir, attachmentDirName)) { + if strings.HasPrefix(fullPath, fmt.Sprintf("%s/%s", clearDir, AttachmentDirName)) { continue }