General Configuration

您可以在 book.toml 文件中配置图书的参数。

下面是一个示例,说明 book.toml 文件:

[book]
title = "Example book"
author = "John Doe"
description = "The example book covers examples."

[rust]
edition = "2018"

[build]
build-dir = "my-example-book"
create-missing = false

[preprocessor.index]

[preprocessor.links]

[output.html]
additional-css = ["custom.css"]

[output.html.search]
limit-results = 15

支持的配置选项

请务必注意,在 配置中的路径始终相对于书的根的位置,即配置文件的 位置。

常规元数据

下面是图书的通常信息.

  • title: 书名
  • authors: 本书的作者
  • description: 该书的说明,作为元数据添加 每个页面的 html的 <head>
  • src: 默认情况下,源目录位于 根目录的src目录。但这可以通过src 元数据进行设置。
  • language: 本书的主要语言,例如用作语言属性<html lang="en">

book.toml

[book]
title = "Example book"
authors = ["John Doe", "Jane Doe"]
description = "The example book covers examples."
src = "my-src"  #源文件将放在“root/my-src”中,而不是“root/src”
language = "en"

Rust options Rust 选项

Options for the Rust language, relevant to running tests and playground integration.

Rust 语言的选项,与运行测试和 Playground 集成 有关。

[rust]
edition = "2015"   # the default edition for code blocks
  • edition: 定义Rust 代码片段的默认版本。默认 是“2015”。单个代码块可以使用注释 如edition2015edition2018edition2021进行设置,例如:

    ```rust,edition2015
    // This only works in 2015.
    let try = true;
    ```
    

Build options 构建选项

控制图书的构建过程选项。

[build]
build-dir = "book"                # 设置输出的目录
create-missing = true             # 是否创建缺失页面
use-default-preprocessors = true  # 使用默认预处理器
  • build-dir: 用于放置渲染的书籍的目录。默认情况下,这是 book/在书籍的根目录中。 这可以用--dest-dir CLI 选项覆盖。

  • create-missing: 默认情况下,在SUMMARY.md中指定的不存在的文件 将在本书构建时创建(即create-missing = true)。如果 为false,则当任何一个文件不存在的时候,构建过程将退出并显示错误。

  • use-default-preprocessors: 禁用 默认预处理器(links & 索引),通过将此选项设置为 false

    如果您有相同的和/或其他预处理器通过其表声明 的配置,它们将改为运行。

    • 为清楚起见,在没有定义预处理器配置的情况下,将采用默认的links and index
    • 设置use-default-preprocessors = false 则禁止默认的预处理器运行.
    • 如果添加[preprocessor.links],那么无论是否设置 use-default-preprocessors ,它将links 它将运行。