Skip to content
This repository was archived by the owner on Feb 27, 2024. It is now read-only.

Commit 75b1685

Browse files
committed
Merge branch '33-rename-post-archive' into develop
2 parents 90d9f01 + c5b78f6 commit 75b1685

File tree

17 files changed

+330
-393
lines changed

17 files changed

+330
-393
lines changed

api/wordpress/_global/getPostTypeStaticPaths.js

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,16 +45,19 @@ export default async function getPostTypeStaticPaths(postType) {
4545
// Process paths.
4646
const paths = !posts?.data?.[pluralName]?.edges
4747
? []
48-
: posts.data[pluralName].edges.map((post) => {
49-
// Trim leading and trailing slashes then split into array on inner slashes.
50-
const slug = post.node[pathField].replace(/^\/|\/$/g, '').split('/')
48+
: posts.data[pluralName].edges
49+
.map((post) => {
50+
// Trim leading and trailing slashes then split into array on inner slashes.
51+
const slug = post.node[pathField].replace(/^\/|\/$/g, '').split('/')
5152

52-
return {
53-
params: {
54-
slug
53+
return {
54+
params: {
55+
slug
56+
}
5557
}
56-
}
57-
})
58+
})
59+
// Filter out certain posts with custom routes (e.g., homepage).
60+
.filter((post) => !!post.params.slug.join('/').length)
5861

5962
return {
6063
paths,

api/wordpress/_global/getPostTypeStaticProps.js

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,22 @@ export default async function getPostTypeStaticProps(
4545
slug
4646
)
4747

48+
const props = {
49+
post,
50+
error,
51+
errorMessage
52+
}
53+
54+
// Custom handling for homepage.
55+
if (error) {
56+
// Fallback to empty props if homepage not set in WP.
57+
props.post = null
58+
props.error = false
59+
}
60+
4861
// Merge in query results as Apollo state.
4962
return addApolloState(apolloClient, {
50-
props: {
51-
post,
52-
error,
53-
errorMessage
54-
},
63+
props,
5564
revalidate: 60 * 5
5665
})
5766
}

api/wordpress/pages/queryHomepage.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
const {gql} = require('@apollo/client')
2+
const {singlePageFragment} = require('./queryPageById')
3+
4+
// Query: retrieve homepage.
5+
const queryHomepage = gql`
6+
query GET_HOMEPAGE($imageSize: MediaItemSizeEnum = LARGE) {
7+
homepageSettings {
8+
frontPage {
9+
...SinglePageFields
10+
}
11+
}
12+
}
13+
${singlePageFragment}
14+
`
15+
16+
export default queryHomepage

api/wordpress/pages/queryPageById.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import featuredImagePostFields from '../_partials/featuredImagePostFields'
66
const {gql} = require('@apollo/client')
77

88
// Fragment: retrieve single page fields.
9-
const singlePageFragment = gql`
9+
export const singlePageFragment = gql`
1010
fragment SinglePageFields on Page {
1111
${globalPostFields}
1212
blocksJSON

components/common/Layout.js

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,32 @@
1+
import Meta from '@/components/common/Meta'
2+
import Footer from '@/components/organisms/Footer'
3+
import Header from '@/components/organisms/Header'
4+
import {NextSeo} from 'next-seo'
15
import PropTypes from 'prop-types'
2-
import Meta from './Meta'
3-
import Header from '../organisms/Header'
4-
import Footer from '../organisms/Footer'
5-
import config from '@/functions/config'
66

77
export default function Layout({children, ...props}) {
88
return (
99
<>
10-
<Meta title={props.title} description={props.description} />
10+
<NextSeo
11+
title={props?.title}
12+
description={props?.description}
13+
openGraph={props?.openGraph}
14+
nofollow={props?.noFollow}
15+
noindex={props?.noIndex}
16+
/>
17+
<Meta />
1118
<Header />
1219
<main>{children}</main>
1320
<Footer />
1421
</>
1522
)
1623
}
1724

18-
Layout.defaultProps = {
19-
description: config.siteDescription,
20-
title: config.siteName
21-
}
22-
2325
Layout.propTypes = {
24-
children: PropTypes.object.isRequired,
25-
description: PropTypes.string,
26-
title: PropTypes.string
26+
children: PropTypes.any.isRequired,
27+
description: PropTypes.string.isRequired,
28+
noFollow: PropTypes.bool,
29+
noIndex: PropTypes.bool,
30+
openGraph: PropTypes.object,
31+
title: PropTypes.string.isRequired
2732
}

components/common/Meta.js

Lines changed: 1 addition & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,10 @@
1-
import config from '@/functions/config'
21
import Head from 'next/head'
3-
import PropTypes from 'prop-types'
42

5-
export default function Meta(props) {
3+
export default function Meta() {
64
return (
75
<Head>
8-
<title>
9-
{props.title} - {props.description}
10-
</title>
116
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
127
<meta httpEquiv="x-ua-compatible" content="ie=edge" />
13-
<meta name="description" content={props.description} />
148
<meta name="msapplication-TileColor" content="#fffff" />
159
<meta name="msapplication-config" content="/favicon/browserconfig.xml" />
1610
<meta name="theme-color" content="#fff" />
@@ -33,34 +27,6 @@ export default function Meta(props) {
3327
/>
3428
<link rel="manifest" href="/favicon/site.webmanifest" />
3529
<link rel="shortcut icon" href="/favicon/favicon.ico" />
36-
<meta name="twitter:card" content="summary" />
37-
<meta name="twitter:url" content={config.siteUrl} />
38-
<meta name="twitter:title" content={props.title} />
39-
<meta name="twitter:description" content={props.description} />
40-
<meta
41-
name="twitter:image"
42-
content={`${config.siteUrl}/favicon/android-icon-192x192.png`}
43-
/>
44-
<meta name="twitter:creator" content={config.author} />
45-
<meta property="og:type" content="website" />
46-
<meta property="og:title" content={props.title} />
47-
<meta property="og:description" content={props.description} />
48-
<meta property="og:site_name" content={props.title} />
49-
<meta property="og:url" content={config.siteUrl} />
50-
<meta
51-
property="og:image"
52-
content={`${config.siteUrl}/favicon/apple-icon.png`}
53-
/>
5430
</Head>
5531
)
5632
}
57-
58-
Meta.defaultProps = {
59-
title: config.siteName,
60-
description: config.siteDescription
61-
}
62-
63-
Meta.propTypes = {
64-
title: PropTypes.string,
65-
description: PropTypes.string
66-
}

functions/config.js

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,7 @@ const config = {
33
siteDescription: 'The description of this website',
44
siteUrl: 'https://website.vercel.app',
55
author: '@yourname',
6-
navigation: [
7-
{label: 'Home', href: '/'},
8-
{label: 'About', href: '/about'},
9-
{label: 'Apollo', href: '/apollo'},
10-
{label: 'SSG', href: '/ssg'},
11-
{label: 'SSR', href: '/ssr'},
12-
{label: 'ISR', href: '/isr'}
13-
],
6+
navigation: [{label: 'HOOK UP WP NAV MENU', href: '/'}],
147
social: {
158
github: {
169
label: 'Github',

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,9 @@
5959
"eslint-plugin-react": "^7.22.0",
6060
"eslint-plugin-react-hooks": "^4.2.0",
6161
"graphql": "^15.4.0",
62-
"husky": "^4.3.6",
62+
"husky": "^4.3.7",
6363
"lint-staged": "^10.5.3",
64+
"next-seo": "^4.17.0",
6465
"next-sitemap": "^1.3.29",
6566
"postcss-flexbugs-fixes": "^4.2.1",
6667
"postcss-preset-env": "^6.7.0",

pages/[...slug].js

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
import Layout from '@/components/common/Layout'
2-
import {Info} from '@/components/molecules/Alert'
3-
import PropTypes from 'prop-types'
41
import getPostTypeStaticPaths from '@/api/wordpress/_global/getPostTypeStaticPaths'
52
import getPostTypeStaticProps from '@/api/wordpress/_global/getPostTypeStaticProps'
3+
import Layout from '@/components/common/Layout'
4+
import PropTypes from 'prop-types'
65

76
// Define route post type.
87
const postType = 'page'
@@ -16,15 +15,23 @@ const postType = 'page'
1615
*/
1716
export default function Page({post}) {
1817
return (
19-
<Layout title={post?.title} description={post?.excerpt}>
18+
<Layout
19+
title="Query from Yoast SEO"
20+
description="Query from Yoast SEO"
21+
noIndex={false} // query from yoast seo
22+
noFollow={false} // query from yoast seo
23+
openGraph={{
24+
title: 'Query from Yoast SEO',
25+
description: 'Query from Yoast SEO',
26+
images: [
27+
{
28+
url: 'Query from Yoast SEO',
29+
alt: 'Query from Yoast SEO'
30+
}
31+
]
32+
}}
33+
>
2034
<div className="container">
21-
<Info>
22-
The content below is sourced from the WordPress REST-API.{' '}
23-
<a href="https://nextjs.org/docs/basic-features/data-fetching#getstaticpaths-static-generation">
24-
Learn more about SSG.
25-
</a>
26-
</Info>
27-
2835
<section>
2936
<article>
3037
<h1 dangerouslySetInnerHTML={{__html: post?.title}} />

pages/_app.js

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
import PropTypes from 'prop-types'
1+
import {useApollo} from '@/api/apolloConfig'
22
import '@/styles/index.css'
33
import {ApolloProvider} from '@apollo/client'
4+
import {DefaultSeo} from 'next-seo'
45
import Error from 'next/error'
5-
import {useApollo} from '@/api/apolloConfig'
6+
import PropTypes from 'prop-types'
67

78
export default function App({Component, pageProps}) {
89
/**
@@ -23,7 +24,29 @@ export default function App({Component, pageProps}) {
2324
{error ? (
2425
<Error statusCode={500} title={errorMessage} />
2526
) : (
26-
<Component {...pageProps} />
27+
<>
28+
<DefaultSeo
29+
title="Query from Yoast SEO"
30+
description="Query from Yoast SEO"
31+
noIndex={false} // query from yoast seo
32+
noFollow={false} // query from yoast seo
33+
openGraph={{
34+
type: 'website',
35+
locale: 'en_US',
36+
url: 'Query from Yoast SEO',
37+
site_name: '',
38+
images: [
39+
{
40+
url: 'Query from Yoast SEO',
41+
width: 'Query from Yoast SEO',
42+
height: 'Query from Yoast SEO',
43+
alt: 'Query from Yoast SEO'
44+
}
45+
]
46+
}}
47+
/>
48+
<Component {...pageProps} />
49+
</>
2750
)}
2851
</ApolloProvider>
2952
)

0 commit comments

Comments
 (0)