Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upload files to corresponding path on Notion #2

Merged
merged 1 commit into from
Dec 9, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions git_notion/git_notion.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
from configparser import ConfigParser
import re

from pathlib import Path

from notion.block import PageBlock
from notion.block import TextBlock
from notion.client import NotionClient
Expand Down Expand Up @@ -33,6 +35,12 @@ def get_or_create_page(base_page, title):
return page


def create_path_pages(base_page, path_pages):
for page in path_pages:
base_page = get_or_create_page(base_page, page)
return base_page


def upload_file(base_page, filename: str, page_title=None):
page_title = page_title or filename
page = get_or_create_page(base_page, page_title)
Expand Down Expand Up @@ -62,7 +70,10 @@ def sync_to_notion(repo_root: str = "."):
ignore_regex = os.getenv("NOTION_IGNORE_REGEX") or config.get('git-notion', 'ignore_regex', fallback=None)
root_page = get_client().get_block(root_page_url)
repo_page = get_or_create_page(root_page, repo_name)
for file in glob.glob("**/*.md", recursive=True):
if ignore_regex is None or not re.match(ignore_regex, file):
print(file)
upload_file(repo_page, file)
for path in glob.glob("**/*.md", recursive=True):
if ignore_regex is None or not re.match(ignore_regex, path):
print(path)
path_pages = path.split(os.path.sep)[:-1]
base_page = create_path_pages(repo_page, path_pages)
page_title = Path(path).stem
upload_file(base_page, path, page_title)