From 09290d96e8c2fe75530672f186e1a26e0440b958 Mon Sep 17 00:00:00 2001 From: khalilcodes Date: Thu, 24 Mar 2022 13:16:54 +0300 Subject: [PATCH] [site,title,#94]: fix incorrect page titles Remove next seo from layout and to pages directly. --- site/components/Layout.js | 8 +------- site/pages/[...slug].js | 15 +++++++++++++-- site/pages/_app.js | 12 +----------- site/pages/index.js | 6 +++--- 4 files changed, 18 insertions(+), 23 deletions(-) diff --git a/site/components/Layout.js b/site/components/Layout.js index 80ccedc..723c408 100644 --- a/site/components/Layout.js +++ b/site/components/Layout.js @@ -1,17 +1,11 @@ -import Link from 'next/link' import Head from 'next/head' -import { NextSeo } from 'next-seo' - import Nav from './Nav' import siteConfig from '../config/siteConfig' import navLinks from '../config/navLinks.js' -export default function Layout({ children, title='' }) { +export default function Layout({ children }) { return ( <> - diff --git a/site/pages/[...slug].js b/site/pages/[...slug].js index ce9e33e..683ab6b 100644 --- a/site/pages/[...slug].js +++ b/site/pages/[...slug].js @@ -1,7 +1,7 @@ import MdxPage from '../components/MDX'; import { allOtherPages } from 'contentlayer/generated'; import { useMDXComponent } from 'next-contentlayer/hooks'; -import { NewsArticleJsonLd } from 'next-seo'; +import { NewsArticleJsonLd, NextSeo } from 'next-seo'; export default function Page({ body, ...rest }) { @@ -17,8 +17,19 @@ export default function Page({ body, ...rest }) { tags: rest.tags, } } + + const titleFromUrl = rest._raw.flattenedPath + .split("/") + .pop() + .replace(/-/g, " ") + // capitalize first char of each word + .replace(/(^\w{1})|(\s{1}\w{1})/g, (str) => str.toUpperCase()); + return ( - + <> + + + ); } diff --git a/site/pages/_app.js b/site/pages/_app.js index 6f7d55f..b4da4b1 100644 --- a/site/pages/_app.js +++ b/site/pages/_app.js @@ -24,16 +24,6 @@ function MyApp({ Component, pageProps }) { }, [router.events]) } // end Google Analytics - - const pageTitle = ( - // check if markdown page - Component.name == "Page" - ? pageProps.title ?? - // convert path to title - pageProps._raw.flattenedPath.split("/").pop().replace(/-/g, " ") - : Component.name - ) // capitalize first char of each word - .replace(/(^\w{1})|(\s{1}\w{1})/g, (str) => str.toUpperCase()); return ( @@ -66,7 +56,7 @@ function MyApp({ Component, pageProps }) { }} /> )} - + diff --git a/site/pages/index.js b/site/pages/index.js index b16f1eb..394d44e 100644 --- a/site/pages/index.js +++ b/site/pages/index.js @@ -2,16 +2,16 @@ import { Hero } from 'components/Home/Hero' import { Latest } from 'components/Home/Latest' import Features from 'components/Home/Features' import Why from 'components/Home/Why' +import { NextSeo } from 'next-seo' export default function Home(props) { return ( <> + ) -} - -Home.layout = 'js' \ No newline at end of file +} \ No newline at end of file