Skip to content

Commit

Permalink
Initial setup for migration to Next app instead of pages
Browse files Browse the repository at this point in the history
  • Loading branch information
bluprince13 committed May 27, 2024
1 parent 58bdc24 commit 7ffdcd9
Show file tree
Hide file tree
Showing 7 changed files with 175 additions and 61 deletions.
46 changes: 46 additions & 0 deletions src/app/AppBody.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { ThemeProvider, StyledEngineProvider } from '@mui/material/styles'
import CssBaseline from '@mui/material/CssBaseline'
import theme from '@Modules/theme'
import '@Styles/globals.css'
import { SpeedInsights } from '@vercel/speed-insights/next'

import { StateProvider } from '@Modules/store'
import { GoogleAnalytics } from '@Components/GoogleAnalytics'
import SearchAppBar from '@Components/SearchAppBar/SearchAppBar'
import Footer from '@Components/Footer'
const Layout = ({ children }) => (
<div
style={{
display: 'flex',
minHeight: '100vh',
flexDirection: 'column'
}}
>
{children}
</div>
)

const Content = ({ children }) => {
return <div style={{ padding: '1rem' }}>{children}</div>
}

export const AppBody = ({ children }: { children: React.ReactNode }) => {
return (
<>
<GoogleAnalytics />
<StyledEngineProvider injectFirst>
<ThemeProvider theme={theme}>
<CssBaseline />
<StateProvider>
<Layout>
<SearchAppBar />
<Content>{children}</Content>
<Footer />
<SpeedInsights />
</Layout>
</StateProvider>
</ThemeProvider>
</StyledEngineProvider>
</>
)
}
19 changes: 19 additions & 0 deletions src/app/layout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import '@Styles/globals.css'
import { AppBody } from '@App/AppBody'
import { siteMetadata } from '@Modules/metadata'

export const metadata = siteMetadata

export default function RootLayout({
children
}: {
children: React.ReactNode
}) {
return (
<html lang="en">
<body>
<AppBody>{children}</AppBody>
</body>
</html>
)
}
24 changes: 24 additions & 0 deletions src/components/GoogleAnalytics.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
'use client';

import ReactGA from 'react-ga'
import { useEffect } from 'react'

export const initGA = () => {
ReactGA.initialize('UA-35322373-3', { debug: false })
}

export const logPageView = () => {
ReactGA.set({ page: window.location.pathname })
ReactGA.pageview(window.location.pathname)
}

export const GoogleAnalytics = () => {
useEffect(() => {
if (!window.GA_INITIALIZED) {
initGA()
window.GA_INITIALIZED = true
}
logPageView()
})
return null
}
3 changes: 3 additions & 0 deletions src/components/StandardSeo.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ import { NextSeo } from 'next-seo'

const SITE_ROOT = 'https://bluprince13.com'

/**
* @deprecated Use generateMetadata instead.
*/
const StandardSeo = ({ pageTitle, description, path, bannerPath }) => {
const title = `${pageTitle} - Vipin Ajayakumar`
const url = `${SITE_ROOT}${path}`
Expand Down
10 changes: 0 additions & 10 deletions src/modules/googleAnalytics.js

This file was deleted.

78 changes: 78 additions & 0 deletions src/modules/metadata.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
import { Metadata } from 'next'

const SITE_ROOT = 'https://bluprince13.com'
const title = 'bluprince13'
const description = 'Full-stack web developer'

export const siteMetadata: Metadata = {
title,
description,
alternates: {
canonical: SITE_ROOT,
// TODO: Support multiple RSS feeds
// https://github.com/vercel/next.js/discussions/62365
types: {
'application/rss+xml': `${SITE_ROOT}/feed.xml`
}
},
openGraph: {
type: 'website',
locale: 'en_GB',
url: SITE_ROOT,
title,
description,
images: [
{
url: `${SITE_ROOT}/photo.jpg`,
alt: title
}
]
},
twitter: {
creator: '@vipinajayakumar',
site: '@vipinajayakumar',
card: 'summary_large_image'
}
}

interface MetadataProps {
pageTitle: string
description: string
path: string
bannerPath?: string
}

export const generateMetadata = ({
pageTitle,
description,
path,
bannerPath
}: MetadataProps): Metadata => {
const title = `${pageTitle} - Vipin Ajayakumar`
const url = `${SITE_ROOT}${path}`
const featuredImage = bannerPath ? `${SITE_ROOT}${bannerPath}` : null

return {
title,
description,
openGraph: {
url,
title,
description,
images: featuredImage
? [
{
url: featuredImage,
alt: title
}
]
: []
},
twitter: {
card: 'summary_large_image',
title,
description,
images: featuredImage ? [featuredImage] : []
}
}
}
56 changes: 5 additions & 51 deletions src/pages/_app.js
Original file line number Diff line number Diff line change
@@ -1,46 +1,12 @@
import { useEffect } from 'react'
import Head from 'next/head'
import { useEffect } from 'react'
import { DefaultSeo } from 'next-seo'

import { ThemeProvider, StyledEngineProvider } from '@mui/material/styles';
import CssBaseline from '@mui/material/CssBaseline'
import theme from '@Modules/theme'
import '@Styles/globals.css'
import { SpeedInsights } from '@vercel/speed-insights/next'

import { StateProvider } from '@Modules/store'
import { initGA, logPageView } from '@Modules/googleAnalytics'
import SearchAppBar from '@Components/SearchAppBar/SearchAppBar'
import Footer from '@Components/Footer'
import { AppBody } from 'src/app/AppBody'
import SEO from '@Modules/seo.config'

const Layout = ({ children }) => (
<div
style={{
display: 'flex',
minHeight: '100vh',
flexDirection: 'column'
}}
>
{children}
</div>
)

const Content = ({ children }) => {
return <div style={{ padding: '1rem' }}>{children}</div>
}

function MyApp({ Component, pageProps }) {
useEffect(() => {
if (!window.GA_INITIALIZED) {
initGA()
window.GA_INITIALIZED = true
}
logPageView()
})

useEffect(() => {
// Remove the server-side injected CSS.
const jssStyles = document.querySelector('#jss-server-side')
if (jssStyles) {
jssStyles.parentElement.removeChild(jssStyles)
Expand Down Expand Up @@ -75,21 +41,9 @@ function MyApp({ Component, pageProps }) {
/>
</Head>
<DefaultSeo {...SEO} />
<StyledEngineProvider injectFirst>
<ThemeProvider theme={theme}>
<CssBaseline />
<StateProvider>
<Layout>
<SearchAppBar />
<Content>
<Component {...pageProps} />
</Content>
<Footer />
<SpeedInsights />
</Layout>
</StateProvider>
</ThemeProvider>
</StyledEngineProvider>
<AppBody>
<Component {...pageProps} />
</AppBody>
</>
)
}
Expand Down

1 comment on commit 7ffdcd9

@vercel
Copy link

@vercel vercel bot commented on 7ffdcd9 May 27, 2024

Choose a reason for hiding this comment

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

Please sign in to comment.