From 0b5b688ecec8088ab3e76dc757ca4caeb7c1ffbe Mon Sep 17 00:00:00 2001 From: Khalil Ali <42637597+khalilcodes@users.noreply.github.com> Date: Mon, 21 Mar 2022 18:12:59 +0300 Subject: [PATCH 001/103] [site/theme]: Added page titles fixes #82. Note this works by getting the page path (slug) and unparsing it e.g. '/claims' => Claims. 'notes-on-neometallism' => 'Notes on neometallism'. In future, we may have title explicitly set in the front matter (or otherwise) and we can use that. --- site/pages/_app.js | 34 +++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/site/pages/_app.js b/site/pages/_app.js index d4d9c71..12d0531 100644 --- a/site/pages/_app.js +++ b/site/pages/_app.js @@ -11,9 +11,9 @@ import MdxPage from '../components/MDX' import * as gtag from '../lib/gtag' function MyApp({ Component, pageProps }) { + const router = useRouter() // Google Analytics if (siteConfig.analytics) { - const router = useRouter() useEffect(() => { const handleRouteChange = (url) => { gtag.pageview(url) @@ -25,23 +25,31 @@ function MyApp({ Component, pageProps }) { }, [router.events]) } // end Google Analytics + + const pageTitle = ( + router.pathname == "/" + ? "home" + // convert slug to title + : router.pathname.split("/").pop().replace(/-/g, " ") + ) // capitalize first char of each word + .replace(/(^\w{1})|(\s{1}\w{1})/g, (str) => str.toUpperCase()); return ( {/* Global Site Tag (gtag.js) - Google Analytics */} - {siteConfig.analytics && + {siteConfig.analytics && (