Skip to content

Commit

Permalink
Merge branch 'main' into renovate/major-eslint-monorepo
Browse files Browse the repository at this point in the history
  • Loading branch information
MikuroXina authored Sep 3, 2024
2 parents 65f1a00 + dcfcd41 commit e430a71
Show file tree
Hide file tree
Showing 6 changed files with 356 additions and 58 deletions.
67 changes: 24 additions & 43 deletions gatsby-node.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { type GatsbyNode, type NodeInput } from "gatsby";
import { getAllBlogs } from "./src/lib/blog-fetch";
import { getMembers } from "./src/lib/member-fetch";
import path from "path";

Expand All @@ -19,6 +20,23 @@ export const sourceNodes: GatsbyNode["sourceNodes"] = async (api) => {
} satisfies NodeInput;
api.actions.createNode(node);
}

const blogs = await getAllBlogs();
for (const blog of blogs) {
const id = api.createNodeId(blog.slug);
const node = {
...blog,
id,
_id: blog.slug,
parent: null,
children: [],
internal: {
type: "Blog",
contentDigest: api.createContentDigest(blog),
},
} satisfies NodeInput;
api.actions.createNode(node);
}
};

export const createSchemaCustomization: GatsbyNode["createSchemaCustomization"] = (api) => {
Expand All @@ -40,45 +58,7 @@ export const createSchemaCustomization: GatsbyNode["createSchemaCustomization"]
};

