From e832004fae69b9691d1a4b93f13dcb7c33906bd8 Mon Sep 17 00:00:00 2001 From: shigahi Date: Fri, 20 Feb 2026 16:50:17 +0900 Subject: [PATCH] Fix slug routing for Notion pages with username-prefixed paths 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 --- src/code.ts | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/code.ts b/src/code.ts index b2150aa..35574cd 100644 --- a/src/code.ts +++ b/src/code.ts @@ -689,7 +689,8 @@ ${ } // Get current slug from page ID for canonical URL - const pageId = url.pathname.slice(-32); + const pageIdMatch = url.pathname.match(/[0-9a-f]{32}/); + const pageId = pageIdMatch ? pageIdMatch[0] : ''; const currentSlug = PAGE_TO_SLUG[pageId] || ''; return appendJavascript(response, SLUG_TO_PAGE, currentSlug, url); @@ -958,7 +959,8 @@ ${ PAGE_TO_SLUG[page] = slug; }); function getPage() { - return location.pathname.slice(-32); + const match = location.pathname.match(/[0-9a-f]{32}/); + return match ? match[0] : ''; } function getSlug() { return location.pathname.slice(1); @@ -1027,8 +1029,9 @@ ${ const pushState = window.history.pushState; window.history.pushState = function(state) { const dest = new URL(location.protocol + location.host + arguments[2]); - const id = dest.pathname.slice(-32); - if (pages.includes(id)) { + const idMatch = dest.pathname.match(/[0-9a-f]{32}/); + const id = idMatch ? idMatch[0] : ''; + if (id && pages.includes(id)) { arguments[2] = '/' + PAGE_TO_SLUG[id]; } return pushState.apply(window.history, arguments);