样式与图标
可以直接发布手写 CSS,也可以用官方 tailwind 模块编译原子类。SVG 图标通过 @tola/icon 管理。
普通 CSS
将样式目录声明到 [assets].trees,在模板 <head> 中通过 asset-url 引入:
[assets]
cache-busting = true
trees = [{ source = "static/styles", url-prefix = "/styles" }]#import "@tola/address:0.0.0": asset-url
#html.link(rel: "stylesheet", href: asset-url("/styles/main.css"))Tola 不会改写 CSS 里的 url(...)。如果样式表发布在 /docs/styles/main.css,其中写的 url("../fonts/inter.woff2") 会由浏览器相对样式表地址解析为 /docs/fonts/inter.woff2,因此使用相对路径可以自动兼容任意 site.base-path。
Tailwind CSS
官方模块
在项目中安装 Tailwind CSS v4 CLI,然后声明模块:
[modules.tailwind]
git = { url = "https://github.com/tola-rs/modules.git", subdir = "tailwind" }
[modules.tailwind.options]
runner = "auto"
dev = "run"在 <head> 中通过 output-url 引入它产出的样式表:
#import "@tola/address:0.0.0": output-url
#html.link(rel: "stylesheet", href: output-url("_tola-modules/tailwind/tailwind.css"))关于 tailwind 模块的 input、minify、runner 与 dev 选项细节见 模块与主题。
自定义钩子
当站点或主题有自己的 package.json(例如同时用 PostCSS、自定义主题变量或按需扫描 .typ 文件),可以在 [[hooks.before-build]] 中调用 Tailwind CLI 并配合 dev = "reuse" 加速热重载:
[[hooks.before-build]]
name = "styles"
nu = "tools/styles.nu"
dev = "reuse"
rerun-on = { include = ["styles", "**/*.typ"], exclude = ["public", ".tola", "generated"] }
generates = ["generated/styles/site.css"]编写 Tailwind v4 的 @source 清单时,建议显式排除 public/、vendor/、node_modules/ 以及自动生成的大量参考存根目录,既减少 Tailwind 扫描耗时,也避免在 tola dev 修改内容时触发不必要的 CSS 重编。
SVG 图标
在 tola.toml(或模块的 tola-module.toml)的 [icons.collections] 中声明本地 SVG 目录或远程图标集预设(例如 Lucide):
[icons.collections.ui]
source-type = "local-svg-dir"
path = "icons/ui"[icons.collections.ui]
source-type = "remote-json"
preset = "lucide"
version = "1.2.154"远程图标集会被锁定进 tola.lock,并支持 tola vendor 离线打包。配置完成后可运行 tola inspect icons 列出可用图标名称。
在 Typst 中通过 @tola/icon:0.0.0 渲染图标:
#import "@tola/icon:0.0.0": icon, icon-url
// 1. 内联 SVG:通过 currentColor 继承文字颜色;省略 label 表示纯装饰性图标(自动加 aria-hidden)
#icon("ui:rocket") 快速启动
// 2. 独立表达含义的图标:提供 label 生成无障碍名称
#icon("ui:search", label: "搜索文档")
// 3. 发布为独立 SVG 文件并用 <img> 引用(适合复用大图,不继承外部文字颜色)
#html.img(src: icon-url("ui:rocket"), alt: "火箭图标")如果图标集声明在模块清单里,在模块 Typst 代码中绑定当前模块实例名称,避免和站点同名集合冲突:
#import "@tola/icon:0.0.0": icon
#import "@tola/module:0.0.0": get-module
#let ui-icon = icon.with(module: get-module().name)需要把图标嵌入自定义 SVG(例如用 Typst 生成 Open Graph 分享图或 favicon)时,调用 icon-bytes("ui:rocket") 可直接拿到原始字节流,再传给 image(...)。