Skip to content
Open
Show file tree
Hide file tree
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
14 changes: 7 additions & 7 deletions cli/nao_core/commands/sync/providers/notion/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,13 +244,13 @@ def extract_page_title(page: dict[str, Any], page_id: str) -> str:
"""Read a page's title from its properties, falling back to its ID."""
properties = page.get("properties", {})

for prop_name in ["title", "Title", "Name", "name", "Page"]:
if prop_name in properties:
title_prop = properties[prop_name]
if title_prop.get("type") == "title":
title_array = title_prop.get("title", [])
if title_array:
return "".join(t.get("plain_text", "") for t in title_array)
# Database rows name their title property freely (e.g. "Topic"), so match on the
# property type rather than a list of conventional names.
for title_prop in properties.values():
if title_prop.get("type") == "title":
title_array = title_prop.get("title", [])
if title_array:
return "".join(t.get("plain_text", "") for t in title_array)

return page_id

Expand Down
18 changes: 18 additions & 0 deletions cli/tests/nao_core/commands/sync/test_notion_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from nao_core.commands.sync.providers.notion.provider import (
NotionSyncProvider,
extract_notion_id,
extract_page_title,
extract_view_id,
markdown_filename,
render_document,
Expand Down Expand Up @@ -113,6 +114,23 @@ def test_extract_notion_id_prefers_the_object_over_the_view():
assert extract_notion_id(url) == "35e5f0e8a00080c69a81ef456a2b174b"


def test_extract_page_title_reads_a_custom_named_title_property():
page = {
"properties": {
"Owner": {"type": "people", "people": []},
"Topic": {"type": "title", "title": [{"plain_text": "Basic "}, {"plain_text": "Knowledge"}]},
}
}

assert extract_page_title(page, "35e5f0e8a00080c69a81ef456a2b174b") == "Basic Knowledge"


def test_extract_page_title_falls_back_to_the_id_when_the_title_is_empty():
page = {"properties": {"Topic": {"type": "title", "title": []}}}

assert extract_page_title(page, "35e5f0e8a00080c69a81ef456a2b174b") == "35e5f0e8a00080c69a81ef456a2b174b"


@pytest.mark.parametrize(
"title",
["Schema: Orders", "# Draft", "true", "2026-01-01", "- dash", '"quoted"', "value #comment"],
Expand Down
Loading