diff --git a/plugins/gatsby-transformer-nz-author/gatsby-node.ts b/plugins/gatsby-transformer-nz-author/gatsby-node.ts index ddd5c69c..0cd34a11 100644 --- a/plugins/gatsby-transformer-nz-author/gatsby-node.ts +++ b/plugins/gatsby-transformer-nz-author/gatsby-node.ts @@ -25,6 +25,7 @@ export const createSchemaCustomization: GatsbyNode["createSchemaCustomization"] lastName: String! nickName: String social: JSON + articles: [Blog] @link(by: "author.slug", from: "slug") } `); }; diff --git a/src/components/articlepreview.tsx b/src/components/articlepreview.tsx index e5d09b10..3290d40c 100644 --- a/src/components/articlepreview.tsx +++ b/src/components/articlepreview.tsx @@ -5,7 +5,7 @@ import { GatsbyImage, ImageDataLike, getImage } from "gatsby-plugin-image"; import { Tag } from "../templates/tags"; -type BlogPostNode = Queries.PreviewDataFragment; +export type BlogPostNode = Queries.PreviewDataFragment; interface PreviewProps { node: BlogPostNode; } diff --git a/src/gatsby-types.d.ts b/src/gatsby-types.d.ts index 095507cd..2915ffe6 100644 --- a/src/gatsby-types.d.ts +++ b/src/gatsby-types.d.ts @@ -35,6 +35,7 @@ type AVIFOptions = { }; type Author = Node & { + readonly articles: Maybe>>; readonly children: ReadonlyArray; readonly firstName: Scalars['String']; readonly gatsbyPath: Maybe; @@ -98,6 +99,7 @@ type AuthorEdge = { }; type AuthorFieldSelector = { + readonly articles: InputMaybe; readonly children: InputMaybe; readonly firstName: InputMaybe; readonly gatsbyPath: InputMaybe; @@ -111,6 +113,7 @@ type AuthorFieldSelector = { }; type AuthorFilterInput = { + readonly articles: InputMaybe; readonly children: InputMaybe; readonly firstName: InputMaybe; readonly gatsbyPath: InputMaybe; @@ -169,6 +172,7 @@ type AuthorGroupConnection_sumArgs = { }; type AuthorSortInput = { + readonly articles: InputMaybe; readonly children: InputMaybe; readonly firstName: InputMaybe; readonly gatsbyPath: InputMaybe; @@ -2130,6 +2134,7 @@ type Query_allSitePluginArgs = { type Query_authorArgs = { + articles: InputMaybe; children: InputMaybe; firstName: InputMaybe; gatsbyPath: InputMaybe; @@ -3144,7 +3149,7 @@ type AuthorInfoByIdQueryVariables = Exact<{ }>; -type AuthorInfoByIdQuery = { readonly author: { readonly firstName: string, readonly lastName: string, readonly nickName: string | null, readonly social: Record | null } | null }; +type AuthorInfoByIdQuery = { readonly author: { readonly firstName: string, readonly lastName: string, readonly nickName: string | null, readonly social: Record | null, readonly articles: ReadonlyArray<{ readonly date: string, readonly excerpt: string | null, readonly slug: string, readonly tags: ReadonlyArray, readonly title: string, readonly heroImage: { readonly alt: string, readonly image: { readonly childImageSharp: { readonly gatsbyImageData: import('gatsby-plugin-image').IGatsbyImageData } | null } | null }, readonly readingTime: { readonly text: string | null } | null } | null> | null } | null }; type BlogPostByIdQueryVariables = Exact<{ id: InputMaybe; diff --git a/src/pages/author/{author.slug}/index.tsx b/src/pages/author/{author.slug}/index.tsx index d3fbfaa3..8b155a56 100644 --- a/src/pages/author/{author.slug}/index.tsx +++ b/src/pages/author/{author.slug}/index.tsx @@ -3,7 +3,8 @@ import * as React from "react"; import { PageProps, graphql } from "gatsby"; import { Icon } from "@iconify-icon/react"; -import { Layout, MDXWrapper } from "~components"; +import { ArticlePreview, Layout, MDXWrapper } from "~components"; +import type { BlogPostNode } from "~components/articlepreview"; type AuthorPageProps = PageProps; @@ -84,10 +85,16 @@ const AuthorPage = ({ data, children }: AuthorPageProps) => { ) : undefined; + const previews = (data.author.articles ? data.author.articles : []) + .filter((article): article is BlogPostNode => article !== null) + .sort((a, b) => (a.date > b.date ? -1 : 1)) + .map((article) => ); + return ( {socialBox} {children} + {previews} ); }; @@ -99,6 +106,9 @@ export const query = graphql` lastName nickName social + articles { + ...PreviewData + } } } `;