Skip to content

Commit

Permalink
feature: add list of articles to author
Browse files Browse the repository at this point in the history
  • Loading branch information
NobbZ committed Jul 2, 2023
1 parent 8049053 commit d5de445
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 3 deletions.
1 change: 1 addition & 0 deletions plugins/gatsby-transformer-nz-author/gatsby-node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export const createSchemaCustomization: GatsbyNode["createSchemaCustomization"]
lastName: String!
nickName: String
social: JSON
articles: [Blog] @link(by: "author.slug", from: "slug")
}
`);
};
Expand Down
2 changes: 1 addition & 1 deletion src/components/articlepreview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
7 changes: 6 additions & 1 deletion src/gatsby-types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ type AVIFOptions = {
};

type Author = Node & {
readonly articles: Maybe<ReadonlyArray<Maybe<Blog>>>;
readonly children: ReadonlyArray<Node>;
readonly firstName: Scalars['String'];
readonly gatsbyPath: Maybe<Scalars['String']>;
Expand Down Expand Up @@ -98,6 +99,7 @@ type AuthorEdge = {
};

type AuthorFieldSelector = {
readonly articles: InputMaybe<BlogFieldSelector>;
readonly children: InputMaybe<NodeFieldSelector>;
readonly firstName: InputMaybe<FieldSelectorEnum>;
readonly gatsbyPath: InputMaybe<FieldSelectorEnum>;
Expand All @@ -111,6 +113,7 @@ type AuthorFieldSelector = {
};

type AuthorFilterInput = {
readonly articles: InputMaybe<BlogFilterListInput>;
readonly children: InputMaybe<NodeFilterListInput>;
readonly firstName: InputMaybe<StringQueryOperatorInput>;
readonly gatsbyPath: InputMaybe<StringQueryOperatorInput>;
Expand Down Expand Up @@ -169,6 +172,7 @@ type AuthorGroupConnection_sumArgs = {
};

type AuthorSortInput = {
readonly articles: InputMaybe<BlogSortInput>;
readonly children: InputMaybe<NodeSortInput>;
readonly firstName: InputMaybe<SortOrderEnum>;
readonly gatsbyPath: InputMaybe<SortOrderEnum>;
Expand Down Expand Up @@ -2130,6 +2134,7 @@ type Query_allSitePluginArgs = {


type Query_authorArgs = {
articles: InputMaybe<BlogFilterListInput>;
children: InputMaybe<NodeFilterListInput>;
firstName: InputMaybe<StringQueryOperatorInput>;
gatsbyPath: InputMaybe<StringQueryOperatorInput>;
Expand Down Expand Up @@ -3144,7 +3149,7 @@ type AuthorInfoByIdQueryVariables = Exact<{
}>;


type AuthorInfoByIdQuery = { readonly author: { readonly firstName: string, readonly lastName: string, readonly nickName: string | null, readonly social: Record<string, unknown> | null } | null };
type AuthorInfoByIdQuery = { readonly author: { readonly firstName: string, readonly lastName: string, readonly nickName: string | null, readonly social: Record<string, unknown> | null, readonly articles: ReadonlyArray<{ readonly date: string, readonly excerpt: string | null, readonly slug: string, readonly tags: ReadonlyArray<string>, 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<Scalars['String']>;
Expand Down
12 changes: 11 additions & 1 deletion src/pages/author/{author.slug}/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<Queries.AuthorInfoByIdQuery>;

Expand Down Expand Up @@ -84,10 +85,16 @@ const AuthorPage = ({ data, children }: AuthorPageProps) => {
</div>
) : 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) => <ArticlePreview node={article} key={article.slug} />);

return (
<Layout pageTitle={title}>
{socialBox}
<MDXWrapper>{children}</MDXWrapper>
{previews}
</Layout>
);
};
Expand All @@ -99,6 +106,9 @@ export const query = graphql`
lastName
nickName
social
articles {
...PreviewData
}
}
}
`;
Expand Down

0 comments on commit d5de445

Please sign in to comment.