Skip to content

Fix slug routing for Notion pages with username-prefixed paths#61

Merged
shigahi merged 1 commit intomasterfrom
fix/slug-page-id-extraction
Feb 20, 2026
Merged

Fix slug routing for Notion pages with username-prefixed paths#61
shigahi merged 1 commit intomasterfrom
fix/slug-page-id-extraction

Conversation

@shigahi
Copy link
Collaborator

@shigahi shigahi commented Feb 20, 2026

Summary

  • Fix page ID extraction in generated Worker code to handle Notion's username-prefixed URL paths (e.g., /philipb/Ressources-9a8ace54b67c4611b93ead8db1b67c19)
  • Replace pathname.slice(-32) with regex /[0-9a-f]{32}/ in 3 locations: client-side getPage(), pushState hook, and server-side canonical URL extraction

Root Cause

When Notion uses a personal workspace, page URLs contain a username prefix: /{username}/{Page-Name}-{pageId}. The previous slice(-32) approach extracted the last 32 characters of the full path, which included part of the page name instead of just the hex page ID. This caused updateSlug() to fail, leaving the URL in its raw Notion format.

Fix

Using pathname.match(/[0-9a-f]{32}/) correctly extracts the 32-character hex page ID regardless of the URL path structure.

Fixes #55

Test plan

  • Verify slugs work with standard Notion URLs (/{pageId})
  • Verify slugs work with username-prefixed Notion URLs (/{username}/{PageName}-{pageId})
  • Verify client-side navigation (pushState) correctly rewrites URLs to slugs
  • Verify canonical URLs are correctly resolved

🤖 Generated with Claude Code

Use regex to extract 32-char hex page IDs instead of slice(-32),
which fails when Notion returns paths like /username/Page-Name-{pageId}.

Fixes #55

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@shigahi shigahi mentioned this pull request Feb 20, 2026
@shigahi shigahi merged commit 1198c5b into master Feb 20, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Slug not working

1 participant