Skip to content

创作内容

Astro 是你以内容为中心的网站的完美选择:博客、营销网站、作品集等等!

¥Astro is a perfect choice for your content-focused site: blogs, marketing sites, portfolios, and more!

Astro 帮助你创作和展示你的内容。你可以使用 Markdown/MDX 直接在 Astro 中撰写博客文章,或从无头 CMS 获取内容。Astro 允许你围绕你的内容构建网站:你可以向页面添加布局、创建帖子索引并设置 RSS 源以允许读者订阅。

¥Astro helps you author and present your content. You can write a blog post directly in Astro using Markdown/MDX, or fetch your content from a headless CMS. Astro lets you build a site around your content: you can add a layout to your pages, create an index of posts, and set up an RSS feed to allow readers to subscribe.

¥Writing Content

在 Astro 中,你可以通过多种方式创作内容:

¥In Astro, you can author your content in a variety of ways:

¥Markdown Authoring

Markdown 是一种方便的语法,用于编写具有基本格式和常见元素(如标题、列表和图片)的富文本。Astro 内置了对项目中 Markdown 文件的支持。

¥Markdown is a convenient syntax for writing rich text with basic formatting and common elements like headers, lists, and images. Astro has built-in support for Markdown files in your project.

在代码编辑器中创建并编写一个新的 .md 文件,或者引入用你最喜欢的 Markdown 编辑器编写的现有文件。一些在线 Markdown 编辑器(例如 StackEdit迪林格)甚至允许你编辑你的作品并将其与存储在 GitHub 上的 Astro 存储库同步。

¥Create and write a new .md file in your code editor or bring in an existing file written in your favorite Markdown editor. Some online Markdown editors like StackEdit and Dillinger will even allow you to edit and sync your work with your Astro repository stored on GitHub.

¥MDX Authoring

如果你将 Astro MDX 集成 添加到你的项目中,你还可以使用 .mdx 文件编写内容,这些文件可以包含 Markdown 中的 JavaScript 表达式和组件。这包括静态 Astro 组件 和交互式 框架组件。这允许你在文本内容中包含 UI 元素,例如横幅或交互式轮播。

¥If you add the Astro MDX integration to your project, you can also write content using .mdx files, which can include JavaScript expressions and components within your Markdown. This includes both static Astro components and interactive framework components. This allows you to include UI elements such as a banner or an interactive carousel along with your text content.

直接在代码编辑器中与项目文件一起编写和编辑 .mdx 文件。MDX 文件是 Astro 中的 支持的页面文件类型,也可以用作 内容集合条目

¥Write and edit .mdx files directly in your code editor, alongside your project files. MDX files are a supported page file type in Astro, and may also be used as content collection entries.

Learn more about using MDX with Astro.

¥Headless CMS Authoring

在现有的内容管理系统 (CMS)(例如 Storyblok、WordPress 或 Contentful)中撰写博客文章。一些 CMS(例如 Storyblok)提供官方 Astro 整合。其他人公开了 Astro 页面可以使用的 JavaScript SDK 到 获取你的远程内容

¥Write blog posts in your existing Content Management System (CMS) such as Storyblok, WordPress, or Contentful. Some CMSes, like Storyblok, provide an official Astro integration. Others expose a JavaScript SDK that Astro pages can use to fetch your remote content.

Explore our collection of CMS guides and Astro CMS integrations for a wide selection of resources.

¥Managing content pages

¥Page files

src/pages 目录中的 Markdown 和 MDX 文件将使用 Astro 的 基于文件的路由 自动在你的网站上生成页面,该 基于文件的路由 构建在与帖子文件路径相对应的 URL 上。

¥Markdown and MDX files that live in your src/pages directory will automatically generate pages on your site using Astro’s file-based routing, built at a URL corresponding to the post’s file path.

¥Local content

你还可以选择将 Markdown 和 MDX 文件保留在 src/pages 目录之外,而将 import their content 保留在 .astro 页面中。

¥You can also choose to keep your Markdown and MDX files outside of the src/pages directory, and instead import their content into .astro pages.

¥Content collections

Astro 自己的 内容集合 提供了一种强大、类型安全的方式来处理 src/content/ 目录中组织的 Markdown、MDX 或 Markdoc 内容。

¥Astro’s own content collections provide a powerful, type-safe way to work with Markdown, MDX, or Markdoc content organized in the src/content/ directory.

¥Remote content

你也可以从项目外部的来源 远程获取 markdown。这将需要你自己的 Markdown 解析器或社区集成(例如 astro-remote)。

¥You can also fetch markdown remotely from a source outside of your project. This will require your own Markdown parser, or a community integration (e.g. astro-remote).

¥Showcasing your content

为了构建常用功能来组织和显示你的内容,例如博客存档或每个博客标签的页面,Astro 允许你从 Markdown 和 MDX 前言中进行 获取文件名和元数据,或使用 内容集合辅助实用程序 查询你的条目并生成页面内容和路由。

¥To build common features to organize and display your content, such as a blog archive or a page for each blog tag, Astro allows you to fetch filenames and metadata from your Markdown and MDX frontmatter or use content collection helper utilities to query your entries and generate page content and routes.

要发布给更广泛的受众,可以分发给 feed 阅读器的 创建 RSS 提要

¥To publish to a broader audience, create an RSS feed that can be distributed to feed readers.

¥Community Integrations

除了官方的 @astrojs/mdx@astrojs/markdoc 集成之外,还有几个第三方 社区整合 可用于处理 Astro 项目中的内容。

¥In addition to the official @astrojs/mdx and @astrojs/markdoc integrations, there are several third-party community integrations for working with content in your Astro project.

Astro 中文网 - 粤ICP备13048890号