rickvanlieshout.com/src/hooks/use-categories-list.ts
2022-04-16 14:53:32 +00:00

34 lines
709 B
TypeScript

import { graphql, useStaticQuery } from "gatsby";
interface CategoriesQueryResult {
allMarkdownRemark: {
group: Array<{
fieldValue: string;
totalCount: number;
}>;
};
}
const useCategoriesList = () => {
const { allMarkdownRemark } = useStaticQuery<CategoriesQueryResult>(
graphql`
query CategoriesListQuery {
allMarkdownRemark(
filter: {
frontmatter: { template: { eq: "post" }, draft: { ne: true } }
}
) {
group(field: frontmatter___category) {
fieldValue
totalCount
}
}
}
`,
);
return allMarkdownRemark.group ?? [];
};
export default useCategoriesList;