Skip to content

Commit

Permalink
Merge branch 'main' into guides/deploy/aws
Browse files Browse the repository at this point in the history
  • Loading branch information
yanthomasdev authored Aug 3, 2023
2 parents 8652d62 + e8f78fe commit 02cb12e
Show file tree
Hide file tree
Showing 33 changed files with 3,171 additions and 241 deletions.
12 changes: 6 additions & 6 deletions src/content/docs/en/guides/deploy/space.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ This guide includes step-by-step instructions for building sites in Space. Both
To push an Astro site to Space, make sure you first:

- Create a [Space account](https://deta.space).
- Install the [Space CLI](https://deta.space/docs/en/basics/cli) and log in.
- Install the [Space CLI](https://deta.space/docs/en/build/reference/cli) and log in.

Create a Space project **inside** the directory of your Astro project. Run the CLI and follow the instructions on the screen.

Expand Down Expand Up @@ -83,17 +83,17 @@ Deploy your project with the following command:
space push
```

This will run the build process and create a new [Space app instance](https://deta.space/docs/en/basics/revisions#testing-changes) where you can access your Astro app.
This will run the build process and create a new [Space app instance](https://deta.space/docs/en/build/fundamentals/development/builder-instance#for-testing) where you can access your Astro app.

By default Space apps are private and are only accessible to you.

If you want to make your app available to others you can use [Public Routes](https://deta.space/docs/en/reference/spacefile#public_routes) to make parts of your app public. Or, you can [create a release](https://deta.space/docs/en/basics/releases) to let others install your app into their own personal cloud.
If you want to make your app available to others you can use [Public Routes](https://deta.space/docs/en/reference/spacefile#public_routes) to make parts of your app public. Or, you can [create a release](https://deta.space/docs/en/publish/releasing#releases) to let others install your app into their own personal cloud.

## Next steps

- [Add more compute to your Space project](https://deta.space/docs/en/basics/micros)
- [Store data for your Space project](https://deta.space/docs/en/basics/data)
- [Launch your Space app](https://deta.space/docs/en/basics/releases)
- [Add more compute to your Space project](https://deta.space/docs/en/build/fundamentals/the-space-runtime/micros#adding-a-micro)
- [Store data for your Space project](https://deta.space/docs/en/build/fundamentals/data-storage#content)
- [Launch your Space app](https://deta.space/docs/en/publish/releasing#releases)

## Examples

Expand Down
2 changes: 1 addition & 1 deletion src/content/docs/ja/concepts/why-astro.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,6 @@ Astroは、他のUIフレームワークや言語よりも複雑でないよう

**Astroは、Webサイトを構築するために必要なものがすべて揃ったオールインワンのWebフレームワークです。** コンポーネント構文、ファイルベースのルーティング、アセットハンドリング、ビルドプロセス、バンドル、最適化、データフェッチなど、Astroにはさまざまな機能が搭載されています。Astroのコア機能だけで、優れたウェブサイトを構築できます。

さらにコントロールが必要な場合は、 [React](https://www.npmjs.com/package/@astrojs/react)[Svelte](https://www.npmjs.com/package/@astrojs/svelte)[Vue](https://www.npmjs.com/package/@astrojs/vue)[Tailwind CSS](https://www.npmjs.com/package/@astrojs/tailwind)[MDX](https://www.npmjs.com/package/@astrojs/mdx)[画像最適化](https://www.npmjs.com/package/@astrojs/image)など、[100以上のインテグレーション](https://astro.build/integrations/)を使用してAstroを拡張できます。[お気に入りのCMSを接続](https://astro.build/integrations/)したり、[お気に入りのホストにデプロイ](/ja/guides/deploy/)するのも、コマンド1つでできます。
さらにコントロールが必要な場合は、 [React](https://www.npmjs.com/package/@astrojs/react)[Svelte](https://www.npmjs.com/package/@astrojs/svelte)[Vue](https://www.npmjs.com/package/@astrojs/vue)[Tailwind CSS](https://www.npmjs.com/package/@astrojs/tailwind)[MDX](https://www.npmjs.com/package/@astrojs/mdx)[画像最適化](https://www.npmjs.com/package/@astrojs/image)など、[100以上のインテグレーション](https://astro.build/integrations/)を使用してAstroを拡張できます。[お気に入りのCMSを接続](/ja/guides/cms/)したり、[お気に入りのホストにデプロイ](/ja/guides/deploy/)するのも、コマンド1つでできます。

AstroはUIにとらわれず、**自分好みのUIフレームワークを持ち込めます(BYOF: Bring Your Own UI Framework)**。React、Preact、Solid、Svelte、Vue、LitはすべてAstroで公式にサポートされています。同じページで異なるフレームワークを混在もでき、将来の移行を容易にし、単一のフレームワークにプロジェクトが固定されるのを防げます。
47 changes: 47 additions & 0 deletions src/content/docs/pl/guides/aliases.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
---
title: Aliasy
description: Wprowadzenie do aliasów z Astro.
i18nReady: true
---

**Alias** jest sposobem na tworzenie skrótów dla twoich importów.

Aliasy mogą ułatwić pracę z kodem zawierającym wiele folderów i relatywnych importów.

```astro title="src/pages/about/company.astro" del="../../components" del="../../assets"
---
import Button from '../../components/controls/Button.astro';
import logoUrl from '../../assets/logo.png?url';
---
```

W tym przykładzie, programista musiałby zrozumieć relację pomiędzy `src/pages/about/company.astro`, `src/components/controls/Button.astro` i `src/assets/logo.png`. Potem, jeśli `company.astro` zmieniłoby swoją lokalizację, importy te także musiałyby zostać zaktualizowane.

Możesz dodać aliasy dla importów w pliku `tsconfig.json` lub `jsconfig.json`.

```json title="tsconfig.json" ins={5-6}
{
"compilerOptions": {
"baseUrl": ".",
"paths": {
"@components/*": ["src/components/*"],
"@assets/*": ["src/assets/*"]
}
}
}
```

:::note
Upewnij się, że `compilerOptions.baseUrl` jest ustawione. Dzięki temu, ścieżki aliasowe będą mogły być rozwiązane.
:::

Dzięki tej zmianie, możesz teraz importować używając aliasów gdziekolwiek w twoim projekcie:

```astro title="src/pages/about/company.astro" ins="@components" ins="@assets"
---
import Button from '@components/controls/Button.astro';
import logoUrl from '@assets/logo.png?url';
---
```

Aliasy te są także automatycznie zintegrowane w [VS Code](https://code.visualstudio.com/docs/languages/jsconfig) i innych edytorach tekstu.
4 changes: 2 additions & 2 deletions src/content/docs/pt-br/core-concepts/routing.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ Você pode definir regras para [redirecionar usuários para páginas permanentem

Você pode especificar um mapeamento de redirecionamentos permanentes na sua configuração do Astro com o valor de `redirects`. Para a maioria dos redirecionamentos, isto é um mapeamento de uma rota antiga para uma nova rota:

```js title="astro.config.mjs" {5, 7-9}
```js title="astro.config.mjs" {4-6}
import { defineConfig } from 'astro/config';

export default defineConfig({
Expand All @@ -251,7 +251,7 @@ Estes redirecionamentos seguem as mesmas regras que rotas baseadas em arquivos.

Usando um adaptador de SSR ou estático, você também pode providenciar um objeto como o valor, te permitindo especificar o código de `status` em adição ao novo destino (`destination`):

```js
```js title="astro.config.mjs" {5-8}
import { defineConfig } from 'astro/config';

export default defineConfig({
Expand Down
6 changes: 3 additions & 3 deletions src/content/docs/zh-cn/core-concepts/routing.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ const { title, text } = page;

在你的 Astro 配置中,你可以使用 `redirects` 值来指定永久重定向的映射关系。对于大多数重定向而言,通常是将旧路由映射到新路由:

```js title="astro.config.mjs" {5, 7-9}
```js title="astro.config.mjs" {4-6}
import { defineConfig } from 'astro/config';

export default defineConfig({
Expand All @@ -257,7 +257,7 @@ export default defineConfig({

使用 SSR(服务器端渲染)或者静态适配器,你还可以将对象作为值提供,除了新的 `destination` 端点指向之外,还可以指定 `status` 状态码:

```js
```js title="astro.config.mjs" {5-8}
import { defineConfig } from 'astro/config';

export default defineConfig({
Expand Down Expand Up @@ -468,4 +468,4 @@ const params = Astro.params;
- _SomeComponent.astro
- _utils.js
- **post1.md**
</FileTree>
</FileTree>
36 changes: 18 additions & 18 deletions src/content/docs/zh-cn/guides/client-side-scripts.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -43,23 +43,23 @@ description: 如何使用浏览器 JavaScript API 将客户端交互界面添加
</script>
```

### 脚本捆绑
### 脚本打包

Astro 默认处理 `<script>` 标签。

- 任何导入会被捆绑,这允许你导入本地文件或者 Node 模块。
- 任何导入会被打包,这允许你导入本地文件或者 Node 模块。
- 处理过的脚本会被注入到你的页面的 `<head>`,同时添加[`type="module"`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules)
- 完全支持 TypeScript,包括导入 TypeScript 文件。
- 如果你的组件在一个页面上被用到了多次,脚本只会有一个。

```astro title="src/components/Example.astro"
<script>
// 会处理!会捆绑!支持 TypeScript!
// 会处理!会打包!支持 TypeScript!
// 也可以导入本地脚本和 Node 模块。
</script>
```

如果不想要捆绑脚本,你可以使用 `is:inline` 指令。
如果不想要打包脚本,你可以使用 `is:inline` 指令。

```astro title="src/components/InlineScript.astro" "is:inline"
<script is:inline>
Expand All @@ -70,20 +70,20 @@ Astro 默认处理 `<script>` 标签。
```

:::note
添加 `type="module"` 或除 `src` 之外的任何属性到 `<script>` 标签将禁用 Astro 的默认捆绑行为,将标签视为具有 `is:inline` 指令。
在某些情况下,Astro 的默认打包行为将被禁用。特别是,在 `<script>` 标签添加 `type="module"` 或者除 `src` 之外的任何属性,都会使 Astro 将该标签视为具有 `is:inline` 指令。当脚本以 JSX 表达式编写时,同样也是如此
:::

📚 请参阅我们的[指令参考](/zh-cn/reference/directives-reference/#脚本和样式指令)页面以获取有关 `<script>` 标签上可用指令的更多信息。

### 脚本加载

您可能希望将脚本编写为单独的 `.js`/`.ts` 文件,或者需要引用另一台服务器上的外部脚本。 您可以通过在 `<script>` 标签的 `src` 属性中引用它们来做到这一点。
你可能希望将脚本编写为单独的 `.js`/`.ts` 文件,或者需要引用另一台服务器上的外部脚本。 你可以通过在 `<script>` 标签的 `src` 属性中引用它们来做到这一点。

#### 导入本地脚本

**何时使用**如果您的脚本位于 `src/`
**何时使用**如果你的脚本位于 `src/`

Astro 将按照其[脚本捆绑规则](#脚本捆绑)为您构建、优化并将这些脚本添加到页面中。
Astro 将按照其[脚本打包规则](#脚本打包)为你构建、优化并将这些脚本添加到页面中。

```astro title="src/components/LocalScripts.astro"
<!-- `src/scripts/local.js` 脚本的相对路径 -->
Expand All @@ -95,9 +95,9 @@ Astro 将按照其[脚本捆绑规则](#脚本捆绑)为您构建、优化并将

#### 加载外部脚本

**何时使用:** 如果您的 JavaScript 文件位于 `public/` 或 CDN 上。
**何时使用:** 如果你的 JavaScript 文件位于 `public/` 或 CDN 上。

要加载在项目的 `src/` 文件夹之外的脚本,请使用 `is:inline` 指令。当您如上所述导入脚本时,此方法会跳过 Astro 提供的 JavaScript 处理、捆绑和优化
要加载在项目的 `src/` 文件夹之外的脚本,请使用 `is:inline` 指令。当你如上所述导入脚本时,此方法会跳过 Astro 提供的 JavaScript 处理、打包和优化

```astro title="src/components/ExternalScripts.astro" "is:inline"
<!-- `public/my-script.js` 脚本的绝对路径 -->
Expand All @@ -113,7 +113,7 @@ Astro 将按照其[脚本捆绑规则](#脚本捆绑)为您构建、优化并将

一些 UI 框架使用自定义语法来处理事件,例如 `onClick={...}` (React/Preact) 或 `@click="..."` (Vue)。Astro 更严格地遵循标准 HTML,并且不对事件使用自定义语法。

相反,您可以在 `<script>` 标签中使用 [`addEventListener`](https://developer.mozilla.org/zh-CN/docs/Web/API/EventTarget/addEventListener) 来处理用户交互。
相反,你可以在 `<script>` 标签中使用 [`addEventListener`](https://developer.mozilla.org/zh-CN/docs/Web/API/EventTarget/addEventListener) 来处理用户交互。

```astro title="src/components/AlertButton.astro"
<button class="alert">Click me!</button>
Expand All @@ -132,14 +132,14 @@ Astro 将按照其[脚本捆绑规则](#脚本捆绑)为您构建、优化并将
```

:::note
如果您在一个页面上有多个 `<AlertButton />` 组件,Astro 将不会多次运行该脚本。 脚本是捆绑在一起的,每页只包含一次。 使用 `querySelectorAll` 确保此脚本将事件侦听器附加到页面上找到的具有 `alert` 类的每个按钮。
如果你在一个页面上有多个 `<AlertButton />` 组件,Astro 将不会多次运行该脚本。 脚本是打包在一起的,每页只包含一次。 使用 `querySelectorAll` 确保此脚本将事件侦听器附加到页面上找到的具有 `alert` 类的每个按钮。
:::

### 具有自定义元素的 Web 组件

您可以使用 Web 组件标准创建具有自定义行为的 HTML 元素。在 `.astro` 组件中定义 [自定义元素](https://developer.mozilla.org/zh-CN/docs/Web/Web_Components/Using_custom_elements) 允许您构建交互式组件而无需 UI 框架库。
你可以使用 Web 组件标准创建具有自定义行为的 HTML 元素。在 `.astro` 组件中定义 [自定义元素](https://developer.mozilla.org/zh-CN/docs/Web/Web_Components/Using_custom_elements) 允许你构建交互式组件而无需 UI 框架库。

在这个例子中,我们定义了一个新的 `<astro-heart>` HTML 元素,用于跟踪您点击喜欢按钮的次数并使用最新计数更新 `<span>`
在这个例子中,我们定义了一个新的 `<astro-heart>` HTML 元素,用于跟踪你点击喜欢按钮的次数并使用最新计数更新 `<span>`

```astro title="src/components/AstroHeart.astro"
<!-- 将按钮包装在我们的自定义元素“astro-heart”中。 -->
Expand Down Expand Up @@ -172,17 +172,17 @@ Astro 将按照其[脚本捆绑规则](#脚本捆绑)为您构建、优化并将

在这里使用自定义元素有两个优点:

1. 除了使用 `document.querySelector()` 搜索整个页面,您可以使用 `this.querySelector()` ,它只在当前自定义元素实例中搜索。这使得一次只处理一个组件实例的子实例变得更容易。
1. 除了使用 `document.querySelector()` 搜索整个页面,你可以使用 `this.querySelector()` ,它只在当前自定义元素实例中搜索。这使得一次只处理一个组件实例的子实例变得更容易。

2. 虽然 `<script>` 只运行一次,但浏览器每次在页面上找到 `<astro-heart>` 时都会运行我们自定义元素的 `constructor()` 方法。 这意味着您可以安全地一次为一个组件编写代码,即使您打算在一个页面上多次使用该组件
2. 虽然 `<script>` 只运行一次,但浏览器每次在页面上找到 `<astro-heart>` 时都会运行我们自定义元素的 `constructor()` 方法。 这意味着你可以安全地一次为一个组件编写代码,即使你打算在一个页面上多次使用该组件

📚 你可以在[web.dev 的《可重用 Web 组件指南》](https://web.dev/custom-elements-v1/)[MDN 对自定义元素的介绍](https://developer.mozilla.org/zh-CN/docs/Web/Web_Components/Using_custom_elements)中了解更多自定义元素。

### 将 frontmatter 变量传递给脚本

在 Astro 组件中,`---` 之间 [frontmatter](/zh-cn/core-concepts/astro-components/#组件脚本) 中的代码在服务器上运行,而不是在浏览器中。要将变量从服务器发送到客户端,我们需要一种方法来存储我们的变量,然后在浏览器中运行 JavaScript 时读取它们。

一种方法是使用 [`data-*` 属性](https://developer.mozilla.org/zh-CN/docs/Learn/HTML/Howto/Use_data_attributes) 在 HTML 中存储变量值输出。 一旦您的 HTML 加载到浏览器中,脚本(包括自定义元素)就可以使用元素的“数据集”属性读取这些属性。
一种方法是使用 [`data-*` 属性](https://developer.mozilla.org/zh-CN/docs/Learn/HTML/Howto/Use_data_attributes) 在 HTML 中存储变量值输出。 一旦你的 HTML 加载到浏览器中,脚本(包括自定义元素)就可以使用元素的“数据集”属性读取这些属性。

在此示例组件中,一个 `message` 属性存储在 `data-message` 属性中,因此自定义元素可以读取 `this.dataset.message` 并在浏览器中获取该属性的值。

Expand Down Expand Up @@ -229,5 +229,5 @@ import AstroGreet from '../components/AstroGreet.astro';
```

:::tip[你知道吗?]
当您将 props 传递给使用 React 等 UI 框架编写的组件时,这实际上是 Astro 在幕后所做的!对于带有 `client:*` 指令的组件,Astro 创建了一个带有 `props` 属性的 `<astro-island>` 自定义元素,该属性将您的服务器端 props 存储在 HTML 输出中。
当你将 props 传递给使用 React 等 UI 框架编写的组件时,这实际上是 Astro 在幕后所做的!对于带有 `client:*` 指令的组件,Astro 创建了一个带有 `props` 属性的 `<astro-island>` 自定义元素,该属性将你的服务器端 props 存储在 HTML 输出中。
:::
46 changes: 46 additions & 0 deletions src/content/docs/zh-cn/guides/deploy/cleavr.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
---
title: 通过 Cleavr 部署你的 Astro 网站
description: 如何将你的 Astro 网站通过 Cleavr 部署到你的 VPS 服务器上
type: deploy
i18nReady: true
---

你可以使用 [Cleavr](https://cleavr.io/) 这款服务器和应用部署管理工具,将 Astro 项目部署到自己的虚拟专用服务器(VPS)上。

:::tip
请查阅 [Cleavr 文档中的 Astro 指南](https://docs.cleavr.io/guides/astro)
:::

## 前期准备

在开始操作前,你需要准备:
- 一个 Cleavr 账户
- 使用 Cleavr 在你的 VPS 提供商上创建一个服务器

## 添加你的网站

1. 在 Cleavr 中,进入你要将 Astro 项目添加到的服务器中。

2. 点击**添加网站**并填写你的应用程序的详细信息,例如域名。

3. 对于**应用程序类型**,根据你设置 Astro 应用程序的方式选择 “NodeJS Static” 或 “NodeJS SSR”。

4. 对于静态应用程序,请将**构件文件夹**设置为 `dist`

5. 对于 SSR 应用程序:
-**入口点**设置为 `entry.mjs`
-**构件文件夹**设置为 `dist/server`

6. 点击**添加**将网站添加到服务器。

## 设置和部署

1. 一旦添加了你的新网站,点击**设置和部署**

2. 为你的 Astro 项目选择**版本控制配置文件****仓库****分支**

3. 对项目进行任何其他必要的配置。

4. 点击**部署**选项卡,然后点击**部署**

恭喜,你刚刚部署了你的 Astro 应用程序!
Loading

0 comments on commit 02cb12e

Please sign in to comment.