-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into reference/directives-reference
- Loading branch information
Showing
12 changed files
with
295 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
--- | ||
title: Crystallize 与 Astro | ||
description: 使用 Crystallize 作为 CMS 向你的 Astro 项目添加内容 | ||
type: cms | ||
stub: true | ||
service: Crystallize | ||
i18nReady: true | ||
--- | ||
[Crystallize](https://crystallize.com/) 是一个面向电子商务的 headless 内容管理系统,提供 GraphQL API 接口。 | ||
## 示例 | ||
|
||
```astro title="src/pages/index.astro" | ||
--- | ||
// 从 Crystallize 的 GraphQL API 获取目录路径 | ||
import BaseLayout from '../../layouts/BaseLayout.astro'; | ||
import { createClient } from '@crystallize/js-api-client'; | ||
const apiClient = createClient({ | ||
tenantIdentifier: 'furniture' | ||
}); | ||
const query = ` | ||
query getCataloguePaths{ | ||
catalogue(language: "en", path: "/shop") { | ||
name | ||
children { | ||
name | ||
path | ||
} | ||
} | ||
} | ||
` | ||
const { data: { catalogue } } = await apiClient.catalogueApi(query) | ||
--- | ||
<BaseLayout> | ||
<h1>{catalogue.name}</h1> | ||
<nav> | ||
<ul> | ||
{catalogue.children.map(child => ( | ||
<li><a href={child.path}>{child.name}</a></li> | ||
))} | ||
</ul> | ||
</nav> | ||
</BaseLayout> | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
--- | ||
title: Directus 与 Astro | ||
description: 使用 Directus 作为 CMS 为你的 Astro 项目添加内容 | ||
type: cms | ||
stub: true | ||
service: Directus | ||
i18nReady: true | ||
--- | ||
|
||
[Directus](https://directus.io/) 是一个 BaaS(后端即服务),可用于为你的 Astro 项目托管数据和内容。 | ||
|
||
## 官方资源 | ||
- 查看官方指南:[使用 Directus 开始构建 Astro 网站](https://directus.io/guides/get-started-building-an-astro-website-with-directus/)。 | ||
- Directus 提供了一个[示例 Astro 博客模板](https://github.com/directus/examples/tree/main/astro)。 | ||
|
||
## 社区资源 | ||
|
||
- 添加你的资源! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
--- | ||
title: Hygraph 与 Astro | ||
description: 使用 Hygraph 作为 CMS 将內容添加到你的 Astro 项目 | ||
type: cms | ||
service: Hygraph | ||
i18nReady: true | ||
--- | ||
import FileTree from '~/components/FileTree.astro' | ||
|
||
[Hygraph](https://hygraph.com/) 是一个无头的 CMS(Content Management System,内容管理系统)。它提供了一个用于 Astro 获取内容的 GraphQL 端点。 | ||
|
||
## 与 Astro 集成 | ||
|
||
在本节中,你将创建一个 [Hygraph](https://hygraph.com/) GraphQL 端点以供 Astro 使用。 | ||
|
||
### 前置准备 | ||
|
||
在开始使用之前,你需要: | ||
|
||
1. **一个 Hygraph 账号和项目** - 如果你还没有账号,你可以 [免费注册](https://app.hygraph.com/signup) 并创建一个项目。 | ||
|
||
2. **Hygraph 访问权限** - 在 `Project Settings > API Access` 中,配置 Public Content API 权限以允许无需身份验证的内容读取请求。如果你还没有设置任何权限,你可以点击 **Yes, initialize defaults** 来添加使用 "High Performance Content API" 所需的权限。 | ||
|
||
### 配置端点 | ||
|
||
在你的项目的根目录中创建或编辑一个 `.env` 文件,并添加以下变量以将你的 Hygraph 端点连接到 Astro: | ||
|
||
```ini title=".env" | ||
HYGRAPH_ENDPOINT=YOUR_HIGH_PERFORMANCE_API | ||
``` | ||
|
||
现在,你应该能够在你的项目中使用这个环境变量了。 | ||
|
||
如果你希望让你的环境变量拥有智能提示(IntelliSense),你可以在 `src/` 目录下创建或编辑 `env.d.ts` 文件,并像这样配置 `ImportMetaEnv`: | ||
|
||
```ts title="src/env.d.ts" | ||
interface ImportMetaEnv { | ||
readonly HYGRAPH_ENDPOINT: string; | ||
} | ||
``` | ||
|
||
:::tip[提示] | ||
了解更多关于[使用环境变量](/zh-cn/guides/environment-variables/)和 Astro 中的 `.env` 文件的信息。 | ||
::: | ||
|
||
你的根目录现在应该包含以下新文件: | ||
|
||
<FileTree title="Project Structure"> | ||
- src/ | ||
- **env.d.ts** | ||
- **.env** | ||
- astro.config.mjs | ||
- package.json | ||
</FileTree> | ||
|
||
### 获取数据 | ||
|
||
使用 `HYGRAPH_ENDPOINT` 从你的 Hygraph 项目中获取数据。 | ||
|
||
例如,要获取具有字符串字段 `title` 的 `blogPosts` 内容类型的条目,请创建一个 GraphQL 查询来获取该内容。然后,定义内容的类型,并将其设置为响应的类型。 | ||
|
||
```astro title="src/pages/index.astro" | ||
--- | ||
interface Post { | ||
title: string; | ||
} | ||
const query = { | ||
method: "POST", | ||
headers: { "Content-Type": "application/json" }, | ||
body: JSON.stringify({ | ||
query: ` | ||
{ | ||
blogPosts { | ||
title | ||
} | ||
}`, | ||
}), | ||
}; | ||
const response = await fetch(import.meta.env.HYGRAPH_ENDPOINT, query); | ||
const json = await response.json(); | ||
const posts: Post[] = json.data.blogPosts; | ||
--- | ||
<html lang="en"> | ||
<head> | ||
<meta charset="utf-8" /> | ||
<link rel="icon" type="image/svg+xml" href="/favicon.svg" /> | ||
<meta name="viewport" content="width=device-width" /> | ||
<meta name="generator" content={Astro.generator} /> | ||
<title>Astro</title> | ||
</head> | ||
<body> | ||
<h1>Astro</h1> | ||
{ | ||
posts.map((post) => ( | ||
<div> | ||
<h2>{post.title}</h2> | ||
</div> | ||
)) | ||
} | ||
</body> | ||
</html> | ||
``` | ||
|
||
## 部署 | ||
|
||
### 配置 Netlify Webhook | ||
|
||
在 Netlify 中设置 Webhook: | ||
|
||
1. 使用 [部署指南](/zh-cn/guides/deploy/netlify/) 将你的网站部署到 Netlify。并记得将你的 `HYGRAPH_ENDPOINT` 添加到环境变量中。 | ||
|
||
2. 然后转到你的 Hygraph 项目 dashboard 并单击 **Apps**。 | ||
|
||
3. 点击 <kbd>Go to Marketplace</kbd> 跳转到应用市场,搜索并选择 Netlify 并按照提供的说明进行后续操作。 | ||
|
||
4. 如果一切顺利,现在你只要在 Hygraph 界面中点击一下就能部署你的网站了。 | ||
|
||
## 社区资源 | ||
|
||
- [使用 `marked` 进行 markdown 解析的 Hygraph + Astro 示例](https://github.com/camunoz2/example-astrowithhygraph)。 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
--- | ||
title: KeystoneJS 与 Astro | ||
description: 使用 KeystoneJS 作为 CMS 将內容添加到你的 Astro 项目 | ||
type: cms | ||
stub: true | ||
service: KeystoneJS | ||
i18nReady: true | ||
--- | ||
|
||
[KeystoneJS](https://keystonejs.com/) 是一个开源无头的 CMS(Content Management System,内容管理系统)。只需描述你的数据结构,即可使用 KeystoneJS 的 GraphQL API 和数据管理界面。 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
src/content/docs/zh-cn/reference/errors/collection-does-not-exist-error.mdx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
--- | ||
title: Collection does not exist | ||
i18nReady: true | ||
githubURL: https://github.com/withastro/astro/blob/main/packages/astro/src/core/errors/errors-data.ts | ||
--- | ||
|
||
> 通过 `getCollection()` 查询的集合不存在。 | ||
## 哪里发生了错误? | ||
|
||
当查询集合时,请确保 `src/content/` 下存在一个和请求名称同名的集合目录。 |
15 changes: 15 additions & 0 deletions
15
src/content/docs/zh-cn/reference/errors/content-collection-type-mismatch-error.mdx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
--- | ||
title: Collection contains entries of a different type. | ||
i18nReady: true | ||
githubURL: https://github.com/withastro/astro/blob/main/packages/astro/src/core/errors/errors-data.ts | ||
--- | ||
|
||
> `COLLECTION_NAME` 包含 `ACTUAL_TYPE` 类型的条目,但却配置为 `EXPECTED_TYPE` 集合。 | ||
## 哪里发生了错误? | ||
|
||
内容集合必须包含所配置的类型。默认类型为 `type: 'content'`。试着为数据集合添加 `type: 'data'` 的类型。 | ||
|
||
**请参阅:** | ||
|
||
- [定义内容集合](/zh-cn/guides/content-collections/#defining-collections) |
11 changes: 11 additions & 0 deletions
11
src/content/docs/zh-cn/reference/errors/data-collection-entry-parse-error.mdx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
--- | ||
title: Data collection entry failed to parse. | ||
i18nReady: true | ||
githubURL: https://github.com/withastro/astro/blob/main/packages/astro/src/core/errors/errors-data.ts | ||
--- | ||
|
||
> `COLLECTION_ENTRY_NAME` 解析失败。 | ||
## 哪里发生了错误? | ||
|
||
`type: 'data'` 的集合条目必须返回一个包含有效 JSON(对于 `.json` 条目)或 YAML(对于 `.yaml` 条目)的对象。 |
11 changes: 11 additions & 0 deletions
11
src/content/docs/zh-cn/reference/errors/duplicate-content-entry-slug-error.mdx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
--- | ||
title: Duplicate content entry slug. | ||
i18nReady: true | ||
githubURL: https://github.com/withastro/astro/blob/main/packages/astro/src/core/errors/errors-data.ts | ||
--- | ||
|
||
> `COLLECTION_NAME` 包含多个相同的 `SLUG` 条目。Slug 必须是唯一的。 | ||
## 哪里发生了错误? | ||
|
||
内容集合条目必须具有唯一的 slug。通常是由 `slug` frontmatter 属性引起的重复。 |
15 changes: 15 additions & 0 deletions
15
src/content/docs/zh-cn/reference/errors/mixed-content-data-collection-error.mdx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
--- | ||
title: Content and data cannot be in same collection. | ||
i18nReady: true | ||
githubURL: https://github.com/withastro/astro/blob/main/packages/astro/src/core/errors/errors-data.ts | ||
--- | ||
|
||
> `COLLECTION_NAME` 同时包含了内容和数据条目。所有条目必须是相同的类型。 | ||
## 哪里发生了错误? | ||
|
||
一个内容集合不能同时包含内容和数据条目。必须按类型将条目存储在单独的集合中。 | ||
|
||
**请参阅:** | ||
|
||
- [定义内容集合](/zh-cn/guides/content-collections/#defining-collections) |
15 changes: 15 additions & 0 deletions
15
src/content/docs/zh-cn/reference/errors/unsupported-config-transform-error.mdx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
--- | ||
title: Unsupported transform in content config. | ||
i18nReady: true | ||
githubURL: https://github.com/withastro/astro/blob/main/packages/astro/src/core/errors/errors-data.ts | ||
--- | ||
|
||
> **UnsupportedConfigTransformError**: 内容配置中的 `transform()` 函数必须返回有效的 JSON,或者与 devalue 库兼容的数据类型(包括 Dates、Maps 和 Sets)。\n完整错误:PARSE_ERROR | ||
## 哪里发生了错误? | ||
|
||
内容配置中的 `transform()` 函数必须返回有效的 JSON,或者与 devalue 库兼容的数据类型(包括 Dates、Maps 和 Sets)。 | ||
|
||
**请参阅:** | ||
|
||
- [devalue 库](https://github.com/rich-harris/devalue) |