2022-01-09 21:12:31 +01:00
|
|
|
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(
|
2023-03-26 23:20:54 +02:00
|
|
|
filter: { frontmatter: { template: { eq: "post" }, draft: { ne: true } } }
|
|
|
|
sort: { frontmatter: { date: DESC } }
|
2022-01-09 21:12:31 +01:00
|
|
|
) {
|
2023-03-26 23:20:54 +02:00
|
|
|
group(field: { frontmatter: { category: SELECT } }) {
|
2022-01-09 21:12:31 +01:00
|
|
|
fieldValue
|
|
|
|
totalCount
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`);
|
|
|
|
|
|
|
|
return result?.data?.allMarkdownRemark?.group ?? [];
|
|
|
|
};
|
|
|
|
|
|
|
|
export default categoriesQuery;
|