From c022db9f5f90c4815feb69c78c24e0ae36dae01b Mon Sep 17 00:00:00 2001 From: Shyam Saraswati Date: Fri, 5 Aug 2022 13:18:39 +1000 Subject: [PATCH] Image upload only when changed (#10) (#12) * Only upload images that have changed by recording a file hash as the image comment * Add image to attachments based markdown formatted image links Allow dash in attachment filename (#13) Co-authored-by: Simon Stamm Signed-off-by: Pawel Sikora --- .gitignore | 2 + mkdocs_with_confluence/plugin.py | 135 ++++++++++++++++++++++++------- setup.py | 2 +- 3 files changed, 108 insertions(+), 31 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..dbef035 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +mkdocs_with_confluence/__pycache__/* +mkdocs_with_confluence.egg-info/* diff --git a/mkdocs_with_confluence/plugin.py b/mkdocs_with_confluence/plugin.py index 93ccd16..95b0e82 100644 --- a/mkdocs_with_confluence/plugin.py +++ b/mkdocs_with_confluence/plugin.py @@ -1,5 +1,6 @@ import time import os +import hashlib import sys import re import tempfile @@ -211,16 +212,19 @@ class MkdocsWithConfluence(BasePlugin): tf = tempfile.NamedTemporaryFile(delete=False) f = open(tf.name, "w") - files = [] + attachments = [] try: for match in re.finditer(r'img src="file://(.*)" s', markdown): if self.config["debug"]: print(f"DEBUG - FOUND IMAGE: {match.group(1)}") - files.append(match.group(1)) + attachments.append(match.group(1)) + for match in re.finditer(r"!\[[\w\. -]*\]\((?!http|file)(.*)\)", markdown): + if self.config["debug"]: + print(f"DEBUG - FOUND IMAGE: {match.group(1)}") + attachments.append("docs/" + match.group(1)) except AttributeError as e: if self.config["debug"]: print(f"DEBUG - WARN(({e}): No images found in markdown. Proceed..") - new_markdown = re.sub( r'