Skip to content

Commit 9ebdfa5

Browse files
committed
Fix off-by-one in matcher
1 parent 2f32ff9 commit 9ebdfa5

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

src/_notion_scripts/upload.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -163,21 +163,22 @@ def main(
163163
for details in blocks
164164
]
165165

166-
match_until_index = 0
166+
last_matching_index: int | None = None
167167
for index, existing_page_block in enumerate(iterable=page.children):
168168
if index < len(blocks) and existing_page_block == block_objs[index]:
169-
match_until_index = index
169+
last_matching_index = index
170170
else:
171171
break
172172

173173
click.echo(
174174
message=(
175-
f"Matching blocks until index {match_until_index} for page "
175+
f"Matching blocks until index {last_matching_index} for page "
176176
f"'{title}'"
177177
),
178178
)
179-
for existing_page_block in page.children[match_until_index + 1 :]:
179+
delete_start_index = (last_matching_index or -1) + 1
180+
for existing_page_block in page.children[delete_start_index:]:
180181
existing_page_block.delete()
181182

182-
page.append(blocks=block_objs[match_until_index + 1 :])
183+
page.append(blocks=block_objs[delete_start_index:])
183184
click.echo(message=f"Updated existing page: '{title}' ({page.url})")

0 commit comments

Comments
 (0)