5
5
"fmt"
6
6
"net/http"
7
7
"net/url"
8
+ "strings"
8
9
"time"
9
10
)
10
11
@@ -54,7 +55,7 @@ func (cli *Client) ContentBySpaceAndTitle(space, title string) (Content, error)
54
55
q := url.Values {
55
56
"title" : {title },
56
57
"spaceKey" : {space },
57
- "expand" : {"version" },
58
+ "expand" : {"version,body.storage " },
58
59
}
59
60
60
61
resp , err := cli .ApiGET ("/content" , q )
@@ -158,6 +159,10 @@ func (cli *Client) ContentUpdate(content Content) (Content, error) {
158
159
159
160
//从指定空间查找或创建指定标题的内容
160
161
func (cli * Client ) PageFindOrCreateBySpaceAndTitle (space , parentId , title , data string ) (Content , error ) {
162
+ //内容中的空行会被Confluence保存时自动去掉
163
+ //因此前先去掉,以避免对比内容变化时受到影响
164
+ data = strings .TrimSuffix (strings .TrimPrefix (data , "\n " ), "\n " )
165
+
161
166
content , err := cli .ContentBySpaceAndTitle (space , title )
162
167
if err != nil {
163
168
return Content {}, fmt .Errorf ("查找%s出错: %s" , title , err )
@@ -168,8 +173,18 @@ func (cli *Client) PageFindOrCreateBySpaceAndTitle(space, parentId, title, data
168
173
return cli .PageCreateInSpace (space , parentId , title , data )
169
174
}
170
175
171
- //存在但内容未变化,直接跳过
172
- if data != content .Body .Storage .Value {
176
+ //存在:对比内容是否有变化
177
+ newValue , err := cli .ContentBodyConvertTo (data , "storage" , "view" )
178
+ if err != nil {
179
+ return Content {}, fmt .Errorf ("转换新内容失败: %s" , err )
180
+ }
181
+
182
+ oldValue , err := cli .ContentBodyConvertTo (content .Body .Storage .Value , "storage" , "view" )
183
+ if err != nil {
184
+ return Content {}, fmt .Errorf ("转换旧内容失败: %s" , err )
185
+ }
186
+
187
+ if newValue == oldValue {
173
188
return content , nil
174
189
}
175
190
0 commit comments