What I am looking to accomplish is to search a page's body for a specific string using RegEx and then replace that text with an HTML link to be rendered by Confluence Cloud. I am currently doing this is in Server with custom JavaScript in the "custom header/footer" section of the admin interface but I am now faced with finding an equivalent solution for the cloud.
My imagination thinks I may be able to use the PageView event in ScriptRunner to manipulate the page body and return a new body to be rendered. I haven't seen any examples of this, is it possible?
Hi Matt,
I guess listening to the 'Page Viewed' event would be too much. I would suggest listening to the 'Page Updated' and 'Page Created' events.
Here's an example PUT request to update a page body in the Confluence cloud.
// Page ID
def id = "20873217"
def content = get("/wiki/rest/api/content/${id}").asObject(Map).body
put("/wiki/rest/api/content/${content.id}")
.header('Content-Type', 'application/json')
.body([
version: [
number: content.version.number + 1
],
title: content.title,
type: content.type,
body: [
storage: [
value: 'New Content here',
representation: 'storage'
]
]
])
.asObject(Map)
Cheers,
Helmy
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.