mirror of
https://github.com/mastermindzh/rickvanlieshout.com
synced 2025-07-27 12:42:28 +02:00
refactor(starter): upgrade to new version of gatsby
This commit is contained in:
32
internal/gatsby/queries/categories-query.ts
Normal file
32
internal/gatsby/queries/categories-query.ts
Normal file
@@ -0,0 +1,32 @@
|
||||
import { CreatePagesArgs } from "gatsby";
|
||||
|
||||
interface CategoriesQueryResult {
|
||||
allMarkdownRemark: {
|
||||
group: Array<{
|
||||
fieldValue: string;
|
||||
totalCount: number;
|
||||
}>;
|
||||
};
|
||||
}
|
||||
|
||||
const categoriesQuery = async (graphql: CreatePagesArgs["graphql"]) => {
|
||||
const result = await graphql<CategoriesQueryResult>(`
|
||||
{
|
||||
allMarkdownRemark(
|
||||
filter: {
|
||||
frontmatter: { template: { eq: "post" }, draft: { ne: true } }
|
||||
}
|
||||
sort: { order: DESC, fields: [frontmatter___date] }
|
||||
) {
|
||||
group(field: frontmatter___category) {
|
||||
fieldValue
|
||||
totalCount
|
||||
}
|
||||
}
|
||||
}
|
||||
`);
|
||||
|
||||
return result?.data?.allMarkdownRemark?.group ?? [];
|
||||
};
|
||||
|
||||
export default categoriesQuery;
|
Reference in New Issue
Block a user