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

Enable configurable Github folder <> Notion subpage URL mappings #13

Merged
merged 12 commits into from
Mar 29, 2024
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@ ignore_regex = models/.*
notion_root_page = https://www.notion.so/...
```

If you want to map specific Github folders to Notion subpages besides the `notion_root_page`, you can add the folder names and subpage URLs as parameters in the `setup.cfg` for the repo:
```
[folders]
# docs = <any_notion_url> # This can be any subpage of the Notion root page
# docs/NestedTest = <any_other_notion_url> # This can be the same subpage as above, or any other subpage of the Notion root page
```

## Usage

```bash
Expand Down
2 changes: 2 additions & 0 deletions docs/NestedTest/nested_example.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
### Heading for Test
Here's an example of a markdown file that's in a nested folder within the folder `docs`. We can also add the folder path `docs/NestedDocs` in `setup.cfg` to pick up this file to the specified Notion URL.
4 changes: 3 additions & 1 deletion docs/example.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
Example
==

This is an example markdown file to sync.
This is an example markdown file to sync.

If you add the `docs` folder name to the `[folders]` config settings in `setup.cfg`, this file will sync to the specified Notion subpage URL.
19 changes: 17 additions & 2 deletions git_notion/git_notion.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,22 @@ 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)

# Extract folder from the file path
folder = os.path.dirname(file)

# Use folder-specific URL if available, otherwise use the default repo_page URL
folder_url = config.get('folders', folder, fallback=None)
upload_file(repo_page if folder_url is None else get_client().get_block(folder_url), file)
if folder_url:
print(file, "uploaded to: ", folder_url)
else:
print(file, "uploaded to: default repo page")



# Example call:
# sync_to_notion(repo_root="/path/to/repo", config_file_path="notion_config.ini")
4 changes: 4 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,7 @@ collect_ignore = ['setup.py']

[git-notion]
notion_root_page = https://www.notion.so/Git-Documents-6cf97b2d7ab64a7d964c7a7bcc42f9aa

[folders]
# docs = <any_notion_url> # This can be any subpage of the Notion root page
# docs/NestedTest = <any_other_notion_url> # This can be the same subpage as above, or any other subpage of the Notion root page
Loading