From db59c47e2bfc5b601264a0de013a29aebdd5c7ab Mon Sep 17 00:00:00 2001 From: Mara-Li Date: Tue, 26 Oct 2021 13:51:00 +0200 Subject: [PATCH] fix: :ambulance: Fix parsing bug with Jekyll with link (convert https link to markdown normal links) --- YAFPA/common/conversion.py | 10 ++++++---- YAFPA/common/convert_all.py | 3 +-- YAFPA/common/image_transform.py | 4 ++++ YAFPA/common/metadata.py | 8 -------- 4 files changed, 11 insertions(+), 14 deletions(-) diff --git a/YAFPA/common/conversion.py b/YAFPA/common/conversion.py index d0efdd9..7d13722 100644 --- a/YAFPA/common/conversion.py +++ b/YAFPA/common/conversion.py @@ -48,6 +48,7 @@ def clipboard(filepath, folder): def file_write(file, contents, folder): file_name = os.path.basename(file) + meta = frontmatter.load(file) if contents == "": return False else: @@ -60,7 +61,6 @@ def file_write(file, contents, folder): mt.frontmatter_check(file_name, folder) return True else: - meta = frontmatter.load(file) if not meta["share"] or meta["share"] == False: check.delete_file(file, folder) return False @@ -104,10 +104,8 @@ def file_convert(file, folder, option=0): path_folder = path_folder.replace(os.sep, "") path_folder = path_folder.replace("_", "") if not path_folder in file: - data = open(file, "r", encoding="utf-8") meta = frontmatter.load(file) - lines = data.readlines() - data.close() + lines = meta.content.splitlines(True) if option == 1: if "share" not in meta.keys() or meta["share"] is False: meta["share"] = True @@ -193,6 +191,10 @@ def file_convert(file, folder, option=0): final_text = re.sub("#\^(.*)]]", "]]", final_text) final_text = final_text + " " final.append(final_text) + meta_list = [(f"{k}: {v} \n") for k, v in meta.metadata.items()] + meta_list.insert(0, '--- \n') + meta_list.insert(len(meta_list) + 1, "--- \n") + final = meta_list + final return final else: diff --git a/YAFPA/common/convert_all.py b/YAFPA/common/convert_all.py index 2c66d8c..818ebf4 100644 --- a/YAFPA/common/convert_all.py +++ b/YAFPA/common/convert_all.py @@ -21,13 +21,12 @@ def diff_file(file, folder, update=0): retro_old = checkFile.retro(notes_path) meta_old = frontmatter.load(notes_path) meta_old = mt.remove_frontmatter(meta_old.metadata) - temp = convert.file_convert(file, folder) try: front_temp = frontmatter.loads("".join(temp)) except yaml.parser.ParserError: print("ERROR : ", file) - pass + return False #skip meta_new = mt.remove_frontmatter(front_temp.metadata) new_version = checkFile.retro(temp, 1) if new_version == retro_old and sorted(meta_old.keys()) == sorted( diff --git a/YAFPA/common/image_transform.py b/YAFPA/common/image_transform.py index 5bc1828..96a17b7 100644 --- a/YAFPA/common/image_transform.py +++ b/YAFPA/common/image_transform.py @@ -103,6 +103,10 @@ def convert_to_wikilink(line): links = links[0] if not re.search("https?:\/\/", links): line = transform_link(line, links) + elif re.search("https?:\/\/", final_text): + link = re.search("https?:\/\/.*", final_text) #solo link fix jekyll liquid + link = link.group() + line = line.replace(link, f"[{link.strip()}]({link.strip()})") return line diff --git a/YAFPA/common/metadata.py b/YAFPA/common/metadata.py index 3e465e3..d537131 100644 --- a/YAFPA/common/metadata.py +++ b/YAFPA/common/metadata.py @@ -23,9 +23,6 @@ def remove_frontmatter(meta): def frontmatter_check(filename, folder): metadata = open(Path(f"{folder}/{filename}"), "r", encoding="utf-8") meta = frontmatter.load(metadata) - folder_key = str(folder).replace(f"{BASEDIR}", "") - folder_key = folder_key.replace(os.sep, "") - folder_key = folder_key.replace("_", "") metadata.close() final = open(Path(f"{folder}/{filename}"), "w", encoding="utf-8") now = datetime.now().strftime("%d-%m-%Y") @@ -35,11 +32,6 @@ def frontmatter_check(filename, folder): meta["date"] = now if not "title" in meta.keys(): meta["title"] = filename.replace(".md", "") - if not "link" in meta.keys(): - filename = filename.replace(".md", "") - filename = filename.replace(" ", "-") - clip = f"{web}{folder_key}/{filename}" - meta["link"] = clip update = frontmatter.dumps(meta) final.write(update) final.close()