Skip to content

Commit

Permalink
add header for page to rename
Browse files Browse the repository at this point in the history
  • Loading branch information
brnv committed Mar 8, 2019
1 parent 4176251 commit 7cd2d9d
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 8 deletions.
11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,16 @@ Confluence instance and update it accordingly.

File in extended format should follow specification
```markdown
[]:# (X-Space: <space key>)
[]:# (X-Parent: <parent 1>)
[]:# (X-Parent: <parent 2>)
[]:# (X-Title: <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:
Expand Down
30 changes: 27 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"bytes"
"fmt"
"io/ioutil"
"net/url"
netURL "net/url"
"os"
"path/filepath"
"regexp"
Expand Down Expand Up @@ -112,13 +112,15 @@ const (
HeaderSpace = `Space`
HeaderTitle = `Title`
HeaderLayout = `Layout`
HeaderRename = `Rename`
)

type Meta struct {
Parents []string
Space string
Title string
Layout string
Rename string
}

var (
Expand Down Expand Up @@ -237,7 +239,7 @@ func main() {
}
}

url, err := url.Parse(targetURL)
url, err := netURL.Parse(targetURL)
if err != nil {
logger.Fatal(err)
}
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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`,
Expand Down

0 comments on commit 7cd2d9d

Please sign in to comment.