Skip to content

Commit

Permalink
refactor: use a fragment for post previews
Browse files Browse the repository at this point in the history
  • Loading branch information
NobbZ committed Jun 27, 2023
1 parent b7a3323 commit f925bb7
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 39 deletions.
27 changes: 25 additions & 2 deletions src/components/articlepreview.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import * as React from "react";

import { Link } from "gatsby";
import { Link, graphql } from "gatsby";
import { GatsbyImage, ImageDataLike, getImage } from "gatsby-plugin-image";

import { Tag } from "../templates/tags";

type BlogPostNode = Queries.BlogPostsQuery["allMdx"]["nodes"][0];
type BlogPostNode = Queries.PreviewDataFragment;
interface PreviewProps {
node: BlogPostNode;
}
Expand Down Expand Up @@ -62,3 +62,26 @@ export const Preview = ({ node }: PreviewProps) => {
</article>
);
};

export const query = graphql`
fragment PreviewData on Mdx {
excerpt
fields {
readingTime {
text
}
}
frontmatter {
date
title
slug
tags
hero_image_alt
hero_image {
childImageSharp {
gatsbyImageData(width: 200)
}
}
}
}
`;
4 changes: 3 additions & 1 deletion src/gatsby-types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2683,6 +2683,8 @@ type GatsbyImageSharpFluid_withWebp_tracedSVGFragment = { readonly tracedSVG: st

type GatsbyImageSharpFluidLimitPresentationSizeFragment = { readonly maxHeight: number, readonly maxWidth: number };

type PreviewDataFragment = { readonly excerpt: string | null, readonly fields: { readonly readingTime: { readonly text: string | null } | null } | null, readonly frontmatter: { readonly date: string, readonly title: string, readonly slug: string, readonly tags: ReadonlyArray<string>, readonly hero_image_alt: string, readonly hero_image: { readonly childImageSharp: { readonly gatsbyImageData: import('gatsby-plugin-image').IGatsbyImageData } | null } | null } };

type SiteTitleQueryVariables = Exact<{ [key: string]: never; }>;


Expand All @@ -2698,7 +2700,7 @@ type TagInfoQueryVariables = Exact<{
}>;


type TagInfoQuery = { readonly allMdx: { readonly totalCount: number, readonly edges: ReadonlyArray<{ readonly node: { readonly id: string, readonly excerpt: string | null, readonly fields: { readonly readingTime: { readonly text: string | null } | null } | null, readonly frontmatter: { readonly hero_image_alt: string, readonly title: string, readonly slug: string, readonly date: string, readonly tags: ReadonlyArray<string>, readonly hero_image: { readonly childImageSharp: { readonly gatsbyImageData: import('gatsby-plugin-image').IGatsbyImageData } | null } | null } } }> } };
type TagInfoQuery = { readonly allMdx: { readonly totalCount: number, readonly edges: ReadonlyArray<{ readonly node: { readonly id: string, readonly excerpt: string | null, readonly fields: { readonly readingTime: { readonly text: string | null } | null } | null, readonly frontmatter: { readonly date: string, readonly title: string, readonly slug: string, readonly tags: ReadonlyArray<string>, readonly hero_image_alt: string, readonly hero_image: { readonly childImageSharp: { readonly gatsbyImageData: import('gatsby-plugin-image').IGatsbyImageData } | null } | null } } }> } };

type TagListQueryVariables = Exact<{ [key: string]: never; }>;

Expand Down
19 changes: 1 addition & 18 deletions src/pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,25 +22,8 @@ export const query = graphql`
query BlogPosts {
allMdx(sort: { frontmatter: { date: DESC } }) {
nodes {
fields {
readingTime {
text
}
}
frontmatter {
date
title
slug
tags
hero_image_alt
hero_image {
childImageSharp {
gatsbyImageData(width: 200)
}
}
}
id
excerpt
...PreviewData
}
}
}
Expand Down
19 changes: 1 addition & 18 deletions src/templates/tags.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -90,24 +90,7 @@ export const pageQuery = graphql`
edges {
node {
id
excerpt
fields {
readingTime {
text
}
}
frontmatter {
hero_image_alt
hero_image {
childImageSharp {
gatsbyImageData(width: 200)
}
}
title
slug
date
tags
}
...PreviewData
}
}
}
Expand Down

0 comments on commit f925bb7

Please sign in to comment.