diff --git a/studio/schemas/objects/titleAndMeta.tsx b/studio/schemas/objects/titleAndMeta.tsx index c670f7c17..f52124217 100644 --- a/studio/schemas/objects/titleAndMeta.tsx +++ b/studio/schemas/objects/titleAndMeta.tsx @@ -5,6 +5,7 @@ import { TextArea, Label, Box } from '@sanity/ui' // eslint-disable-next-line import/no-unresolved import PatchEvent, { set } from 'part:@sanity/form-builder/patch-event' import { SchemaType } from '../../types' +import { Rule } from '@sanity/types' //const createPatchFrom = (value) => PatchEvent.from(value === '' ? unset() : set(value)) type TextAreaWithCharsProps = { @@ -21,8 +22,8 @@ const TextAreaWithChars = forwardRef { - onChange(PatchEvent.from(set(event.target.value))) + (event: React.FormEvent) => { + onChange(PatchEvent.from(set((event.target as HTMLTextAreaElement).value))) }, [onChange], ) @@ -44,7 +45,7 @@ export default { title: 'Fields for title and description meta', name: 'titleAndMeta', type: 'object', - validation: (Rule: any) => [Rule.required().warning(`Please pay attention to SEO`)], + validation: (Rule: Rule) => [Rule.required().warning('Please pay attention to SEO')], fields: [ { name: 'documentTitle', @@ -60,7 +61,7 @@ export default { { name: 'metaDescription', title: 'Meta description', - validation: (Rule: any) => [ + validation: (Rule: Rule) => [ Rule.required().warning('Meta description is important for SEO'), Rule.max(160).warning('Google recommends max. 160 chars'), ], diff --git a/web/pages/_middleware.ts b/web/pages/_middleware.ts index f91138318..12bc9625e 100644 --- a/web/pages/_middleware.ts +++ b/web/pages/_middleware.ts @@ -4,6 +4,7 @@ import { NextRequest, NextResponse } from 'next/server' import { getLocaleFromName } from '../lib/localization' import { hasArchivedNews, isGlobal } from '../common/helpers/datasetHelpers' import { getDocumentBySlug } from '../common/helpers/getPaths' +import archivedNews from '../lib/archive/archivedNewsPaths.json' const PERMANENT_REDIRECT = 301 const TEMPORARY_REDIRECT = 302 @@ -47,7 +48,11 @@ export async function middleware(request: NextRequest) { // Redirect external links to news which is now archived if link doesn't exist in Sanity if (hasArchivedNews && pathname.startsWith('/news') && !pathname.startsWith('/news/archive')) { const existsInSanity = await pathExistsInSanity(pathname, isPreview) - if (!existsInSanity) return NextResponse.redirect(`${origin}${pathname.replace('news', 'news/archive')}`) + if (!existsInSanity) { + const archivedPath = pathname.replace('news', 'news/archive') + const existsInArchive = archivedNews.some((e) => e.slug === archivedPath) + if (existsInArchive) return NextResponse.redirect(`${origin}${archivedPath}`) + } } // Redirect to the same url lowercased if necessary diff --git a/web/pages/news/archive/[...pagePath].tsx b/web/pages/news/archive/[...pagePath].tsx index dd7751e5a..d6d11b8e7 100644 --- a/web/pages/news/archive/[...pagePath].tsx +++ b/web/pages/news/archive/[...pagePath].tsx @@ -21,6 +21,7 @@ import { SkipNavContent } from '@reach/skip-nav' import { hasArchivedNews, isGlobal } from '../../../common/helpers/datasetHelpers' import { getFullUrl } from '../../../common/helpers/getFullUrl' import { filterDataToSingleItem } from '../../../lib/filterDataToSingleItem' +import archivedNews from '../../../lib/archive/archivedNewsPaths.json' import type { MenuData, SimpleMenuData } from '../../../types/types' import { FormattedMessage } from 'react-intl' @@ -176,6 +177,9 @@ export const getStaticProps: GetStaticProps = async ({ preview = false, params, const pagePathArray = params?.pagePath as string[] const pagePath = pagePathArray.join('/') + const existsInArchive = archivedNews.some((e) => e.slug === `/news/archive/${pagePath}`) + if (!existsInArchive) return { notFound: true } + const response = await fetchArchiveData(pagePathArray, pagePath, locale) const pageData = response ? await parseResponse(response) : false