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

Commit

Permalink
fix: Fix metadata if 'category' don't exist
Browse files Browse the repository at this point in the history
  • Loading branch information
Mara-Li committed Dec 27, 2021
1 parent 698d957 commit 9a940e0
Showing 1 changed file with 35 additions and 18 deletions.
53 changes: 35 additions & 18 deletions YAFPA/common/conversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
link_conversion as links,
admonition as adm,
metadata as mt,
)
)
from YAFPA.common import global_value as settings

BASEDIR = Path(settings.BASEDIR)
Expand Down Expand Up @@ -87,10 +87,17 @@ def convert_hashtags(final_text):
for i in range(0, len(token)):
if token[i] in css:
final_text = final_text.replace(token[i], "")
if final_text.startswith('#'):
heading = re.findall('#', final_text)
heading = ''.join(heading)
IAL = heading + " **" + final_text.replace('#', '').strip() + "**{: " + token[i] + "} \n"
if final_text.startswith("#"):
heading = re.findall("#", final_text)
heading = "".join(heading)
IAL = (
heading
+ " **"
+ final_text.replace("#", "").strip()
+ "**{: "
+ token[i]
+ "} \n"
)
else:
IAL = "**" + final_text.strip() + "**{: " + token[i] + "} \n"
final_text = final_text.replace(final_text, IAL)
Expand Down Expand Up @@ -130,15 +137,21 @@ def file_convert(file, folder, all_file, option=0):
lines = adm.admonition_trad(lines)
for ln in lines:
final_text = ln.replace(" \n", "\n")
if not final_text.strip().endswith("%%") and not final_text.strip().startswith("%%"):
#skip comment
if not final_text.strip().endswith("%%") and not final_text.strip().startswith(
"%%"
):
# skip comment
final_text = final_text.replace("\n", " \n")
final_text = links.link_image_conversion(final_text, meta, os.path.basename(file), all_file, folder)
final_text = links.link_image_conversion(
final_text, meta, os.path.basename(file), all_file, folder
)

if not '`' in final_text:
if not "`" in final_text:
final_text = re.sub("\%{2}(.*)\%{2}", "", final_text)

if re.search(r"\\U\w+", final_text) and not "Users" in final_text: #Fix emoji if bug because of frontmatter
if (
re.search(r"\\U\w+", final_text) and not "Users" in final_text
): # Fix emoji if bug because of frontmatter
emojiz = re.search(r"\\U\w+", final_text)
emojiz = emojiz.group().strip().replace('"', "")
convert_emojiz = (
Expand All @@ -153,12 +166,13 @@ def file_convert(file, folder, all_file, option=0):
# Admonition space
final_text = final_text.replace(" \n", "\n")


elif re.search("```mermaid\s+", final_text):
# Convert to jekyll-support mermaid format
final_text = final_text.replace("```mermaid", "```mermaid!")

if re.search("#\w+", final_text) and not re.search("(`|\[{2}|\()(.*)#(.*)(`|\]{2}|\))", final_text):
if re.search("#\w+", final_text) and not re.search(
"(`|\[{2}|\()(.*)#(.*)(`|\]{2}|\))", final_text
):
# Hashtags
final_text = convert_hashtags(final_text)

Expand Down Expand Up @@ -186,18 +200,21 @@ def file_convert(file, folder, all_file, option=0):
elif re.search("==(.*)==", final_text):
final_text = re.sub("==", "[[", final_text, 1)
final_text = re.sub("( ?)==", "::highlight]] ", final_text, 2)
elif re.search("(\[{2}|\().*\.(png|jpg|jpeg|gif)", final_text): # CONVERT IMAGE
elif re.search(
"(\[{2}|\().*\.(png|jpg|jpeg|gif)", final_text
): # CONVERT IMAGE
final_text = links.move_img(final_text)
elif re.fullmatch(
"\\\\", final_text.strip()
): # New line when using "\" in obsidian file
final_text = " \n"
final.append(final_text)
category = meta.metadata['category'].split('/')
if len(category) > 1:
meta.metadata['category'] = category[1]
else:
meta.metadata['category'] = category[0]
if meta.metadata["category"]:
category = meta.metadata["category"].split("/")
if len(category) > 1:
meta.metadata["category"] = category[1]
else:
meta.metadata["category"] = category[0]
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")
Expand Down

0 comments on commit 9a940e0

Please sign in to comment.