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