From 30255b572c28d93e4ee14151d2b7007460f1b4a2 Mon Sep 17 00:00:00 2001 From: Pedro Soares Date: Tue, 21 Jan 2025 16:55:15 -0300 Subject: [PATCH] feat: test next-seo with server side rendering --- packages/core/src/pages/s.tsx | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/packages/core/src/pages/s.tsx b/packages/core/src/pages/s.tsx index 5e8187ff60..f128d99e41 100644 --- a/packages/core/src/pages/s.tsx +++ b/packages/core/src/pages/s.tsx @@ -1,4 +1,4 @@ -import type { GetStaticProps } from 'next' +import type { GetServerSideProps } from 'next' import { NextSeo } from 'next-seo' import { useRouter } from 'next/router' import { useMemo } from 'react' @@ -26,6 +26,7 @@ import { getPage, SearchContentType } from 'src/server/cms' type Props = { page: SearchContentType globalSections: GlobalSectionsData + searchTerm: string } export interface SearchPageContextType { @@ -54,13 +55,13 @@ const useSearchParams = ({ }, [asPath, defaultSort]) } -function Page({ page: searchContentType, globalSections }: Props) { +function Page({ page: searchContentType, globalSections, searchTerm }: Props) { const { settings } = searchContentType const applySearchState = useApplySearchState() const searchParams = useSearchParams({ sort: settings?.productGallery?.sortBySelection as SearchState['sort'], }) - + console.log({ searchTerm }) const title = 'Search Results' const { description, titleTemplate } = storeConfig.seo const itemsPerPage = settings?.productGallery?.itemsPerPage ?? ITEMS_PER_PAGE @@ -78,8 +79,8 @@ function Page({ page: searchContentType, globalSections }: Props) { {/* SEO */} , Locator -> = async ({ previewData }) => { +> = async (context) => { + const { previewData, query } = context + + const searchTerm = query.q as string const globalSections = await getGlobalSectionsData(previewData) if (storeConfig.cms.data) { @@ -133,7 +137,7 @@ export const getStaticProps: GetStaticProps< }) return { - props: { page: pageData, globalSections }, + props: { page: pageData, globalSections, searchTerm }, } } } @@ -147,6 +151,7 @@ export const getStaticProps: GetStaticProps< props: { page, globalSections, + searchTerm, }, } }