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 bcd14b7
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 10 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>)
[]:# (ID: <id>)

<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
28 changes: 23 additions & 5 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,13 +112,15 @@ const (
HeaderSpace = `Space`
HeaderTitle = `Title`
HeaderLayout = `Layout`
HeaderID = `ID`
)

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

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

url, err := url.Parse(targetURL)
urlParsed, err := url.Parse(targetURL)
if err != nil {
logger.Fatal(err)
}

baseURL := url.Scheme + "://" + url.Host
baseURL := urlParsed.Scheme + "://" + urlParsed.Host

if url.Host == "" {
if urlParsed.Host == "" {
baseURL, err = config.GetString("base_url")
if err != nil {
if zhash.IsNotFound(err) {
Expand All @@ -264,7 +266,7 @@ func main() {

api := NewAPI(baseURL, username, password)

pageID := url.Query().Get("pageId")
pageID := urlParsed.Query().Get("pageId")

if pageID != "" && meta != nil {
logger.Warningf(
Expand All @@ -285,7 +287,20 @@ func main() {

var target *PageInfo

if meta != nil {
if meta.ID != "" && meta.Title != "" {
page, err := api.getPageByID(meta.ID)
if err != nil {
logger.Fatal(err)
}
page.Links.Full = strings.Replace(
page.Links.Full,
url.QueryEscape(page.Title),
url.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 +643,9 @@ func extractMeta(data []byte) (*Meta, error) {
case HeaderLayout:
meta.Layout = strings.TrimSpace(matches[2])

case HeaderID:
meta.ID = strings.TrimSpace(matches[2])

default:
logger.Errorf(
`encountered unknown header '%s' line: %#v`,
Expand Down

0 comments on commit bcd14b7

Please sign in to comment.