diff --git a/src/libs/notion.ts b/src/libs/notion.ts index 03d27f3..6c23e95 100644 --- a/src/libs/notion.ts +++ b/src/libs/notion.ts @@ -54,18 +54,18 @@ const getPropertyValue = (property) => { */ export const getPageProperty = ({ pageId, recordMap }) => { if (!pageId || !recordMap) { - return + return {} } const pageBlock = get(recordMap, ['block', pageId]) if (!pageBlock || get(pageBlock, ['value', 'type']) !== 'page') { - return + return {} } // TODO: need a more robust way to get the correct collection id. const collectionId = Object.keys(recordMap.collection)[0] if (!collectionId) { - return + return {} } const collection = get(recordMap, ['collection', collectionId]) @@ -205,8 +205,11 @@ export const getSinglePagePath = ({ pageName, pageId, recordMap }) => { return } - const property: any = getPageProperty({ pageId, recordMap }) - const slug = property.Slug || property.Title + const property: any = getPageProperty({ pageId, recordMap }) || {} + const slug = property?.Slug || property?.Title + if (!slug) { + return + } const pagePath = [encodeURIComponent(slug), uuidToId(pageId)].join('-') return pagePath } diff --git a/src/libs/server/transformer.ts b/src/libs/server/transformer.ts index ca05380..71e2fbe 100644 --- a/src/libs/server/transformer.ts +++ b/src/libs/server/transformer.ts @@ -248,20 +248,31 @@ export const transformMenuItems = ( articleStream: ArticleStream ): MenuItem[] => { const recordMap = articleStream.content - const menuItems: MenuItem[] = articleStream.ids.map((pageId) => { + const menuItems: MenuItem[] = articleStream.ids.reduce((items, pageId) => { const pagePath = getSinglePagePath({ pageName, pageId, recordMap, }) - const url = `/${pageName}/${pagePath}` - const block = get(recordMap, ['block', pageId, 'value']) - const label = getBlockTitle(block, recordMap as any) - return { - label, - url, + if (pagePath) { + const url = `/${pageName}/${pagePath}` + const block = get(recordMap, ['block', pageId, 'value']) + const label = getBlockTitle(block, recordMap as any) + const item = { + label, + url, + } + items.push(item) + } else { + const options: logOption = { + category: 'transformMenuItems', + message: `strip out empty pagePath. | pageName: ${pageName} | pageId: ${pageId}`, + level: 'warn', + } + log(options) } - }) + return items + }, []) const schema = { type: 'array', @@ -350,14 +361,25 @@ export const transformPageUrls = ( articleStream: ArticleStream ): string[] => { const recordMap = articleStream.content - let pageUrls: string[] = articleStream.ids.map((pageId) => { + let pageUrls: string[] = articleStream.ids.reduce((items, pageId) => { const pagePath = getSinglePagePath({ pageName, pageId, recordMap, }) - return `/${pageName}/${pagePath}` - }) + if (pagePath) { + const url = `/${pageName}/${pagePath}` + items.push(url) + } else { + const options: logOption = { + category: 'transformPageUrls', + message: `strip out empty pagePath. | pageName: ${pageName} | pageId: ${pageId}`, + level: 'warn', + } + log(options) + } + return items + }, []) pageUrls.push(`/${pageName}`) diff --git a/tests/e2e/playwright.config.ts b/tests/e2e/playwright.config.ts index 96747bf..fed1768 100644 --- a/tests/e2e/playwright.config.ts +++ b/tests/e2e/playwright.config.ts @@ -42,8 +42,12 @@ const config: PlaywrightTestConfig = { /* Maximum time each action such as `click()` can take. Defaults to 0 (no limit). */ actionTimeout: 0, /* Base URL to use in actions like `await page.goto('/')`. */ - baseURL: - 'https://dazedbear-github-io-git-test-adjustment-music-logbook-dazedbear.vercel.app/', + baseURL: isCI + ? `${get(website, [currentEnv, 'protocol'])}://${get(website, [ + currentEnv, + 'host', + ])}` + : 'http://local.dazedbear.pro:3000', /* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */ trace: 'on-first-retry', },