From d7904bcba22a504206ba9598fc2b5b6720125f41 Mon Sep 17 00:00:00 2001 From: Brian Buller Date: Thu, 8 Dec 2022 11:40:53 -0600 Subject: [PATCH] Add Repo & Notes fields --- project.go | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/project.go b/project.go index e8ac502..5328a23 100644 --- a/project.go +++ b/project.go @@ -11,6 +11,8 @@ type Project struct { Original string // Original raw project text Name string // The name of the project Directory string // The directory part of the project text + Notes string // The filename of the notes file, defaults to Directory+/+notes.md + Repo string // The directory to the git repository, defaults to Directory+/+Name Contexts []string ProjectTags []string AdditionalTags map[string]string @@ -36,10 +38,26 @@ func ParseProject(text string) (*Project, error) { } project.Name = strings.TrimSpace(project.Name) parts = parts[pIdx:] + var notesAbs, repoAbs bool + project.Notes = "notes.md" + project.Repo = project.Name for _, v := range parts { switch v[0] { case '^': // Project Directory project.Directory = v[1:] + if strings.HasSuffix(project.Directory, "/") { + project.Directory = strings.TrimSuffix(project.Directory, "/") + } + case '~': // Project Repo + project.Repo = v[1:] + if strings.HasPrefix(project.Repo, "/") { + repoAbs = true + } + case '#': + project.Notes = v[1:] + if strings.HasPrefix(project.Notes, "/") { + notesAbs = true + } case '@': // Contexts project.Contexts = append(project.Contexts, v[1:]) case '+': // ProjectTags @@ -54,6 +72,12 @@ func ParseProject(text string) (*Project, error) { } } } + if !notesAbs { + project.Notes = fmt.Sprintf("%s/%s", project.Directory, project.Notes) + } + if !repoAbs { + project.Repo = fmt.Sprintf("%s/%s", project.Directory, project.Repo) + } return &project, err }