Skip to content

Commit

Permalink
passing parent as page id, preventing lookups
Browse files Browse the repository at this point in the history
  • Loading branch information
TheWolfNL authored and justmiles committed Jan 9, 2023
1 parent fbbe251 commit c8e94c7
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
14 changes: 10 additions & 4 deletions lib/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,16 @@ func (f *MarkdownFile) Upload(m *Markdown2Confluence) (urlPath string, err error
return urlPath, fmt.Errorf("Error checking for existing page: %s", err)
}

if len(f.Parents) > 0 {
ancestorID, err = f.FindOrCreateAncestors(m)
if err != nil {
return urlPath, err
// if ancestor was set because parent is a page id
if f.Ancestor != "" {
ancestorID = f.Ancestor
} else {
// otherwise perform lookups and create ancestors
if len(f.Parents) > 0 {
ancestorID, err = f.FindOrCreateAncestors(m)
if err != nil {
return urlPath, err
}
}
}

Expand Down
16 changes: 12 additions & 4 deletions lib/markdown.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"os"
"path/filepath"
"regexp"
"strconv"
"strings"
"sync"
"time"
Expand Down Expand Up @@ -229,9 +230,16 @@ func (m *Markdown2Confluence) Run() []error {
}

if m.Parent != "" {
parents := strings.Split(m.Parent, "/")
md.Parents = append(parents, md.Parents...)
md.Parents = deleteEmpty(md.Parents)
// If parent was passed as page id
id, _ := strconv.Atoi(m.Parent)
if id != 0 {
md.Ancestor = fmt.Sprintf("%d", id)
} else {
// Otherwise split parents
parents := strings.Split(m.Parent, "/")
md.Parents = append(parents, md.Parents...)
md.Parents = deleteEmpty(md.Parents)
}
}

markdownFiles = append(markdownFiles, md)
Expand All @@ -255,7 +263,7 @@ func (m *Markdown2Confluence) Run() []error {
for _, markdownFile := range markdownFiles {

// Create parent pages synchronously
if len(markdownFile.Parents) > 0 {
if markdownFile.Ancestor == "" && len(markdownFile.Parents) > 0 {
var err error
markdownFile.Ancestor, err = markdownFile.FindOrCreateAncestors(m)
if err != nil {
Expand Down

0 comments on commit c8e94c7

Please sign in to comment.