产品
产品
为多产品文档站点添加产品切换器
团队版和企业版功能
此功能仅适用于团队版和企业版套餐。要开始使用,请联系 support@buildwithfern.com。
为多产品文档站点添加产品切换器。每个产品可以有自己的导航、标签页、版本和 API 参考,产品之间还可以共享内容。
产品可以是内部的(托管在您的站点上)或外部的(链接到外部 URL)。
向您的文档添加产品
定义您的产品
在您的 fern 文件夹内创建一个 products 文件夹。要指定产品的内容和导航结构,请为每个产品向 products 文件夹添加一个 .yml 文件。
确保包含 navigation 和 tabs 属性(如果适用)。
外部产品
您还可以定义外部产品,它们链接到外部 URL(独立应用程序、第三方文档或其他外部资源),而不是您站点内的文档。它们会出现在产品切换器中,但在选择时会将用户导航到指定的 URL。外部产品直接在 docs.yml 中定义(不需要特定产品的 .yml 文件)。
要在编辑器中启用 YAML 验证和自动完成功能,请在每个 product.yml 文件的顶部添加模式指令。
添加您的产品配置
要定义产品,请向 docs.yml 中的 products 列表添加项目,指定 display-name 以及 path(对于内部产品)或 href(对于外部产品)。
对于内部和外部产品,image、icon 和 subtitle 都是可选参数。如果您同时提供 image 和 icon,image 将优先使用。内部产品还支持可选的 slug 和 versions 参数。
产品图标
Icons can be in three formats:
- Font Awesome icons: Use icon names like
fa-solid fa-rocket. Pro and Brand Icons from Font Awesome are supported. - Custom image files: Use relative paths to image files (e.g.,
./assets/icons/my-icon.svgor../assets/icons/my-icon.png). Paths are relative to the YAML file where the icon is referenced (e.g.,docs.yml). For example, if you set an icon infern/products/my-product.yml, the path./assets/icon.svgresolves tofern/products/assets/icon.svg. If you set it infern/docs.yml, the same path resolves tofern/assets/icon.svg. - Inline SVG: Provide an SVG string wrapped in quotes (e.g.,
"<svg>...</svg>").
下面的示例是一个具有两个内部产品(产品 A 和产品 B)和一个外部产品(产品 C)的站点的 docs.yml 配置。
添加站点级着陆页
您可以添加一个着陆页,该页面出现在文档站点的根目录下,独立于任何产品。当您希望用户在选择产品之前看到介绍页面时,这非常有用。
在您的 docs.yml 中配置 landing-page 属性:
着陆页不与任何产品关联,可在文档站点的根 URL(或指定的 slug)处访问。
有关详细的配置选项,请参阅着陆页配置参考。
为您的产品添加版本控制
您可以选择为内部产品添加版本。版本化和非版本化的产品可以在您的站点中并存。外部产品不支持版本。
在下面的示例中,产品 A 是非版本化的,产品 B 是版本化的:
定义您的版本
在要版本化的产品文件夹内创建一个 versions 文件夹。
单个产品的每个版本都有自己的 yml 文件。要指定每个版本的内容,请向 versions 文件夹添加一个 .yml 文件来定义该版本的导航结构。确保包含 navigation 和 tabs 属性(如果适用)。
版本特定的 yml 文件:
添加您的版本配置
通过向 versions 列表添加项目并指定 display-name 和 path 来在顶级 docs.yml 中定义版本。
包含两个产品(一个非版本化,一个版本化)的 Fern Docs 网站的顶级 doc.yml 配置可能如下所示:
Default versions
Versions appear in a dropdown on your site in the order listed in docs.yml. The first version in your versions list is the default version and uses unversioned paths like example.com/getting-started. Other versions use versioned paths like example.com/v2/getting-started.
Fern automatically handles version routing by redirecting broken versioned links to the default version. Canonical URLs point to the unversioned path to consolidate SEO signals. To override this for version-specific pages, see SEO metadata.
指示可用性
You can optionally set the availability status for each version. Options are deprecated, ga, stable, and beta.
Version availability is distinct from section and page availability, with different options. If you want to set section and page availability, do so in your version-specific yml files.
添加实例受众
通过为版本和/或产品标记受众,控制哪些版本和/或产品出现在每个文档实例中。这使得可以为不同用户群体(例如,内部开发者、beta 测试者、公共客户)提供单独的站点。
内容根据受众标签进行过滤:
- 匹配:具有与实例受众匹配的受众的内容被包含
- 不匹配:具有不匹配受众的内容被排除
- 无受众:没有受众标签的内容默认被包含
在 docs.yml 中为实例、产品和版本定义受众:
与 API 参考受众结合
实例受众与 API 参考受众一起工作,后者过滤 API 文档中的端点和模式。您可以同时使用这两个功能:
- 实例受众 - 控制哪些产品和版本出现在每个实例中
- API 参考受众 - 控制哪些端点和模式出现在 API 参考中
例如,您可能有一个仅包含公共产品的 public 实例。在这些产品中,API 参考应该标记为 public,以便过滤只显示 public 端点。
条件渲染内容
要根据当前产品在页面内条件渲染内容,请使用 <If> 组件。
自定义选择器样式
您可以通过定位 CSS 类直接自定义产品和版本选择器的外观:
fern-product-selector- 控制产品选择器的样式fern-version-selector- 控制版本选择器的样式

常见样式调整
Adjusting positioning:
Use transform: translateY(Npx) to adjust the vertical positioning of the selectors. This ensures that the selectors match the line height of your logo for better visual alignment.
Enhancing visual prominence: You can modify the border radius and add borders to make the selectors more prominent and better integrated with your site’s design aesthetic.
自定义下拉菜单样式
产品和版本选择器的下拉菜单可以使用这些特定的 CSS 类进行自定义:
fern-product-selector-radio-group- 控制产品下拉菜单的样式fern-version-selector-radio-group- 控制版本下拉菜单的样式
产品选择器
版本选择器

常见样式调整
为下拉菜单启用网格布局: