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

Commit

Permalink
fix: Wrap quote title & maintain slash in path
Browse files Browse the repository at this point in the history
  • Loading branch information
younho9 committed Feb 15, 2021
1 parent f7a2074 commit 0238f34
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
6 changes: 3 additions & 3 deletions narkdown/exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ def parse_notion_blocks(self, blocks, path, offset):

self.get_notion_page(block.get_browseable_url(), sub_path=path)

child_title = replace_path(block.title)
child_title = replace_filename(block.title)

if self.create_page_directory:
contents += f"[{block.title}]({child_title}/index.md)"
Expand Down Expand Up @@ -427,7 +427,7 @@ def get_metadata(self, page, database, path):
if page.cover:
metadata.append(f"cover: {self.get_image_path(path, page.cover, 'cover')}")
if self.generate_slug:
metadata.append(f"slug: '{replace_path(page.title)}'")
metadata.append(f"slug: '{replace_filename(page.title)}'")
if database:
ordered_properties = get_ordered_properties(database)
prop_map = map(
Expand All @@ -437,7 +437,7 @@ def get_metadata(self, page, database, path):
props = list(filter(lambda s: len(s) != 0, prop_map))
return metadata + props
if page.title:
metadata.append(f"title: {page.title}")
metadata.append(f"title: '{page.title}'")

return metadata

Expand Down
12 changes: 10 additions & 2 deletions narkdown/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ def inputWithDefault(message, default):
return value


def replace_filename(filename):
return strip_dash(remove_dup_dash(remove_slash(remove_special(filename)))).lower()


def replace_path(pathname):
return strip_dash(remove_dup_dash(remove_special(pathname))).lower()

Expand All @@ -67,6 +71,10 @@ def remove_special(string):
)


def remove_slash(string):
return re.sub(r"[\/]", "-", string)


def strip_dash(string):
if len(string) == 0:
return string
Expand All @@ -90,7 +98,7 @@ def property_to_str(page, prop):
return ""

if prop_type == "title":
return f"{prop_slug}: {prop_value}"
return f"{prop_slug}: '{prop_value}'"
if prop_type in ["created_time", "last_edited_time"]:
return f"{prop_slug}: {prop_value.strftime('%Y-%m-%d')}"
if prop_type in ["created_by", "last_edited_by"]:
Expand Down Expand Up @@ -128,7 +136,7 @@ def get_created_time(page, database):

def get_filename(append_created_time, page, database):
created_time = get_created_time(page, database)
title = replace_path(page.title)
title = replace_filename(page.title)

if not created_time:
return title
Expand Down

0 comments on commit 0238f34

Please sign in to comment.