mirror of
				https://github.com/mastermindzh/rickvanlieshout.com
				synced 2025-10-31 16:49:49 +01:00 
			
		
		
		
	
		
			
				
	
	
		
			31 lines
		
	
	
		
			712 B
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
			
		
		
	
	
			31 lines
		
	
	
		
			712 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: { frontmatter: { date: DESC } }
 | |
|       ) {
 | |
|         group(field: { frontmatter: { category: SELECT } }) {
 | |
|           fieldValue
 | |
|           totalCount
 | |
|         }
 | |
|       }
 | |
|     }
 | |
|   `);
 | |
| 
 | |
|   return result?.data?.allMarkdownRemark?.group ?? [];
 | |
| };
 | |
| 
 | |
| export default categoriesQuery;
 |