From b404d25a7a9ea3bbfaa4064fbbe126388b66deee Mon Sep 17 00:00:00 2001 From: vrabe Date: Mon, 27 Jan 2025 03:58:43 +0800 Subject: [PATCH 1/3] update `astro-pages.mdx`, not includes 500 pages --- src/content/docs/zh-tw/basics/astro-pages.mdx | 51 +++++++++++++++---- 1 file changed, 40 insertions(+), 11 deletions(-) diff --git a/src/content/docs/zh-tw/basics/astro-pages.mdx b/src/content/docs/zh-tw/basics/astro-pages.mdx index b4a7738a3e15f..bedb1bcb77354 100644 --- a/src/content/docs/zh-tw/basics/astro-pages.mdx +++ b/src/content/docs/zh-tw/basics/astro-pages.mdx @@ -1,6 +1,6 @@ --- title: 頁面 -description: Astro 頁面簡介 +description: Astro 頁面簡介。 i18nReady: true --- @@ -71,11 +71,13 @@ import MySiteLayout from '../layouts/MySiteLayout.astro'; ## Markdown/MDX 頁面 -Astro 也會將任何 `src/pages/` 內的 Markdown(`.md`)檔作為你最後網站的頁面。如果你有[安裝 MDX 整合](/zh-tw/guides/integrations-guide/mdx/#installation)的話,它也會對 MDX(`.mdx`)檔做同樣的事。這普遍用於以文字為主的頁面,像是部落格文章和文件。 +Astro 也會將任何 `src/pages/` 內的 Markdown(`.md`)檔作為你最後網站的頁面。如果你有[安裝 MDX 整合](/zh-tw/guides/integrations-guide/mdx/#installation)的話,它也會對 MDX(`.mdx`)檔做同樣的事。 -此外,`src/content/` 的 [Markdown 或 MDX 頁面內容合集](/zh-tw/guides/content-collections/)可以[動態產生頁面](/zh-tw/guides/routing/#dynamic-routes)。 +:::tip +對於包含結構相似且相關的 Markdown 檔(如部落格文章或商品項目)的資料夾,請考慮建立[內容合集](/zh-tw/guides/content-collections/),而不是頁面。 +::: -頁面版面在 [Markdown 檔](#markdownmdx-頁面)特別地有用。Markdown 檔可以使用特殊的 `layout` frontmatter 屬性指定 [版面元件](/zh-tw/basics/layouts/),進而將 Markdown 內容包進完整的 `...` 頁面檔案裡。 +Markdown 檔可以使用特殊的 `layout` frontmatter 屬性指定 [版面元件](/zh-tw/basics/layouts/),進而將 Markdown 內容包進完整的 `...` 頁面檔案裡。 ```md {3} --- @@ -96,10 +98,42 @@ title: '我的 Markdown 頁面' ## 自訂 404 錯誤頁面 -如要自訂 404 錯誤頁面,可以在 `/src/pages` 新增 `404.astro` 或 `404.md`。 +如要自訂 404 錯誤頁面,可以在 `src/pages` 新增 `404.astro` 或 `404.md`。 建構時會產生 `404.html` 頁面,大多數的[部署服務](/zh-tw/guides/deploy/)會找到並使用該檔案。 +## 自訂 500 錯誤頁面 + +For a custom 500 error page to show for pages that are [rendered on demand](/en/guides/on-demand-rendering/), create the file `src/pages/500.astro`. This custom page is not available for prerendered pages and can't be prerendered. + +If an error occurs rendering this page, your host's default 500 error page will be shown to your visitor. + +

+ +During development, if you have a `500.astro`, the error thrown at runtime is logged in your terminal, as opposed to being shown in the error overlay. + +### `error` + +

+ +`src/pages/500.astro` is a special page that is automatically passed an `error` prop for any error thrown during rendering. This allows you to use the details of an error (e.g. from a page, from middleware, etc.) to display information to your visitor. + +The error prop's data type can be anything, which may affect how you type or use the value in your code: + +```astro title="src/pages/500.astro" +--- +interface Props { + error: unknown +} + +const { error } = Astro.props +--- + +
{error instanceof Error ? error.message : 'Unknown error'}
+``` + +To avoid leaking sensitive information when displaying content from the `error` prop, consider evaluating the error first, and returning appropriate content based on the error thrown. For example, you should avoid displaying the error's stack as it contains information about how your code is structured on the server. + ## 局部頁面

@@ -118,7 +152,7 @@ title: '我的 Markdown 頁面' 局部頁面搭配算繪套件同樣能夠開發動態內容,是不使用 [Astro 群島](/zh-tw/concepts/islands/) 和 [`