mirror of
https://github.com/mastermindzh/rickvanlieshout.com
synced 2024-12-27 07:18:17 +01:00
33 lines
729 B
TypeScript
33 lines
729 B
TypeScript
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;
|