Compare commits
6 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
136d9c72b6 | ||
![]() |
f3553e9dfd | ||
![]() |
85cc3f5e86 | ||
![]() |
162cb4a1bb | ||
![]() |
36ae68be6b | ||
![]() |
c3a08433de |
2
Makefile
2
Makefile
@ -7,7 +7,7 @@ venv:
|
|||||||
|
|
||||||
run_example:
|
run_example:
|
||||||
|
|
||||||
@docker build -t mkdocs-example -f ./example/Dockerfile --build-arg JIRA_PASSWORD=$(shell sops --decrypt ./example/secret.yaml | yq '.JIRA_PASSWORD' ) .
|
@docker build -t mkdocs-example -f ./example/Dockerfile --build-arg MKDOCS_TO_CONFLUENCE_PASSWORD=$(shell sops --decrypt ./example/secret.yaml | yq '.JIRA_PASSWORD' ) .
|
||||||
@docker run -p 8000:8000 mkdocs-example
|
@docker run -p 8000:8000 mkdocs-example
|
||||||
|
|
||||||
lint:
|
lint:
|
||||||
|
17
README.md
17
README.md
@ -8,7 +8,9 @@ To enable plugin, you need to set the `MKDOCS_TO_CONFLUENCE` environment variabl
|
|||||||
```BASH
|
```BASH
|
||||||
export MKDOCS_TO_CONFLUENCE=1
|
export MKDOCS_TO_CONFLUENCE=1
|
||||||
```
|
```
|
||||||
|
|
||||||
By default the dry-run mode is turned off. If you wan't to enable it, you can use the config file, ot the `MKDOCS_TO_CONFLUENCE_DRY_RUN` environment variable
|
By default the dry-run mode is turned off. If you wan't to enable it, you can use the config file, ot the `MKDOCS_TO_CONFLUENCE_DRY_RUN` environment variable
|
||||||
|
|
||||||
```BASH
|
```BASH
|
||||||
export MKDOCS_TO_CONFLUENCE_DRY_RUN=1
|
export MKDOCS_TO_CONFLUENCE_DRY_RUN=1
|
||||||
```
|
```
|
||||||
@ -16,13 +18,12 @@ export MKDOCS_TO_CONFLUENCE_DRY_RUN=1
|
|||||||
## Setup
|
## Setup
|
||||||
Install the plugin using pip:
|
Install the plugin using pip:
|
||||||
|
|
||||||
`pip install mkdocs-with-confluence`
|
`pip install https://github.com/allanger/mkdocs-with-confluence/releases/download/v0.3.1/mkdocs_with_confluence-0.3.1.tar.gz`
|
||||||
|
|
||||||
Activate the plugin in `mkdocs.yml`:
|
Activate the plugin in `mkdocs.yml`:
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
plugins:
|
plugins:
|
||||||
- search
|
|
||||||
- mkdocs-with-confluence
|
- mkdocs-with-confluence
|
||||||
```
|
```
|
||||||
|
|
||||||
@ -37,12 +38,14 @@ Use following config and adjust it according to your needs:
|
|||||||
host_url: https://<YOUR_CONFLUENCE_DOMAIN>/rest/api/content
|
host_url: https://<YOUR_CONFLUENCE_DOMAIN>/rest/api/content
|
||||||
space: <YOUR_SPACE>
|
space: <YOUR_SPACE>
|
||||||
parent_page_name: <YOUR_ROOT_PARENT_PAGE>
|
parent_page_name: <YOUR_ROOT_PARENT_PAGE>
|
||||||
username: <YOUR_USERNAME_TO_CONFLUENCE>
|
username: <YOUR_USERNAME_TO_CONFLUENCE> # JIRA_USERNAME env var can be used
|
||||||
password: <YOUR_PASSWORD_TO_CONFLUENCE>
|
password: <YOUR_PASSWORD_TO_CONFLUENCE> # JIRA_PASSWORD env var can be used
|
||||||
dryrun: true
|
dryrun: true # MKDOCS_TO_CONFLUENCE_DRY_RUN env var can be used
|
||||||
```
|
header_message: <A_MESSAGE_THAT_WILL_BE_ADDED_TO_EVERY_PAGE>
|
||||||
|
upstream_url: <URL_OF_YOUR_MKDOCS_INSTANCE>
|
||||||
|
header_warning: "‼️ This page is created automatically, all you changes will be overwritten during the next MKDocs deployment. Do not edit a page here ‼️"
|
||||||
|
|
||||||
## Parameters:
|
```
|
||||||
|
|
||||||
### Requirements
|
### Requirements
|
||||||
- md2cf
|
- md2cf
|
||||||
|
@ -9,9 +9,9 @@ RUN mkdir /out
|
|||||||
RUN mv $(find /src/dist -maxdepth 1 -mindepth 1 -name '*tar.gz') /out/mkdocs_with_confluence.tar.gz
|
RUN mv $(find /src/dist -maxdepth 1 -mindepth 1 -name '*tar.gz') /out/mkdocs_with_confluence.tar.gz
|
||||||
|
|
||||||
FROM BUILDER as common_builder
|
FROM BUILDER as common_builder
|
||||||
|
ARG MKDOCS_TO_CONFLUENCE_PASSWORD
|
||||||
ENV MKDOCS_TO_CONFLUENCE=true
|
ENV MKDOCS_TO_CONFLUENCE=true
|
||||||
ARG JIRA_PASSWORD
|
ENV MKDOCS_TO_CONFLUENCE_PASSWORD=$MKDOCS_TO_CONFLUENCE_PASSWORD
|
||||||
ENV JIRA_PASSWORD=$JIRA_PASSWORD
|
|
||||||
RUN pip install mkdocs mkdocs-material
|
RUN pip install mkdocs mkdocs-material
|
||||||
WORKDIR /src
|
WORKDIR /src
|
||||||
COPY ./example /src
|
COPY ./example /src
|
||||||
|
@ -22,6 +22,7 @@ from pathlib import Path
|
|||||||
|
|
||||||
ENABLE_ENV_VAR = "MKDOCS_TO_CONFLUENCE"
|
ENABLE_ENV_VAR = "MKDOCS_TO_CONFLUENCE"
|
||||||
DRY_RUN_ENV_VAR = "MKDOCS_TO_CONFLUENCE_DRY_RUN"
|
DRY_RUN_ENV_VAR = "MKDOCS_TO_CONFLUENCE_DRY_RUN"
|
||||||
|
|
||||||
TEMPLATE_BODY = "<p> TEMPLATE </p>"
|
TEMPLATE_BODY = "<p> TEMPLATE </p>"
|
||||||
HEADER_WARNING = "‼️ This page is created automatically, all you changes will be overwritten during the next MKDocs deployment. Do not edit a page here ‼️"
|
HEADER_WARNING = "‼️ This page is created automatically, all you changes will be overwritten during the next MKDocs deployment. Do not edit a page here ‼️"
|
||||||
SECTION_PAGE_CONTENT = "<p> It's just a Section Page </p>"
|
SECTION_PAGE_CONTENT = "<p> It's just a Section Page </p>"
|
||||||
@ -45,12 +46,13 @@ class MkdocsWithConfluence(BasePlugin):
|
|||||||
("host_url", config_options.Type(str, default=None)),
|
("host_url", config_options.Type(str, default=None)),
|
||||||
("space", config_options.Type(str, default=None)),
|
("space", config_options.Type(str, default=None)),
|
||||||
("parent_page_name", config_options.Type(str, default=None)),
|
("parent_page_name", config_options.Type(str, default=None)),
|
||||||
("username", config_options.Type(str, default=environ.get("JIRA_USERNAME", None))),
|
("username", config_options.Type(str, default=environ.get("MKDOCS_TO_CONFLUENCE_USER", None))),
|
||||||
("password", config_options.Type(str, default=environ.get("JIRA_PASSWORD", None))),
|
("password", config_options.Type(str, default=environ.get("MKDOCS_TO_CONFLUENCE_PASSWORD", None))),
|
||||||
("dryrun", config_options.Type(bool, default=False)),
|
("dryrun", config_options.Type(bool, default=False)),
|
||||||
("header_message", config_options.Type(str, default=None)),
|
("header_message", config_options.Type(str, default=None)),
|
||||||
("upstream_url", config_options.Type(str, default=None)),
|
("upstream_url", config_options.Type(str, default=None)),
|
||||||
("header_warning", config_options.Type(str, default=HEADER_WARNING)),
|
("header_warning", config_options.Type(str, default=HEADER_WARNING)),
|
||||||
|
("set_homepage", config_options.Type(bool, default=False)),
|
||||||
)
|
)
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
@ -107,94 +109,100 @@ class MkdocsWithConfluence(BasePlugin):
|
|||||||
|
|
||||||
|
|
||||||
def on_files(self, files, config):
|
def on_files(self, files, config):
|
||||||
pages = files.documentation_pages()
|
if self.enabled:
|
||||||
try:
|
pages = files.documentation_pages()
|
||||||
self.flen = len(pages)
|
try:
|
||||||
logger.debug(f"number of Files in directory tree: {self.flen}")
|
self.flen = len(pages)
|
||||||
except 0:
|
logger.debug(f"number of Files in directory tree: {self.flen}")
|
||||||
logger.error("no files found to be synced")
|
except 0:
|
||||||
|
logger.error("no files found to be synced")
|
||||||
|
|
||||||
def on_page_markdown(self, markdown, page, config, files):
|
def on_page_markdown(self, markdown, page, config, files):
|
||||||
# TODO: Modify pages here
|
if self.enabled:
|
||||||
try:
|
|
||||||
self.session.auth = (self.config["username"], self.config["password"])
|
|
||||||
confluencePageName = page.url[0:-1]
|
|
||||||
#.replace("/", "-")
|
|
||||||
if self.config["parent_page_name"] is not None:
|
|
||||||
parent_page = self.config["parent_page_name"]
|
|
||||||
else:
|
|
||||||
parent_page = self.config["space"]
|
|
||||||
page_name = ""
|
|
||||||
|
|
||||||
# TODO: Refactor
|
|
||||||
if confluencePageName.rsplit('/',1)[0]:
|
|
||||||
confluencePageName = (f"{confluencePageName.rsplit('/',1)[0]}+{page.title.replace(' ', ' ')}")
|
|
||||||
else:
|
|
||||||
confluencePageName = (f"{page.title.replace(' ', ' ')}")
|
|
||||||
# Create empty pages for sections only
|
|
||||||
logger.info("preparing emtpy pages for sections")
|
|
||||||
for path in page.url.rsplit("/", 2)[0].split("/"):
|
|
||||||
logger.debug(f"path is {path}")
|
|
||||||
parent_id = self.find_page_id(parent_page)
|
|
||||||
if path:
|
|
||||||
if page_name:
|
|
||||||
page_name = page_name + " " + path
|
|
||||||
else:
|
|
||||||
page_name = path
|
|
||||||
logger.info(f"Will create a page {page_name} under the {parent_page}")
|
|
||||||
self.add_page(page_name, parent_id, SECTION_PAGE_CONTENT)
|
|
||||||
parent_page = page_name
|
|
||||||
parent_id = self.find_page_id(parent_page)
|
|
||||||
confluencePageName = parent_page + " " + page.title
|
|
||||||
new_markdown = markdown
|
|
||||||
# -- Adding an upstream url
|
|
||||||
if self.upstream_url:
|
|
||||||
new_markdown = f">Original page is here: {self.upstream_url}/{page.url}\n\n" + new_markdown
|
|
||||||
# -- Adding a header message
|
|
||||||
if self.header_message:
|
|
||||||
new_markdown = f">{self.header_message}\n\n" + new_markdown
|
|
||||||
# -- Adding a repo url
|
|
||||||
if self.repo_url:
|
|
||||||
new_markdown = f">You can edit documentation here: {self.repo_url}\n\n" + new_markdown
|
|
||||||
# -- Adding a header warning
|
|
||||||
new_markdown = f">{self.config['header_warning']}\n\n" + new_markdown
|
|
||||||
# -------------------------------------------------
|
|
||||||
# -- Sync attachments
|
|
||||||
# -------------------------------------------------
|
|
||||||
attachments = []
|
|
||||||
# -- TODO: support named picture
|
|
||||||
md_image_reg = "(?:[!]\[(?P<caption>.*?)\])\((?P<image>.*?)\)(?P<options>\{.*\})?"
|
|
||||||
try:
|
try:
|
||||||
for match in re.finditer(md_image_reg, markdown):
|
self.session.auth = (self.config["username"], self.config["password"])
|
||||||
# -- TODO: I'm sure it can be done better
|
confluence_page_name = page.url[0:-1]
|
||||||
attachment_path = "./docs" + match.group(2)
|
#.replace("/", "-")
|
||||||
logger.info(f"found image: ./docs{match.group(2)}")
|
if self.config["parent_page_name"] is not None:
|
||||||
images = re.search(md_image_reg, new_markdown)
|
parent_page = self.config["parent_page_name"]
|
||||||
# -- TODO: Options maybe the reason why page is invalid, but I'm not sure about it yet
|
else:
|
||||||
# new_markdown = new_markdown.replace(images.group("options"), "")
|
parent_page = self.config["space"]
|
||||||
new_markdown = re.sub(md_image_reg, f"<p><ac:image><ri:attachment ri:filename=\"{os.path.basename(attachment_path)}\"/></ac:image></p>", new_markdown)
|
page_name = ""
|
||||||
attachments.append(attachment_path)
|
|
||||||
except AttributeError as e:
|
# TODO: Refactor
|
||||||
logger.warning(e)
|
if confluence_page_name.rsplit('/',1)[0]:
|
||||||
logger.debug(f"attachments: {attachments}")
|
confluence_page_name = (f"{confluence_page_name.rsplit('/',1)[0]}+{page.title.replace(' ', ' ')}")
|
||||||
confluence_body = self.confluence_mistune(new_markdown)
|
else:
|
||||||
self.add_page(confluencePageName, parent_id, confluence_body)
|
confluence_page_name = (f"{page.title.replace(' ', ' ')}")
|
||||||
if attachments:
|
# Create empty pages for sections only
|
||||||
logger.debug(f"UPLOADING ATTACHMENTS TO CONFLUENCE FOR {page.title}, DETAILS:")
|
logger.info("preparing emtpy pages for sections")
|
||||||
logger.debug(f"FILES: {attachments}")
|
for path in page.url.rsplit("/", 2)[0].split("/"):
|
||||||
for attachment in attachments:
|
logger.debug(f"path is {path}")
|
||||||
logger.debug(f"trying to upload {attachment} to {confluencePageName}")
|
parent_id = self.find_page_id(parent_page)
|
||||||
if self.enabled:
|
if path:
|
||||||
try:
|
if page_name:
|
||||||
self.add_or_update_attachment(confluencePageName, attachment)
|
page_name = page_name + " " + path
|
||||||
except Exception as Argument:
|
else:
|
||||||
logger.warning(Argument)
|
page_name = path
|
||||||
except Exception as exp:
|
logger.info(f"Will create a page {page_name} under the {parent_page}")
|
||||||
logger.error(exp)
|
self.add_page(page_name, parent_id, SECTION_PAGE_CONTENT)
|
||||||
return markdown
|
parent_page = page_name
|
||||||
|
parent_id = self.find_page_id(parent_page)
|
||||||
|
confluence_page_name = parent_page + " " + page.title
|
||||||
|
new_markdown = markdown
|
||||||
|
# -- Adding an upstream url
|
||||||
|
if self.upstream_url:
|
||||||
|
new_markdown = f">Original page is here: {self.upstream_url}/{page.url}\n\n" + new_markdown
|
||||||
|
# -- Adding a header message
|
||||||
|
if self.header_message:
|
||||||
|
new_markdown = f">{self.header_message}\n\n" + new_markdown
|
||||||
|
# -- Adding a repo url
|
||||||
|
if self.repo_url:
|
||||||
|
new_markdown = f">You can edit documentation here: {self.repo_url}\n\n" + new_markdown
|
||||||
|
# -- Adding a header warning
|
||||||
|
new_markdown = f">{self.config['header_warning']}\n\n" + new_markdown
|
||||||
|
# -------------------------------------------------
|
||||||
|
# -- Sync attachments
|
||||||
|
# -------------------------------------------------
|
||||||
|
attachments = []
|
||||||
|
# -- TODO: support named picture
|
||||||
|
md_image_reg = "(?:[!]\[(?P<caption>.*?)\])\((?P<image>.*?)\)(?P<options>\{.*\})?"
|
||||||
|
try:
|
||||||
|
for match in re.finditer(md_image_reg, markdown):
|
||||||
|
# -- TODO: I'm sure it can be done better
|
||||||
|
attachment_path = "./docs" + match.group(2)
|
||||||
|
logger.info(f"found image: ./docs{match.group(2)}")
|
||||||
|
images = re.search(md_image_reg, new_markdown)
|
||||||
|
# -- TODO: Options maybe the reason why page is invalid, but I'm not sure about it yet
|
||||||
|
# new_markdown = new_markdown.replace(images.group("options"), "")
|
||||||
|
new_markdown = re.sub(md_image_reg, f"<p><ac:image><ri:attachment ri:filename=\"{os.path.basename(attachment_path)}\"/></ac:image></p>", new_markdown)
|
||||||
|
attachments.append(attachment_path)
|
||||||
|
except AttributeError as e:
|
||||||
|
logger.warning(e)
|
||||||
|
logger.debug(f"attachments: {attachments}")
|
||||||
|
confluence_body = self.confluence_mistune(new_markdown)
|
||||||
|
self.add_page(confluence_page_name, parent_id, confluence_body)
|
||||||
|
logger.info(f"page url = {page.url}")
|
||||||
|
if not page.url and self.config["set_homepage"]:
|
||||||
|
self.set_homepage(confluence_page_name)
|
||||||
|
|
||||||
|
if attachments:
|
||||||
|
logger.debug(f"UPLOADING ATTACHMENTS TO CONFLUENCE FOR {page.title}, DETAILS:")
|
||||||
|
logger.debug(f"FILES: {attachments}")
|
||||||
|
for attachment in attachments:
|
||||||
|
logger.debug(f"trying to upload {attachment} to {confluence_page_name}")
|
||||||
|
if self.enabled:
|
||||||
|
try:
|
||||||
|
self.add_or_update_attachment(confluence_page_name, attachment)
|
||||||
|
except Exception as Argument:
|
||||||
|
logger.warning(Argument)
|
||||||
|
except Exception as exp:
|
||||||
|
logger.error(exp)
|
||||||
|
return markdown
|
||||||
|
|
||||||
def on_post_page(self, output, page, config):
|
def on_post_page(self, output, page, config):
|
||||||
logger.info("The author was uploading images here, maybe there was a reason for that")
|
if self.enabled:
|
||||||
|
logger.info("The author was uploading images here, maybe there was a reason for that")
|
||||||
|
|
||||||
def on_page_content(self, html, page, config, files):
|
def on_page_content(self, html, page, config, files):
|
||||||
return html
|
return html
|
||||||
@ -260,7 +268,7 @@ class MkdocsWithConfluence(BasePlugin):
|
|||||||
name = os.path.basename(filepath)
|
name = os.path.basename(filepath)
|
||||||
logger.debug(f" * Mkdocs With Confluence: Get Attachment: PAGE ID: {page_id}, FILE: {filepath}")
|
logger.debug(f" * Mkdocs With Confluence: Get Attachment: PAGE ID: {page_id}, FILE: {filepath}")
|
||||||
|
|
||||||
url = self.config["host_url"] + "/" + page_id + "/child/attachment"
|
url = self.config["host_url"] + "/content/" + page_id + "/child/attachment"
|
||||||
headers = {"X-Atlassian-Token": "no-check"} # no content-type here!
|
headers = {"X-Atlassian-Token": "no-check"} # no content-type here!
|
||||||
logger.debug(f"URL: {url}")
|
logger.debug(f"URL: {url}")
|
||||||
|
|
||||||
@ -274,7 +282,7 @@ class MkdocsWithConfluence(BasePlugin):
|
|||||||
def update_attachment(self, page_id, filepath, existing_attachment, message):
|
def update_attachment(self, page_id, filepath, existing_attachment, message):
|
||||||
logger.debug(f" * Mkdocs With Confluence: Update Attachment: PAGE ID: {page_id}, FILE: {filepath}")
|
logger.debug(f" * Mkdocs With Confluence: Update Attachment: PAGE ID: {page_id}, FILE: {filepath}")
|
||||||
|
|
||||||
url = self.config["host_url"] + "/" + page_id + "/child/attachment/" + existing_attachment["id"] + "/data"
|
url = self.config["host_url"] + "/content/" + page_id + "/child/attachment/" + existing_attachment["id"] + "/data"
|
||||||
headers = {"X-Atlassian-Token": "no-check"} # no content-type here!
|
headers = {"X-Atlassian-Token": "no-check"} # no content-type here!
|
||||||
logger.debug(f"URL: {url}")
|
logger.debug(f"URL: {url}")
|
||||||
filename = os.path.basename(filepath)
|
filename = os.path.basename(filepath)
|
||||||
@ -297,7 +305,7 @@ class MkdocsWithConfluence(BasePlugin):
|
|||||||
def create_attachment(self, page_id, filepath, message):
|
def create_attachment(self, page_id, filepath, message):
|
||||||
logger.debug(f" * Mkdocs With Confluence: Create Attachment: PAGE ID: {page_id}, FILE: {filepath}")
|
logger.debug(f" * Mkdocs With Confluence: Create Attachment: PAGE ID: {page_id}, FILE: {filepath}")
|
||||||
|
|
||||||
url = self.config["host_url"] + "/" + page_id + "/child/attachment"
|
url = self.config["host_url"] + "/content/" + page_id + "/child/attachment"
|
||||||
headers = {"X-Atlassian-Token": "no-check"} # no content-type here!
|
headers = {"X-Atlassian-Token": "no-check"} # no content-type here!
|
||||||
logger.debug(f"URL: {url}")
|
logger.debug(f"URL: {url}")
|
||||||
|
|
||||||
@ -320,7 +328,7 @@ class MkdocsWithConfluence(BasePlugin):
|
|||||||
def find_page_id(self, page_name):
|
def find_page_id(self, page_name):
|
||||||
logger.info(f"looking for a page id of the page: {page_name}")
|
logger.info(f"looking for a page id of the page: {page_name}")
|
||||||
name_confl = page_name.replace(" ", "+")
|
name_confl = page_name.replace(" ", "+")
|
||||||
url = self.config["host_url"] + "?title=" + name_confl + "&spaceKey=" + self.config["space"] + "&expand=history"
|
url = self.config["host_url"] + "/content?title=" + name_confl + "&spaceKey=" + self.config["space"] + "&expand=history"
|
||||||
logger.debug(f"URL: {url}")
|
logger.debug(f"URL: {url}")
|
||||||
|
|
||||||
r = self.session.get(url)
|
r = self.session.get(url)
|
||||||
@ -331,7 +339,7 @@ class MkdocsWithConfluence(BasePlugin):
|
|||||||
logger.debug(f"response: {response_json}")
|
logger.debug(f"response: {response_json}")
|
||||||
return response_json["results"][0]["id"]
|
return response_json["results"][0]["id"]
|
||||||
else:
|
else:
|
||||||
logger.debug(f"page {page_name} doens't exist")
|
logger.warning(f"page {page_name} doens't exist")
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def add_page(self, page_name, parent_page_id, page_content_in_storage_format):
|
def add_page(self, page_name, parent_page_id, page_content_in_storage_format):
|
||||||
@ -341,7 +349,7 @@ class MkdocsWithConfluence(BasePlugin):
|
|||||||
self.update_page(page_name, page_content_in_storage_format)
|
self.update_page(page_name, page_content_in_storage_format)
|
||||||
else:
|
else:
|
||||||
logger.info(f"Creating a new page: {page_name} under page with ID: {parent_page_id}")
|
logger.info(f"Creating a new page: {page_name} under page with ID: {parent_page_id}")
|
||||||
url = self.config["host_url"] + "/"
|
url = self.config["host_url"] + "/content/"
|
||||||
logger.debug(f"URL: {url}")
|
logger.debug(f"URL: {url}")
|
||||||
headers = {"Content-Type": "application/json"}
|
headers = {"Content-Type": "application/json"}
|
||||||
space = self.config["space"]
|
space = self.config["space"]
|
||||||
@ -349,9 +357,10 @@ class MkdocsWithConfluence(BasePlugin):
|
|||||||
"type": "page",
|
"type": "page",
|
||||||
"title": page_name,
|
"title": page_name,
|
||||||
"space": {"key": space},
|
"space": {"key": space},
|
||||||
"ancestors": [{"id": parent_page_id}],
|
|
||||||
"body": {"storage": {"value": page_content_in_storage_format, "representation": "storage"}},
|
"body": {"storage": {"value": page_content_in_storage_format, "representation": "storage"}},
|
||||||
}
|
}
|
||||||
|
if parent_page_id:
|
||||||
|
data["ancestors"] = [{"id": parent_page_id}]
|
||||||
logger.debug(f"DATA: {data}")
|
logger.debug(f"DATA: {data}")
|
||||||
if not self.dryrun:
|
if not self.dryrun:
|
||||||
try:
|
try:
|
||||||
@ -370,7 +379,7 @@ class MkdocsWithConfluence(BasePlugin):
|
|||||||
if page_id:
|
if page_id:
|
||||||
page_version = self.find_page_version(page_name)
|
page_version = self.find_page_version(page_name)
|
||||||
page_version = page_version + 1
|
page_version = page_version + 1
|
||||||
url = self.config["host_url"] + "/" + page_id
|
url = self.config["host_url"] + "/content/" + page_id
|
||||||
headers = {"Content-Type": "application/json"}
|
headers = {"Content-Type": "application/json"}
|
||||||
space = self.config["space"]
|
space = self.config["space"]
|
||||||
data = {
|
data = {
|
||||||
@ -398,7 +407,7 @@ class MkdocsWithConfluence(BasePlugin):
|
|||||||
def find_page_version(self, page_name):
|
def find_page_version(self, page_name):
|
||||||
logger.debug(f"INFO - * Mkdocs With Confluence: Find PAGE VERSION, PAGE NAME: {page_name}")
|
logger.debug(f"INFO - * Mkdocs With Confluence: Find PAGE VERSION, PAGE NAME: {page_name}")
|
||||||
name_confl = page_name.replace(" ", "+")
|
name_confl = page_name.replace(" ", "+")
|
||||||
url = self.config["host_url"] + "?title=" + name_confl + "&spaceKey=" + self.config["space"] + "&expand=version"
|
url = self.config["host_url"] + "/content?title=" + name_confl + "&spaceKey=" + self.config["space"] + "&expand=version"
|
||||||
r = self.session.get(url)
|
r = self.session.get(url)
|
||||||
r.raise_for_status()
|
r.raise_for_status()
|
||||||
with nostdout():
|
with nostdout():
|
||||||
@ -413,7 +422,7 @@ class MkdocsWithConfluence(BasePlugin):
|
|||||||
def find_parent_name_of_page(self, name):
|
def find_parent_name_of_page(self, name):
|
||||||
logger.debug(f"INFO - * Mkdocs With Confluence: Find PARENT OF PAGE, PAGE NAME: {name}")
|
logger.debug(f"INFO - * Mkdocs With Confluence: Find PARENT OF PAGE, PAGE NAME: {name}")
|
||||||
idp = self.find_page_id(name)
|
idp = self.find_page_id(name)
|
||||||
url = self.config["host_url"] + "/" + idp + "?expand=ancestors"
|
url = self.config["host_url"] + "/content" + idp + "?expand=ancestors"
|
||||||
|
|
||||||
r = self.session.get(url)
|
r = self.session.get(url)
|
||||||
r.raise_for_status()
|
r.raise_for_status()
|
||||||
@ -431,3 +440,32 @@ class MkdocsWithConfluence(BasePlugin):
|
|||||||
while not condition and time.time() - start < timeout:
|
while not condition and time.time() - start < timeout:
|
||||||
time.sleep(interval)
|
time.sleep(interval)
|
||||||
|
|
||||||
|
def set_homepage(self, page_name):
|
||||||
|
page_id = self.find_page_id(page_name)
|
||||||
|
url = self.config["host_url"] + "/space/" + self.config["space"]
|
||||||
|
headers = {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
"Accept": "application/json"
|
||||||
|
}
|
||||||
|
# data = {"homepage": {"id": page_id}}
|
||||||
|
if not self.dryrun:
|
||||||
|
logger.info("getting the space information")
|
||||||
|
try:
|
||||||
|
r = self.session.get(url, headers=headers)
|
||||||
|
r.raise_for_status
|
||||||
|
with nostdout():
|
||||||
|
response_json = r.json()
|
||||||
|
except Exception as exp:
|
||||||
|
logger.warning(r.json())
|
||||||
|
logger.error(exp)
|
||||||
|
response_json['homepage'] = { "id": page_id }
|
||||||
|
try:
|
||||||
|
r = self.session.put(url, json=response_json, headers=headers)
|
||||||
|
r.raise_for_status()
|
||||||
|
except Exception as exp:
|
||||||
|
logger.warning(r.json())
|
||||||
|
logger.error(exp)
|
||||||
|
if r.status_code == 200:
|
||||||
|
logger.info(f"A page with this id is now a homepage in the space: {page_id}")
|
||||||
|
else:
|
||||||
|
logger.error(f"Can't set homepage to: {page_id}")
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
[tool.poetry]
|
[tool.poetry]
|
||||||
name = "mkdocs-with-confluence"
|
name = "mkdocs-with-confluence"
|
||||||
version = "0.3.1"
|
version = "0.3.4"
|
||||||
description = "MkDocs plugin for uploading markdown documentation to Confluence via Confluence REST API"
|
description = "MkDocs plugin for uploading markdown documentation to Confluence via Confluence REST API"
|
||||||
authors = ["Nikolai Rodionov <allanger@zohomail.com>"]
|
authors = ["Nikolai Rodionov <allanger@zohomail.com>"]
|
||||||
readme = "README.md"
|
readme = "README.md"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user