-
Notifications
You must be signed in to change notification settings - Fork 103
Expand file tree
/
Copy path_app.tsx
More file actions
83 lines (76 loc) · 2.37 KB
/
_app.tsx
File metadata and controls
83 lines (76 loc) · 2.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import App from 'next/app';
import Head from 'next/head';
import Router from 'next/router';
import NProgress from 'nprogress';
import Layout from '../components/layout';
import { getHeaderRes, getFooterRes, getAllEntries } from '../helper';
import 'nprogress/nprogress.css';
import '../styles/third-party.css';
import '../styles/style.css';
import 'react-loading-skeleton/dist/skeleton.css';
import '@contentstack/live-preview-utils/dist/main.css';
import { Props } from "../typescript/pages";
Router.events.on('routeChangeStart', () => NProgress.start());
Router.events.on('routeChangeComplete', () => NProgress.done());
Router.events.on('routeChangeError', () => NProgress.done());
function MyApp(props: Props) {
const { Component, pageProps, header, footer, entries } = props;
const { page, posts, archivePost, blogPost } = pageProps;
const metaData = (seo: any) => {
const metaArr = [];
for (const key in seo) {
if (seo.enable_search_indexing) {
metaArr.push(
<meta
name={
key.includes('meta_')
? key.split('meta_')[1].toString()
: key.toString()
}
content={seo[key].toString()}
key={key}
/>
);
}
}
return metaArr;
};
const blogList: any = posts?.concat(archivePost);
return (
<>
<Head>
<meta
name='application-name'
content='Contentstack-Nextjs-Starter-App'
/>
<meta charSet='utf-8' />
<meta httpEquiv='X-UA-Compatible' content='IE=edge' />
<meta
name='viewport'
content='width=device-width,initial-scale=1,minimum-scale=1'
/>
<meta name='theme-color' content='#317EFB' />
<title>Cheerios</title>
{page?.seo && page.seo.enable_search_indexing && metaData(page.seo)}
</Head>
<Layout
header={header}
footer={footer}
page={page}
blogPost={blogPost}
blogList={blogList}
entries={entries}
>
<Component {...pageProps} />
</Layout>
</>
);
}
MyApp.getInitialProps = async (appContext: any) => {
const appProps = await App.getInitialProps(appContext);
const header = await getHeaderRes();
const footer = await getFooterRes();
const entries = await getAllEntries();
return { ...appProps, header, footer, entries };
};
export default MyApp;