凯西与 Astro
Caisy 是一个无头 CMS,它公开 GraphQL API 来访问内容。
¥Caisy is a headless CMS that exposes a GraphQL API to access content.
将 Caisy CMS 与 Astro 结合使用
标题部分 将 Caisy CMS 与 Astro 结合使用¥Using Caisy CMS with Astro
使用 graphql-request
和 Caisy 的 Astro 富文本渲染器来获取你的 CMS 数据并在 Astro 页面上显示你的内容:
¥Use graphql-request
and Caisy’s rich text renderer for Astro to fetch your CMS data and display your content on an Astro page:
---import RichTextRenderer from '@caisy/rich-text-astro-renderer';import { gql, GraphQLClient } from 'graphql-request';
const params = Astro.params;
const client = new GraphQLClient( `https://cloud.caisy.io/api/v3/e/${import.meta.env.CAISY_PROJECT_ID}/graphql`, { headers: { 'x-caisy-apikey': import.meta.env.CAISY_API_KEY } });const gqlResponse = await client.request( gql` query allBlogArticle($slug: String) { allBlogArticle(where: { slug: { eq: $slug } }) { edges { node { text { json } title slug id } } } } `, { slug: params.slug });
const post = gqlResponse?.allBlogArticle?.edges?.[0]?.node;---<h1>{post.title}</h1><RichTextRenderer node={post.text.json} />
官方资源
标题部分 官方资源¥Official Resources
-
查看 GitHub 或 StackBlitz 上的 Caisy + Astro 示例
-
使用 pagination 查询大量文档。