Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: 500 issue due to invalid Slug #97

Merged
merged 3 commits into from
Oct 9, 2023
Merged
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
13 changes: 8 additions & 5 deletions src/libs/notion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down Expand Up @@ -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
}
Expand Down
44 changes: 33 additions & 11 deletions src/libs/server/transformer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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}`)

Expand Down
8 changes: 6 additions & 2 deletions tests/e2e/playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
},
Expand Down
Loading