[site,title,#94]: fix incorrect page titles

Remove next seo from layout and to pages directly.
This commit is contained in:
khalilcodes 2022-03-24 13:16:54 +03:00
parent 13c2234a91
commit 09290d96e8
4 changed files with 18 additions and 23 deletions

View File

@ -1,17 +1,11 @@
import Link from 'next/link'
import Head from 'next/head' import Head from 'next/head'
import { NextSeo } from 'next-seo'
import Nav from './Nav' import Nav from './Nav'
import siteConfig from '../config/siteConfig' import siteConfig from '../config/siteConfig'
import navLinks from '../config/navLinks.js' import navLinks from '../config/navLinks.js'
export default function Layout({ children, title='' }) { export default function Layout({ children }) {
return ( return (
<> <>
<NextSeo
title={title}
/>
<Head> <Head>
<link rel="icon" href="data:image/svg+xml,<svg xmlns=%22http://www.w3.org/2000/svg%22 viewBox=%220 0 100 100%22><text y=%22.9em%22 font-size=%2290%22>🚀</text></svg>" /> <link rel="icon" href="data:image/svg+xml,<svg xmlns=%22http://www.w3.org/2000/svg%22 viewBox=%220 0 100 100%22><text y=%22.9em%22 font-size=%2290%22>🚀</text></svg>" />
<meta charSet="utf-8" /> <meta charSet="utf-8" />

View File

@ -1,7 +1,7 @@
import MdxPage from '../components/MDX'; import MdxPage from '../components/MDX';
import { allOtherPages } from 'contentlayer/generated'; import { allOtherPages } from 'contentlayer/generated';
import { useMDXComponent } from 'next-contentlayer/hooks'; import { useMDXComponent } from 'next-contentlayer/hooks';
import { NewsArticleJsonLd } from 'next-seo'; import { NewsArticleJsonLd, NextSeo } from 'next-seo';
export default function Page({ body, ...rest }) { export default function Page({ body, ...rest }) {
@ -17,8 +17,19 @@ export default function Page({ body, ...rest }) {
tags: rest.tags, 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 ( return (
<MdxPage children={children} /> <>
<NextSeo title={children.frontmatter.title ?? titleFromUrl} />
<MdxPage children={children} />
</>
); );
} }

View File

@ -24,16 +24,6 @@ function MyApp({ Component, pageProps }) {
}, [router.events]) }, [router.events])
} }
// end Google Analytics // 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 ( return (
<ThemeProvider attribute="class" defaultTheme="dark"> <ThemeProvider attribute="class" defaultTheme="dark">
@ -66,7 +56,7 @@ function MyApp({ Component, pageProps }) {
}} }}
/> />
)} )}
<Layout title={pageTitle}> <Layout>
<Component {...pageProps} /> <Component {...pageProps} />
</Layout> </Layout>
</ThemeProvider> </ThemeProvider>

View File

@ -2,16 +2,16 @@ import { Hero } from 'components/Home/Hero'
import { Latest } from 'components/Home/Latest' import { Latest } from 'components/Home/Latest'
import Features from 'components/Home/Features' import Features from 'components/Home/Features'
import Why from 'components/Home/Why' import Why from 'components/Home/Why'
import { NextSeo } from 'next-seo'
export default function Home(props) { export default function Home(props) {
return ( return (
<> <>
<NextSeo title='Home' />
<Hero /> <Hero />
<Latest /> <Latest />
<Features /> <Features />
<Why /> <Why />
</> </>
) )
} }
Home.layout = 'js'