Skip to content
This repository has been archived by the owner on Dec 30, 2021. It is now read-only.

Commit

Permalink
fix: 🚑 Fix parsing bug with Jekyll with link (convert https link to m…
Browse files Browse the repository at this point in the history
…arkdown normal links)
  • Loading branch information
Mara-Li committed Oct 26, 2021
1 parent 0621e41 commit db59c47
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 14 deletions.
10 changes: 6 additions & 4 deletions YAFPA/common/conversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down
3 changes: 1 addition & 2 deletions YAFPA/common/convert_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
4 changes: 4 additions & 0 deletions YAFPA/common/image_transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
8 changes: 0 additions & 8 deletions YAFPA/common/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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()
Expand Down

0 comments on commit db59c47

Please sign in to comment.