export const createPages: GatsbyNode["createPages"] = async (api) => {
const res = await api.graphql<{
allMarkdownRemark: {
nodes: {
rawMarkdownBody: string;
frontmatter: {
title: string;
author: string;
authorId: string;
date: string;
};
parent: {
name: string;
};
}[];
};
}>(`
{
allMarkdownRemark(sort: { frontmatter: { date: ASC } }) {
nodes {
rawMarkdownBody
frontmatter {
title
author
authorId
date
}
parent {
... on File {
name
}
}
}
}
}
`);
if (res.errors) {
api.reporter.error("querying markdown pages failed");
return;
}
const pages = await getAllBlogs();

Check failure

Code scanning / CodeQL

Assignment to constant Error

Assignment to variable pages, which is
declared
constant.

const pages = res.data?.allMarkdownRemark.nodes;

Check failure

Code scanning / CodeQL

Assignment to constant Error

Assignment to variable pages, which is
declared
constant.
if (!pages) {
Expand All @@ -87,16 +67,17 @@ export const createPages: GatsbyNode["createPages"] = async (api) => {
}

const component = path.resolve("src/templates/blog-post.tsx");
api.reporter.info(`generating ${pages.length} pages`);
for (let i = 0; i < pages.length; ++i) {
const slug = path.basename(pages[i].parent.name);
const prevSlug = i > 0 ? path.basename(pages[i - 1].parent.name) : null;
const nextSlug = i < pages.length - 1 ? path.basename(pages[i + 1].parent.name) : null;
const slug = pages[i].slug;
const prevSlug = i > 0 ? path.basename(pages[i - 1].slug) : null;
const nextSlug = i < pages.length - 1 ? path.basename(pages[i + 1].slug) : null;
api.actions.createPage({
path: `/blog/${slug}`,
component,
context: {
slug,
content: pages[i].rawMarkdownBody,
content: pages[i].markdownBody,
frontmatter: pages[i].frontmatter,
prevSlug,
nextSlug,
Expand Down
190 changes: 189 additions & 1 deletion src/gatsby-types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,172 @@ type Scalars = {
JSON: Record<string, unknown>;
};

type Blog = Node & {
readonly _id: Maybe<Scalars['String']>;
readonly children: ReadonlyArray<Node>;
readonly frontmatter: Maybe<BlogFrontmatter>;
readonly id: Scalars['ID'];
readonly internal: Internal;
readonly markdownBody: Maybe<Scalars['String']>;
readonly parent: Maybe<Node>;
readonly slug: Maybe<Scalars['String']>;
};

type BlogConnection = {
readonly distinct: ReadonlyArray<Scalars['String']>;
readonly edges: ReadonlyArray<BlogEdge>;
readonly group: ReadonlyArray<BlogGroupConnection>;
readonly max: Maybe<Scalars['Float']>;
readonly min: Maybe<Scalars['Float']>;
readonly nodes: ReadonlyArray<Blog>;
readonly pageInfo: PageInfo;
readonly sum: Maybe<Scalars['Float']>;
readonly totalCount: Scalars['Int'];
};


type BlogConnection_distinctArgs = {
field: BlogFieldSelector;
};


type BlogConnection_groupArgs = {
field: BlogFieldSelector;
limit: InputMaybe<Scalars['Int']>;
skip: InputMaybe<Scalars['Int']>;
};


type BlogConnection_maxArgs = {
field: BlogFieldSelector;
};


type BlogConnection_minArgs = {
field: BlogFieldSelector;
};


type BlogConnection_sumArgs = {
field: BlogFieldSelector;
};

type BlogEdge = {
readonly next: Maybe<Blog>;
readonly node: Blog;
readonly previous: Maybe<Blog>;
};

type BlogFieldSelector = {
readonly _id: InputMaybe<FieldSelectorEnum>;
readonly children: InputMaybe<NodeFieldSelector>;
readonly frontmatter: InputMaybe<BlogFrontmatterFieldSelector>;
readonly id: InputMaybe<FieldSelectorEnum>;
readonly internal: InputMaybe<InternalFieldSelector>;
readonly markdownBody: InputMaybe<FieldSelectorEnum>;
readonly parent: InputMaybe<NodeFieldSelector>;
readonly slug: InputMaybe<FieldSelectorEnum>;
};

type BlogFilterInput = {
readonly _id: InputMaybe<StringQueryOperatorInput>;
readonly children: InputMaybe<NodeFilterListInput>;
readonly frontmatter: InputMaybe<BlogFrontmatterFilterInput>;
readonly id: InputMaybe<StringQueryOperatorInput>;
readonly internal: InputMaybe<InternalFilterInput>;
readonly markdownBody: InputMaybe<StringQueryOperatorInput>;
readonly parent: InputMaybe<NodeFilterInput>;
readonly slug: InputMaybe<StringQueryOperatorInput>;
};

type BlogFrontmatter = {
readonly author: Maybe<Scalars['String']>;
readonly authorId: Maybe<Scalars['String']>;
readonly date: Maybe<Scalars['Date']>;
readonly title: Maybe<Scalars['String']>;
};


type BlogFrontmatter_dateArgs = {
difference: InputMaybe<Scalars['String']>;
formatString: InputMaybe<Scalars['String']>;
fromNow: InputMaybe<Scalars['Boolean']>;
locale: InputMaybe<Scalars['String']>;
};

type BlogFrontmatterFieldSelector = {
readonly author: InputMaybe<FieldSelectorEnum>;
readonly authorId: InputMaybe<FieldSelectorEnum>;
readonly date: InputMaybe<FieldSelectorEnum>;
readonly title: InputMaybe<FieldSelectorEnum>;
};

type BlogFrontmatterFilterInput = {
readonly author: InputMaybe<StringQueryOperatorInput>;
readonly authorId: InputMaybe<StringQueryOperatorInput>;
readonly date: InputMaybe<DateQueryOperatorInput>;
readonly title: InputMaybe<StringQueryOperatorInput>;
};

type BlogFrontmatterSortInput = {
readonly author: InputMaybe<SortOrderEnum>;
readonly authorId: InputMaybe<SortOrderEnum>;
readonly date: InputMaybe<SortOrderEnum>;
readonly title: InputMaybe<SortOrderEnum>;
};

type BlogGroupConnection = {
readonly distinct: ReadonlyArray<Scalars['String']>;
readonly edges: ReadonlyArray<BlogEdge>;
readonly field: Scalars['String'];
readonly fieldValue: Maybe<Scalars['String']>;
readonly group: ReadonlyArray<BlogGroupConnection>;
readonly max: Maybe<Scalars['Float']>;
readonly min: Maybe<Scalars['Float']>;
readonly nodes: ReadonlyArray<Blog>;
readonly pageInfo: PageInfo;
readonly sum: Maybe<Scalars['Float']>;
readonly totalCount: Scalars['Int'];
};


type BlogGroupConnection_distinctArgs = {
field: BlogFieldSelector;
};


type BlogGroupConnection_groupArgs = {
field: BlogFieldSelector;
limit: InputMaybe<Scalars['Int']>;
skip: InputMaybe<Scalars['Int']>;
};


type BlogGroupConnection_maxArgs = {
field: BlogFieldSelector;
};


type BlogGroupConnection_minArgs = {
field: BlogFieldSelector;
};


type BlogGroupConnection_sumArgs = {
field: BlogFieldSelector;
};

type BlogSortInput = {
readonly _id: InputMaybe<SortOrderEnum>;
readonly children: InputMaybe<NodeSortInput>;
readonly frontmatter: InputMaybe<BlogFrontmatterSortInput>;
readonly id: InputMaybe<SortOrderEnum>;
readonly internal: InputMaybe<InternalSortInput>;
readonly markdownBody: InputMaybe<SortOrderEnum>;
readonly parent: InputMaybe<NodeSortInput>;
readonly slug: InputMaybe<SortOrderEnum>;
};

type BooleanQueryOperatorInput = {
readonly eq: InputMaybe<Scalars['Boolean']>;
readonly in: InputMaybe<ReadonlyArray<InputMaybe<Scalars['Boolean']>>>;
Expand Down Expand Up @@ -1214,6 +1380,7 @@ type PageInfo = {
};

type Query = {
readonly allBlog: BlogConnection;
readonly allDirectory: DirectoryConnection;
readonly allFile: FileConnection;
readonly allMarkdownRemark: MarkdownRemarkConnection;
Expand All @@ -1223,6 +1390,7 @@ type Query = {
readonly allSiteFunction: SiteFunctionConnection;
readonly allSitePage: SitePageConnection;
readonly allSitePlugin: SitePluginConnection;
readonly blog: Maybe<Blog>;
readonly directory: Maybe<Directory>;
readonly file: Maybe<File>;
readonly markdownRemark: Maybe<MarkdownRemark>;
Expand All @@ -1235,6 +1403,14 @@ type Query = {
};


type Query_allBlogArgs = {
filter: InputMaybe<BlogFilterInput>;
limit: InputMaybe<Scalars['Int']>;
skip: InputMaybe<Scalars['Int']>;
sort: InputMaybe<ReadonlyArray<InputMaybe<BlogSortInput>>>;
};


type Query_allDirectoryArgs = {
filter: InputMaybe<DirectoryFilterInput>;
limit: InputMaybe<Scalars['Int']>;
Expand Down Expand Up @@ -1307,6 +1483,18 @@ type Query_allSitePluginArgs = {
};


type Query_blogArgs = {
_id: InputMaybe<StringQueryOperatorInput>;
children: InputMaybe<NodeFilterListInput>;
frontmatter: InputMaybe<BlogFrontmatterFilterInput>;
id: InputMaybe<StringQueryOperatorInput>;
internal: InputMaybe<InternalFilterInput>;
markdownBody: InputMaybe<StringQueryOperatorInput>;
parent: InputMaybe<NodeFilterInput>;
slug: InputMaybe<StringQueryOperatorInput>;
};


type Query_directoryArgs = {
absolutePath: InputMaybe<StringQueryOperatorInput>;
accessTime: InputMaybe<DateQueryOperatorInput>;
Expand Down Expand Up @@ -2314,7 +2502,7 @@ type StringQueryOperatorInput = {
type BlogEntriesQueryVariables = Exact<{ [key: string]: never; }>;


type BlogEntriesQuery = { readonly allMarkdownRemark: { readonly nodes: ReadonlyArray<{ readonly id: string, readonly frontmatter: { readonly title: string | null, readonly date: string | null, readonly author: string | null, readonly authorId: string | null } | null, readonly parent: { readonly name: string } | {} | null }> } };
type BlogEntriesQuery = { readonly allBlog: { readonly nodes: ReadonlyArray<{ readonly slug: string | null, readonly frontmatter: { readonly title: string | null, readonly date: string | null, readonly author: string | null, readonly authorId: string | null } | null }> } };

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

Expand Down
Loading

0 comments on commit e430a71

Please sign in to comment.