字体和 FontAwesome#

该主题包含 FontAwesome 6 Free 图标字体(.fa-solid, .fa-regular, .fa-brands 样式,用于 图标链接 和警告框)。这是唯一的 自带 字体,除此之外,该主题默认依赖于可用的系统字体来显示正文和标题。

有关 PyData Sphinx Theme 排版和文本样式的更多详细信息,请参阅 PyData Sphinx 主题设计系统 部分。

默认的正文和标题字体可以按如下方式更改:

  • 使用 定制 CSS 样式表,您可以指定用于正文、标题和等宽文本的字体。例如,以下内容可以添加到自定义 CSS 文件中:

    html {
        --pst-font-family-base: Verdana, var(--pst-font-family-base-system);
        --pst-font-family-heading: Cambria, Georgia, Times, var(--pst-font-family-base-system);
        --pst-font-family-monospace: Courier, var(--pst-font-family-monospace-system);
    }
    

    *-system 变量可用作默认字体的后备。

  • 如果您在上述部分中想要指定的字体通常不是默认可用的,您还需要确保加载了该字体。例如,您可以下载并将字体放置在 Sphinx 站点的 _static 目录中,然后更新基本模板以加载字体资源:

    • 在您的 conf.py 中配置 template_path

    • 创建自定义的 layout.html Jinja2 模板,重载 fonts 块(示例用于加载包含在 _static/vendor 目录中的 Lato 字体):

      {% extends "pydata_sphinx_theme/layout.html" %}
      
      {% block fonts %}
        <!-- add `style` or `link` tags with your CSS `@font-face` declarations here -->
        <!-- ... and optionally preload the `woff2` for snappier page loads -->
        <link rel="stylesheet" href="{{ pathto('_static/vendor/lato_latin-ext/1.44.1/index.css', 1) }}">
      
      {% endblock %}
      

      Your text may quickly show up as "unstyled" before the fonts are loaded. To reduce this, you may wish to explore options for preloading content, specifically the binary font files. This ensures the files will be loaded before the CSS is parsed, but should be used with care.