Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Content-Appearance header #258

Merged
merged 1 commit into from
Mar 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,13 @@ Also, optional following headers are supported:
* (default) page: normal Confluence page - defaults to this if omitted
* blogpost: [Blog post](https://confluence.atlassian.com/doc/blog-posts-834222533.html) in `Space`. Cannot have `Parent`(s)

```markdown
<!-- Content-Appearance: (full-width|fixed) -->
```

* (default) full-width: content will fill the full page width
* fixed: content will be rendered in a fixed narrow view

```markdown
<!-- Sidebar: <h2>Test</h2> -->
```
Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ func processFile(
html = buffer.String()
}

err = api.UpdatePage(target, html, flags.MinorEdit, meta.Labels)
err = api.UpdatePage(target, html, flags.MinorEdit, meta.Labels, meta.ContentAppearance)
if err != nil {
log.Fatal(err)
}
Expand Down
6 changes: 2 additions & 4 deletions pkg/confluence/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -514,9 +514,7 @@ func (api *API) CreatePage(
return request.Response.(*PageInfo), nil
}

func (api *API) UpdatePage(
page *PageInfo, newContent string, minorEdit bool, newLabels []string,
) error {
func (api *API) UpdatePage(page *PageInfo, newContent string, minorEdit bool, newLabels []string, appearance string) error {
nextPageVersion := page.Version.Number + 1
oldAncestors := []map[string]interface{}{}

Expand Down Expand Up @@ -560,7 +558,7 @@ func (api *API) UpdatePage(
//
"properties": map[string]interface{}{
"content-appearance-published": map[string]interface{}{
"value": "full-width",
"value": appearance,
},
},
// content-appearance-draft should not be set as this is impacted by
Expand Down
51 changes: 33 additions & 18 deletions pkg/mark/meta.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,28 +11,35 @@ import (
)

const (
HeaderParent = `Parent`
HeaderSpace = `Space`
HeaderType = `Type`
HeaderTitle = `Title`
HeaderLayout = `Layout`
HeaderAttachment = `Attachment`
HeaderLabel = `Label`
HeaderInclude = `Include`
HeaderSidebar = `Sidebar`
HeaderParent = `Parent`
HeaderSpace = `Space`
HeaderType = `Type`
HeaderTitle = `Title`
HeaderLayout = `Layout`
HeaderAttachment = `Attachment`
HeaderLabel = `Label`
HeaderInclude = `Include`
HeaderSidebar = `Sidebar`
ContentAppearance = `Content-Appearance`
)

type Meta struct {
Parents []string
Space string
Type string
Title string
Layout string
Sidebar string
Attachments []string
Labels []string
Parents []string
Space string
Type string
Title string
Layout string
Sidebar string
Attachments []string
Labels []string
ContentAppearance string
}

const (
FullWidthContentAppearance = "full-width"
FixedContentAppearance = "fixed"
)

var (
reHeaderPatternV1 = regexp.MustCompile(`\[\]:\s*#\s*\(([^:]+):\s*(.*)\)`)
reHeaderPatternV2 = regexp.MustCompile(`<!--\s*([^:]+):\s*(.*)\s*-->`)
Expand Down Expand Up @@ -78,7 +85,8 @@ func ExtractMeta(data []byte) (*Meta, []byte, error) {

if meta == nil {
meta = &Meta{}
meta.Type = "page" //Default if not specified
meta.Type = "page" // Default if not specified
meta.ContentAppearance = FullWidthContentAppearance // Default to full-width for backwards compatibility
}

//nolint:staticcheck
Expand Down Expand Up @@ -119,6 +127,13 @@ func ExtractMeta(data []byte) (*Meta, []byte, error) {
// Includes are parsed by a different func
continue

case ContentAppearance:
if strings.TrimSpace(value) == FixedContentAppearance {
meta.ContentAppearance = FixedContentAppearance
} else {
meta.ContentAppearance = FullWidthContentAppearance
}

default:
log.Errorf(
nil,
Expand Down