Skip to content

Commit c81dd9b

Browse files
authored
Render first post in the index to get ads (#62)
1 parent 5a08033 commit c81dd9b

File tree

3 files changed

+63
-9
lines changed

3 files changed

+63
-9
lines changed

graphql-types.ts

+18-7
Original file line numberDiff line numberDiff line change
@@ -2980,6 +2980,8 @@ export type IQueryAllDirectoryArgs = {
29802980
export type IQuerySiteArgs = {
29812981
buildTime: Maybe<IDateQueryOperatorInput>;
29822982
siteMetadata: Maybe<ISiteSiteMetadataFilterInput>;
2983+
port: Maybe<IIntQueryOperatorInput>;
2984+
host: Maybe<IStringQueryOperatorInput>;
29832985
pathPrefix: Maybe<IStringQueryOperatorInput>;
29842986
mapping: Maybe<ISiteMappingFilterInput>;
29852987
polyfill: Maybe<IBooleanQueryOperatorInput>;
@@ -3139,6 +3141,8 @@ export type IQueryAllSitePluginArgs = {
31393141
export type ISite = INode & {
31403142
buildTime: Maybe<Scalars['Date']>;
31413143
siteMetadata: Maybe<ISiteSiteMetadata>;
3144+
port: Maybe<Scalars['Int']>;
3145+
host: Maybe<Scalars['String']>;
31423146
pathPrefix: Maybe<Scalars['String']>;
31433147
mapping: Maybe<ISiteMapping>;
31443148
polyfill: Maybe<Scalars['Boolean']>;
@@ -3344,6 +3348,8 @@ export type ISiteFieldsEnum =
33443348
'siteMetadata___author' |
33453349
'siteMetadata___siteUrl' |
33463350
'siteMetadata___social___twitter' |
3351+
'port' |
3352+
'host' |
33473353
'pathPrefix' |
33483354
'mapping___MarkdownRemark_frontmatter_author' |
33493355
'polyfill' |
@@ -3437,6 +3443,8 @@ export type ISiteFieldsEnum =
34373443
export type ISiteFilterInput = {
34383444
buildTime: Maybe<IDateQueryOperatorInput>;
34393445
siteMetadata: Maybe<ISiteSiteMetadataFilterInput>;
3446+
port: Maybe<IIntQueryOperatorInput>;
3447+
host: Maybe<IStringQueryOperatorInput>;
34403448
pathPrefix: Maybe<IStringQueryOperatorInput>;
34413449
mapping: Maybe<ISiteMappingFilterInput>;
34423450
polyfill: Maybe<IBooleanQueryOperatorInput>;
@@ -4182,7 +4190,7 @@ export type ISitePluginPluginOptions = {
41824190
disableBgImageOnAlpha: Maybe<Scalars['Boolean']>;
41834191
disableBgImage: Maybe<Scalars['Boolean']>;
41844192
className: Maybe<Scalars['String']>;
4185-
offsetY: Maybe<Scalars['String']>;
4193+
offsetY: Maybe<Scalars['Int']>;
41864194
icon: Maybe<Scalars['String']>;
41874195
isIconAfterHeader: Maybe<Scalars['Boolean']>;
41884196
active: Maybe<Scalars['Boolean']>;
@@ -4247,7 +4255,7 @@ export type ISitePluginPluginOptionsFilterInput = {
42474255
disableBgImageOnAlpha: Maybe<IBooleanQueryOperatorInput>;
42484256
disableBgImage: Maybe<IBooleanQueryOperatorInput>;
42494257
className: Maybe<IStringQueryOperatorInput>;
4250-
offsetY: Maybe<IStringQueryOperatorInput>;
4258+
offsetY: Maybe<IIntQueryOperatorInput>;
42514259
icon: Maybe<IStringQueryOperatorInput>;
42524260
isIconAfterHeader: Maybe<IBooleanQueryOperatorInput>;
42534261
active: Maybe<IBooleanQueryOperatorInput>;
@@ -4327,7 +4335,7 @@ export type ISitePluginPluginOptionsPluginsPluginOptions = {
43274335
disableBgImageOnAlpha: Maybe<Scalars['Boolean']>;
43284336
disableBgImage: Maybe<Scalars['Boolean']>;
43294337
className: Maybe<Scalars['String']>;
4330-
offsetY: Maybe<Scalars['String']>;
4338+
offsetY: Maybe<Scalars['Int']>;
43314339
icon: Maybe<Scalars['String']>;
43324340
isIconAfterHeader: Maybe<Scalars['Boolean']>;
43334341
active: Maybe<Scalars['Boolean']>;
@@ -4353,7 +4361,7 @@ export type ISitePluginPluginOptionsPluginsPluginOptionsFilterInput = {
43534361
disableBgImageOnAlpha: Maybe<IBooleanQueryOperatorInput>;
43544362
disableBgImage: Maybe<IBooleanQueryOperatorInput>;
43554363
className: Maybe<IStringQueryOperatorInput>;
4356-
offsetY: Maybe<IStringQueryOperatorInput>;
4364+
offsetY: Maybe<IIntQueryOperatorInput>;
43574365
icon: Maybe<IStringQueryOperatorInput>;
43584366
isIconAfterHeader: Maybe<IBooleanQueryOperatorInput>;
43594367
active: Maybe<IBooleanQueryOperatorInput>;
@@ -4493,13 +4501,16 @@ export type IBlogIndexQueryVariables = {};
44934501

44944502

44954503
export type IBlogIndexQuery = { site: Maybe<{ siteMetadata: Maybe<Pick<ISiteSiteMetadata, 'title'>> }>, allMarkdownRemark: { edges: Array<{ node: (
4496-
Pick<IMarkdownRemark, 'excerpt'>
4504+
Pick<IMarkdownRemark, 'html' | 'excerpt'>
44974505
& { fields: Maybe<(
44984506
Pick<IMarkdownRemarkFields, 'slug'>
44994507
& { readingTime: Maybe<Pick<IMarkdownRemarkFieldsReadingTime, 'text'>> }
45004508
)>, frontmatter: Maybe<(
4501-
Pick<IMarkdownRemarkFrontmatter, 'date' | 'title' | 'description' | 'tags'>
4502-
& { author: Maybe<Pick<IAuthorYaml, 'id'>> }
4509+
Pick<IMarkdownRemarkFrontmatter, 'title' | 'date' | 'description' | 'tags'>
4510+
& { author: Maybe<(
4511+
Pick<IAuthorYaml, 'id' | 'bio' | 'twitter' | 'github'>
4512+
& { profilepicture: Maybe<{ childImageSharp: Maybe<{ fluid: Maybe<IGatsbyImageSharpFluidFragment> }> }> }
4513+
)> }
45034514
)> }
45044515
) }> }, allAuthorYaml: { nodes: Array<Pick<IAuthorYaml, 'bio' | 'id' | 'twitter' | 'github'>> } };
45054516

src/pages/index.tsx

+44-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ import SEO from "../components/Seo";
66

77
import { IBlogIndexQuery } from "../../graphql-types";
88
import PostCard from "../components/PostCard";
9+
import PaperContainer from "../components/PaperContainer";
10+
import Tags from "../components/Tags";
11+
import Bio from "../components/Bio";
12+
import PostNavigator from "../components/PostNavigator";
913

1014
export interface IProps extends PageProps<IBlogIndexQuery> {}
1115

@@ -14,6 +18,12 @@ export default function BlogIndex(props: IProps) {
1418
const siteTitle = data.site.siteMetadata.title;
1519
const posts = data.allMarkdownRemark.edges;
1620

21+
const firstPost = posts[0]?.node;
22+
const firstPostContent = posts[0]?.node.frontmatter;
23+
const { title, date, author, tags = [] } = firstPostContent;
24+
25+
const previousPost = posts[1]?.node;
26+
1727
return (
1828
<Layout location={props.location} title={siteTitle}>
1929
<div className="space-y-3 p-3 lg:p-20">
@@ -42,6 +52,28 @@ export default function BlogIndex(props: IProps) {
4252
})}
4353
</div>
4454
</div>
55+
56+
<PaperContainer>
57+
<article className="space-y-5">
58+
<Tags tags={tags} />
59+
<header className="pb-3">
60+
<h1> {title} </h1>
61+
<div className="py-3 text-sm text-gray-700 dark:text-light_white">
62+
{`${date}${firstPost.fields.readingTime.text}`}
63+
</div>
64+
<Bio author={author} />
65+
</header>
66+
67+
<section
68+
className="space-y-5 nsj-post-content"
69+
dangerouslySetInnerHTML={{ __html: firstPost.html }}
70+
/>
71+
</article>
72+
73+
<div className="py-4">
74+
<PostNavigator previous={previousPost} />
75+
</div>
76+
</PaperContainer>
4577
</Layout>
4678
);
4779
}
@@ -56,6 +88,7 @@ export const pageQuery = graphql`
5688
allMarkdownRemark(sort: { fields: [frontmatter___date], order: DESC }) {
5789
edges {
5890
node {
91+
html
5992
excerpt
6093
fields {
6194
slug
@@ -64,12 +97,22 @@ export const pageQuery = graphql`
6497
}
6598
}
6699
frontmatter {
67-
date(formatString: "MMMM DD, YYYY")
68100
title
101+
date(formatString: "MMMM DD, YYYY")
69102
description
70103
tags
71104
author {
72105
id
106+
bio
107+
twitter
108+
github
109+
profilepicture {
110+
childImageSharp {
111+
fluid {
112+
...GatsbyImageSharpFluid
113+
}
114+
}
115+
}
73116
}
74117
}
75118
}

src/templates/BlogPost.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ export default function BlogPostTemplate(props: IProps) {
5151
<article className="space-y-5">
5252
<Tags tags={tags} />
5353
<header className="pb-3">
54-
<h1> {post.frontmatter?.title} </h1>
54+
<h1> {title} </h1>
5555
<div className="py-3 text-sm text-gray-700 dark:text-light_white">
5656
{`${post.frontmatter.date}${post.fields.readingTime.text}`}
5757
</div>

0 commit comments

Comments
 (0)