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

feat: next seo poc #2619

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Changes from 1 commit
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
21 changes: 13 additions & 8 deletions packages/core/src/pages/s.tsx
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -26,6 +26,7 @@ import { getPage, SearchContentType } from 'src/server/cms'
type Props = {
page: SearchContentType
globalSections: GlobalSectionsData
searchTerm: string
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question: should it be optional? or receive a default value in line 58?


export interface SearchPageContextType {
Expand Down Expand Up @@ -54,13 +55,13 @@ const useSearchParams = ({
}, [asPath, defaultSort])
}

function Page({ page: searchContentType, globalSections }: Props) {
function Page({ page: searchContentType, globalSections, searchTerm }: Props) {
const { settings } = searchContentType

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Risk: Affected versions of next are vulnerable to Acceptance of Extraneous Untrusted Data With Trusted Data / Authorization Bypass Through User-Controlled Key.

Fix: Upgrade this library to at least version 13.5.7 at faststore/yarn.lock:13689.

Reference(s): GHSA-gp8f-8m3g-qvj9, CVE-2024-46982

💬 To ignore this, reply with:
/fp <comment> for false positive
/ar <comment> for acceptable risk
/other <comment> for all other reasons
Alternatively, triage in Semgrep AppSec Platform to ignore the finding created by ssc-adb055b9-fed0-4d70-a57d-eb9825b09449.

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
Expand All @@ -78,8 +79,8 @@ function Page({ page: searchContentType, globalSections }: Props) {
{/* SEO */}
<NextSeo
noindex
title={title}
description={description}
title={`${searchTerm}`}
description={`${searchTerm}: em promoção que você procura? Na Americanas você encontra as melhores ofertas de produtos com entrega rápida. Vem!`}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
title={`${searchTerm}`}
title={searchTerm}

titleTemplate={titleTemplate}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dúvida, esse conteúdo aqui o merchant consegue customizar no repositorio dele sem reescrever toda a pagina?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Em teoria sim, mas preciso validar. Pretendo mudar isso no código antes de mergear.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

acho que aqui podemos fazer algo similar ao que o NextSeo faz com title e titleTemplate para tornar dinâmico, mas adaptando para description (e criando um desciptionTemplate) com replace.

templateDescription.replace(/%s/g, () => updatedDescription);

openGraph={{
type: 'website',
Expand Down Expand Up @@ -114,11 +115,14 @@ function Page({ page: searchContentType, globalSections }: Props) {
)
}

export const getStaticProps: GetStaticProps<
export const getServerSideProps: GetServerSideProps<
Props,
Record<string, string>,
Locator
> = async ({ previewData }) => {
> = async (context) => {
const { previewData, query } = context

const searchTerm = query.q as string
const globalSections = await getGlobalSectionsData(previewData)

if (storeConfig.cms.data) {
Expand All @@ -133,7 +137,7 @@ export const getStaticProps: GetStaticProps<
})

return {
props: { page: pageData, globalSections },
props: { page: pageData, globalSections, searchTerm },
}
}
}
Expand All @@ -147,6 +151,7 @@ export const getStaticProps: GetStaticProps<
props: {
page,
globalSections,
searchTerm,
},
}
}
Expand Down
Loading