diff --git a/README.md b/README.md index bc3d1e73..3a6ec971 100644 --- a/README.md +++ b/README.md @@ -30,15 +30,16 @@ Confluence instance and update it accordingly. File in extended format should follow specification ```markdown -[]:# (X-Space: ) -[]:# (X-Parent: ) -[]:# (X-Parent: ) -[]:# (X-Title: ) +[]:# (Space: <space key>) +[]:# (Parent: <parent 1>) +[]:# (Parent: <parent 2>) +[]:# (Title: <title>) +[]:# (Rename: <title>) <page contents> ``` -There can be any number of 'X-Parent' headers, if mark can't find specified +There can be any number of 'Parent' headers, if mark can't find specified parent by title, it will be created. ## Usage: diff --git a/main.go b/main.go index c48410dc..8649437d 100644 --- a/main.go +++ b/main.go @@ -5,7 +5,7 @@ import ( "bytes" "fmt" "io/ioutil" - "net/url" + netURL "net/url" "os" "path/filepath" "regexp" @@ -112,6 +112,7 @@ const ( HeaderSpace = `Space` HeaderTitle = `Title` HeaderLayout = `Layout` + HeaderRename = `Rename` ) type Meta struct { @@ -119,6 +120,7 @@ type Meta struct { Space string Title string Layout string + Rename string } var ( @@ -237,7 +239,7 @@ func main() { } } - url, err := url.Parse(targetURL) + url, err := netURL.Parse(targetURL) if err != nil { logger.Fatal(err) } @@ -285,7 +287,26 @@ func main() { var target *PageInfo - if meta != nil { + var rename *PageInfo + + if meta.Rename != "" { + rename, _ = api.findPage(meta.Space, meta.Rename) + } + + if rename != nil && meta.Title != "" { + page, err := api.getPageByID(rename.ID) + if err != nil { + logger.Fatal(err) + } + page.Links.Full = strings.Replace( + page.Links.Full, + netURL.QueryEscape(page.Title), + netURL.QueryEscape(meta.Title), 1, + ) + page.Title = meta.Title + + target = page + } else if meta != nil { page, err := resolvePage(api, meta) if err != nil { logger.Fatal(err) @@ -628,6 +649,9 @@ func extractMeta(data []byte) (*Meta, error) { case HeaderLayout: meta.Layout = strings.TrimSpace(matches[2]) + case HeaderRename: + meta.Rename = strings.TrimSpace(matches[2]) + default: logger.Errorf( `encountered unknown header '%s' line: %#v`,