Skip to content

Commit

Permalink
πŸ› Fix preview for 404, 500 #2081 (#2131)
Browse files Browse the repository at this point in the history
* πŸ› Fix preview for 404, 500 #2081

* 🚨  Fix issues from code ql #2081

* Remove comments #2081

* ✨ Add link option to text in 404 #2081
  • Loading branch information
padms authored Mar 12, 2024
1 parent cf7b834 commit 1bf3d65
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 12 deletions.
2 changes: 1 addition & 1 deletion sanityv3/schemas/documents/404.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const textContentType = configureBlockContent({
h3: false,
h4: false,
externalLink: false,
internalLink: false,
internalLink: true,
lists: false,
attachment: false,
smallText: false,
Expand Down
3 changes: 2 additions & 1 deletion web/lib/queries/pageNotFound.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import markDefs from './common/blockEditorMarks'
import { sameLang } from './common/langAndDrafts'

export const pageNotFoundQuery = /* groq */ `
Expand All @@ -6,7 +7,7 @@ export const pageNotFoundQuery = /* groq */ `
"documentTitle": seo.documentTitle,
"metaDescription": seo.metaDescription,
title,
text,
text[]{..., ${markDefs}},
backgroundImage
}
`
13 changes: 8 additions & 5 deletions web/pages/404.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,18 +69,21 @@ Custom404.getLayout = (page: AppProps) => {
)
}

export const getStaticProps: GetStaticProps = async ({ locale = defaultLanguage.locale }) => {
export const getStaticProps: GetStaticProps = async ({ locale = defaultLanguage.locale, preview = false }) => {
const lang = getNameFromLocale(locale)
const intl = await getIntl(locale, false)

const queryParams = {
lang,
}

const { menuData, pageData, footerData } = await getComponentsData({
query: pageNotFoundQuery,
queryParams,
})
const { menuData, pageData, footerData } = await getComponentsData(
{
query: pageNotFoundQuery,
queryParams,
},
preview,
)

return {
props: {
Expand Down
13 changes: 8 additions & 5 deletions web/pages/500.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,16 +69,19 @@ Custom500.getLayout = (page: AppProps) => {
)
}

export const getStaticProps: GetStaticProps = async ({ locale = defaultLanguage.locale }) => {
export const getStaticProps: GetStaticProps = async ({ locale = defaultLanguage.locale, preview = false }) => {
const lang = getNameFromLocale(locale)
const queryParams = {
lang,
}

const { menuData, pageData, footerData } = await getComponentsData({
query: internalServerErrorQuery,
queryParams,
})
const { menuData, pageData, footerData } = await getComponentsData(
{
query: internalServerErrorQuery,
queryParams,
},
preview,
)

const intl = await getIntl(locale, false)

Expand Down
4 changes: 4 additions & 0 deletions web/pages/api/preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ export default function preview(req, res) {
url = locale === 'no' ? `${baseUrl}/no/nyheter?preview` : `${baseUrl}/news?preview`
} else if (Flags.HAS_MAGAZINE_INDEX && ['/magazineIndex', '/drafts.magazineIndex'].includes(pathname)) {
url = locale === 'no' ? `${baseUrl}/no/magasin?preview` : `${baseUrl}/magazine?preview`
} else if (['/pageNotFound', '/drafts.pageNotFound'].includes(pathname)) {
url = `${baseUrl}${locale}/404?preview`
} else if (['/internalServerError', '/drafts.internalServerError'].includes(pathname)) {
url = `${baseUrl}${locale}/500?preview`
} else {
url = `${baseUrl}${locale}${pathname}`
}
Expand Down

0 comments on commit 1bf3d65

Please sign in to comment.