-
-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
68e9245
commit fda0984
Showing
6 changed files
with
235 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import config from '@/lib/config' | ||
import getCategoryBySlug from '@/lib/queries/getCategoryBySlug' | ||
import {Metadata} from 'next' | ||
import Image from 'next/image' | ||
import Link from 'next/link' | ||
import {notFound} from 'next/navigation' | ||
|
||
/** | ||
* Generate the metadata for each static route at build time. | ||
* | ||
* @see https://nextjs.org/docs/app/api-reference/functions/generate-metadata#generatemetadata-function | ||
*/ | ||
export async function generateMetadata({ | ||
params | ||
}: { | ||
params: {slug: string} | ||
}): Promise<Metadata | null> { | ||
const slug = params.slug | ||
|
||
return { | ||
title: `${slug} Archives - ${config.siteName}`, | ||
description: `The post archive for ${slug}` | ||
} | ||
} | ||
|
||
/** | ||
* The category archive route. | ||
* | ||
* @see https://nextjs.org/docs/app/building-your-application/routing/pages-and-layouts#pages | ||
*/ | ||
export default async function CategoryArchive({ | ||
params | ||
}: { | ||
params: {slug: string} | ||
}) { | ||
// Fetch posts from WordPress. | ||
const posts = await getCategoryBySlug(params.slug) | ||
|
||
// No posts? Bail... | ||
if (!posts) { | ||
notFound() | ||
} | ||
|
||
return ( | ||
<main className="flex flex-col gap-8"> | ||
<h1 className="capitalize">Post Category: {params.slug}</h1> | ||
<div className="flex flex-wrap gap-8"> | ||
{posts.map((post) => ( | ||
<article className="w-72" key={post.databaseId}> | ||
<Image | ||
alt={post.featuredImage.node.altText} | ||
height={post.featuredImage.node.mediaDetails.height} | ||
src={post.featuredImage.node.sourceUrl} | ||
width={post.featuredImage.node.mediaDetails.width} | ||
priority={true} | ||
/> | ||
<Link href={`/blog/${post.slug}`}> | ||
<h2 dangerouslySetInnerHTML={{__html: post.title}} /> | ||
</Link> | ||
<p className="text-sm text-gray-500"> | ||
{post.commentCount} Comments | ||
</p> | ||
<div dangerouslySetInnerHTML={{__html: post.excerpt}} /> | ||
<Link className="button" href={`/blog/${post.slug}`}> | ||
View Post | ||
</Link> | ||
</article> | ||
))} | ||
</div> | ||
</main> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import config from '@/lib/config' | ||
import getTagBySlug from '@/lib/queries/getTagBySlug' | ||
import {Metadata} from 'next' | ||
import Image from 'next/image' | ||
import Link from 'next/link' | ||
import {notFound} from 'next/navigation' | ||
|
||
/** | ||
* Generate the metadata for each static route at build time. | ||
* | ||
* @see https://nextjs.org/docs/app/api-reference/functions/generate-metadata#generatemetadata-function | ||
*/ | ||
export async function generateMetadata({ | ||
params | ||
}: { | ||
params: {slug: string} | ||
}): Promise<Metadata | null> { | ||
const slug = params.slug | ||
|
||
return { | ||
title: `${slug} Archives - ${config.siteName}`, | ||
description: `The post archive for ${slug}` | ||
} | ||
} | ||
|
||
/** | ||
* The tag archive route. | ||
* | ||
* @see https://nextjs.org/docs/app/building-your-application/routing/pages-and-layouts#pages | ||
*/ | ||
export default async function TagArchive({params}: {params: {slug: string}}) { | ||
// Fetch posts from WordPress. | ||
const posts = await getTagBySlug(params.slug) | ||
|
||
// No posts? Bail... | ||
if (!posts) { | ||
notFound() | ||
} | ||
|
||
return ( | ||
<main className="flex flex-col gap-8"> | ||
<h1 className="capitalize">Post Category: {params.slug}</h1> | ||
<div className="flex flex-wrap gap-8"> | ||
{posts.map((post) => ( | ||
<article className="w-72" key={post.databaseId}> | ||
<Image | ||
alt={post.featuredImage.node.altText} | ||
height={post.featuredImage.node.mediaDetails.height} | ||
src={post.featuredImage.node.sourceUrl} | ||
width={post.featuredImage.node.mediaDetails.width} | ||
priority={true} | ||
/> | ||
<Link href={`/blog/${post.slug}`}> | ||
<h2 dangerouslySetInnerHTML={{__html: post.title}} /> | ||
</Link> | ||
<p className="text-sm text-gray-500"> | ||
{post.commentCount} Comments | ||
</p> | ||
<div dangerouslySetInnerHTML={{__html: post.excerpt}} /> | ||
<Link className="button" href={`/blog/${post.slug}`}> | ||
View Post | ||
</Link> | ||
</article> | ||
))} | ||
</div> | ||
</main> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import {fetchGraphQL} from '@/lib/functions' | ||
import {Post} from '@/lib/types' | ||
|
||
/** | ||
* Fetch a category archive by slug. | ||
*/ | ||
export default async function getCategoryBySlug( | ||
slug: string, | ||
limit: number = 10 | ||
) { | ||
const query = ` | ||
query GetCategoryBySlug($slug: String!) { | ||
posts(where: {categoryName: $slug, status: PUBLISH}, first: ${limit}) { | ||
nodes { | ||
databaseId | ||
date | ||
excerpt(format: RENDERED) | ||
title(format: RENDERED) | ||
featuredImage { | ||
node { | ||
altText | ||
sourceUrl | ||
mediaDetails { | ||
height | ||
width | ||
} | ||
} | ||
} | ||
seo { | ||
metaDesc | ||
title | ||
} | ||
slug | ||
} | ||
} | ||
} | ||
` | ||
|
||
const variables = { | ||
slug: slug | ||
} | ||
|
||
const response = await fetchGraphQL(query, variables) | ||
|
||
return response.data.posts.nodes as Post[] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import {fetchGraphQL} from '@/lib/functions' | ||
import {Post} from '@/lib/types' | ||
|
||
/** | ||
* Fetch a tag archive by slug. | ||
*/ | ||
export default async function getTagBySlug(slug: string, limit: number = 10) { | ||
const query = ` | ||
query GetTagBySlug($slug: String!) { | ||
posts(where: {tag: $slug, status: PUBLISH}, first: ${limit}) { | ||
nodes { | ||
databaseId | ||
date | ||
excerpt(format: RENDERED) | ||
title(format: RENDERED) | ||
featuredImage { | ||
node { | ||
altText | ||
sourceUrl | ||
mediaDetails { | ||
height | ||
width | ||
} | ||
} | ||
} | ||
seo { | ||
metaDesc | ||
title | ||
} | ||
slug | ||
} | ||
} | ||
} | ||
` | ||
|
||
const variables = { | ||
slug: slug | ||
} | ||
|
||
const response = await fetchGraphQL(query, variables) | ||
|
||
return response.data.posts.nodes as Post[] | ||
} |
fda0984
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
nextjs-wordpress – ./
nextjs-wordpress-git-main-gregrickaby.vercel.app
nextjs-wordpress-gregrickaby.vercel.app
nextjswp.com
www.nextjswp.com