mirror of
https://github.com/mastermindzh/rickvanlieshout.com
synced 2025-12-07 10:47:37 +01:00
refactor(starter): upgrade to new version of gatsby
This commit is contained in:
33
src/hooks/use-categories-list.ts
Normal file
33
src/hooks/use-categories-list.ts
Normal file
@@ -0,0 +1,33 @@
|
||||
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;
|
||||
Reference in New Issue
Block a user