garmeeh / next-seo

Next SEO is a plug in that makes managing your SEO easier in Next.js projects.
MIT License
7.56k stars 390 forks source link

Multiple meta descriptions adding in deployment #1476

Closed Muralidevan27 closed 3 months ago

Muralidevan27 commented 3 months ago

Describe the bug I am using the common component to update meta data / eslint-disable no-nested-ternary / / eslint-disable simple-import-sort/imports / / eslint-disable react/destructuring-assignment /

'use client';

import { DefaultSeo, NextSeo } from 'next-seo'; import { usePathname } from 'next/navigation';

const favicons: Array<React.ComponentPropsWithoutRef<'link'>> = [ { rel: 'apple-touch-icon', sizes: '192x192', type: 'image/png', href: '/icon-192x192.png', }, { rel: 'icon', href: '/icon-256x256.png', sizes: '256x256', type: 'image/png', }, { rel: 'icon', href: '/icon-384x384.png', sizes: '384x384', type: 'image/png', }, { rel: 'icon', href: '/icon-512x512.png', sizes: '512x512', type: 'image/png', }, { rel: 'manifest', href: '/manifest.json' }, { rel: 'mask-icon', href: '/favicon/safari-pinned-tab.svg', color: '#00e887', }, { rel: 'shortcut icon', href: '/icon-192x192.png' }, ];

const defaultMeta = { title: 'title', siteName: 'name', description: 'default description', keywords: 'buy medicines online with discount, online medical store, online pharmacy, online pharmacy india, online medicines, order medicines online',

type: 'website', robots: 'follow, index', image: '', };

type SeoProps = { date?: string; templateTitle?: string; templateDescription?: string; templateKeywords?: string; } & Partial;

export default function Seo(props: SeoProps) { const pathname = usePathname(); const meta = { ...defaultMeta, ...props, };

meta.title = props.templateTitle ? ${props.templateTitle} : meta.title; meta.description = typeof window !== 'undefined' && props.templateDescription ? ${props.templateDescription} : meta.description; meta.keywords = props.templateKeywords ? ${props.templateKeywords} : meta.keywords;

const canonicalURL = typeof window !== 'undefined' && meta.url && pathname ? ${meta.url}${pathname} : meta.url && !pathname ? ${meta.url} : null;

const defaultSeoProps: { canonical?: string } = {}; if (canonicalURL) { defaultSeoProps.canonical = canonicalURL; }

return ( <> <DefaultSeo {...defaultSeoProps} /> <NextSeo title={meta.title} description={meta.description} openGraph={{ url: ${meta.url}${pathname}, title: meta.title, description: meta.description, type: meta.type, site_name: meta.siteName, images: meta.image ? [{ url: meta.image }] : undefined, }} additionalMetaTags={[ { name: 'robots', content: meta.robots, }, { name: 'robots', content: meta.robots, }, { name: 'keywords', content: meta.keywords, }, { name: 'twitter:card', content: 'summary_large_image', }, { name: 'twitter:site', content: 'wellness_24X7', }, { name: 'twitter:title', content: meta.title, }, { name: 'twitter:description', content: meta.description, }, { name: 'twitter:image', content: meta.image, }, { name: 'article:published_time', content: meta.date }, { name: 'publish_date', content: meta.date, // property: 'og:publish_date', },

      {
        name: 'msapplication-TileColor',
        content: '#006d3a',
      },
      {
        name: 'msapplication-config',
        content: '/favicon/browserconfig.xml',
      },
      {
        name: 'theme-color',
        content: '#006D3A',
      },
    ]}
  />
  {favicons.map((linkProps) => (
    <link key={linkProps.href} {...linkProps} />
  ))}
</>

); }

But the meta description is not updating eg: if I open one category the description of the category it will show in head tag if i changed to another category the description is not changing its adding one more description in below but SEO taking the first one I have attached reference below same set adding below with updated description image

please provide fix for this

Additional context Add any other context about the problem here.