-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Block ordering * Removing extra metadata
- Loading branch information
Showing
16 changed files
with
365 additions
and
133 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
from apps.notion.rewrite.links import rewrite_links | ||
from apps.notion.rewrite.tags import drop_extra_tags | ||
from apps.notion.types import BlockData | ||
|
||
|
||
def apply_our_adjustments(notion_block_data: BlockData) -> BlockData: | ||
adjusted = rewrite_links(notion_block_data) | ||
|
||
return drop_extra_tags(adjusted) | ||
|
||
|
||
__all__ = [ | ||
"apply_our_adjustments", | ||
"drop_extra_tags", | ||
"rewrite_links", | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import fnmatch | ||
|
||
from benedict import benedict | ||
|
||
from apps.notion.types import BlockData | ||
|
||
TAGS_TO_LIVE = ( | ||
"value.id", | ||
"value.type", | ||
"value.content.*", | ||
"value.properties.*", | ||
"value.format.page_icon", | ||
"value.format.page_cover", | ||
"value.format.page_cover_position", | ||
"value.parent_id", | ||
"value.parent_table", | ||
) | ||
|
||
|
||
def drop_extra_tags(notion_block_data: BlockData) -> BlockData: | ||
data = benedict(notion_block_data) | ||
for key in sorted(data.keypaths(), key=len, reverse=True): | ||
if not tag_should_live(key): | ||
del data[key] | ||
|
||
return notion_block_data | ||
|
||
|
||
def tag_should_live(tag: str) -> bool: | ||
for tag_to_live in TAGS_TO_LIVE: | ||
if tag_to_live.startswith(f"{tag}."): | ||
return True | ||
|
||
if fnmatch.fnmatch(tag, tag_to_live) or tag == tag_to_live.replace(".*", ""): | ||
return True | ||
|
||
return False |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import pytest | ||
|
||
from apps.notion.rewrite import drop_extra_tags | ||
|
||
@pytest.fixture | ||
def block(): | ||
return { | ||
"role": "reader", | ||
"value": { | ||
"format": {"page_icon": "1.ico"}, | ||
"second_level_value_to_drop": "test", | ||
"second_level_key_to_drop": { | ||
"test": "__expired", | ||
}, | ||
"parent_id": "will_no_be_dropped", | ||
"content": { | ||
"random_key": "random_value", | ||
}, | ||
}, | ||
} | ||
|
||
|
||
def test_extra_tags_are_dropped(block): | ||
block = drop_extra_tags(block) | ||
|
||
assert "role" not in block | ||
assert "second_level_value_to_drop" not in block | ||
assert "second_level_key_to_drop" not in block | ||
|
||
|
||
def test_required_values_are_not_dropped(block): | ||
block = drop_extra_tags(block) | ||
|
||
assert block["value"]["parent_id"] == "will_no_be_dropped" | ||
assert block["value"]["format"]["page_icon"] == "1.ico" | ||
assert block["value"]["content"]["random_key"] == "random_value" # wildcards work wll |
Oops, something went wrong.