@tola/feed

为站点文章生成 RSS、Atom 或 JSON Feed。

导入

typst
#import "@tola/feed:0.0.0": *

导出成员

feed

typc
let feed(
  authors: auto | array = auto,
  description: auto | content | string = auto,
  entries: array = (),
  format: string = "rss",
  id: auto | string = auto,
  language: auto | string = auto,
  output: auto | string = auto,
  title: auto | content | string = auto,
) = content;

向站点 Bundle 输出一份 RSS、Atom 或 JSON Feed 文件。

需要在 [site] 中配置 origin 以生成绝对 URL。

条目字段

每条记录必填 target(输出路径、(output:, fragment:)、label 或 location)与 published(按 UTC 解释的 Typst datetime 或带时区的 RFC 3339 字符串——使用 @tola/schema#timestamp 时传入 .rfc3339)。可选字段:id(文章移动后请沿用原值;Atom 要求为绝对 URI)、title(默认取目标文档标题)、updated、summary、content 与 authors。

格式summarycontent
RSS<description><content:encoded>
Atom<summary><content>(文本或 HTML)
JSON Feedsummary(纯文本)content_text 或 content_html

条目 content 的写法

  • 字符串:按纯文本写入。
  • 简单 Typst 内容(文本、换行、强调、粗体、删除线与 URL 链接):直接转为 HTML,不执行排版与 show rule。
  • 从已导出 HTML 提取正文:传入 (document: output, id: "post-body") 提取该元素及其后代(并保留 <head> 样式),省略 id 则取整个 <body>;元素内的相对 URL 会自动改写为绝对 URL。

命名参数

  • output auto | string 默认值: auto:相对于发布目录的输出路径。auto 按格式默认选用 feed.xml(RSS)、atom.xml(Atom)或 feed.json(JSON Feed)。
  • format string 默认值: "rss":订阅格式:"rss"(默认)、"atom" 或 "json"。
  • id auto | string 默认值: auto:Feed 标识。Atom 要求为绝对 URI;auto 默认由 site.url 生成。
  • title auto | content | string 默认值: auto:Feed 标题(不可为空白);auto 取 site.title。
  • description auto | content | string 默认值: auto:Feed 简介;auto 取 site.description。
  • language auto | string 默认值: auto:BCP 47 语言标签;auto 取 site.language.tag。
  • authors auto | array 默认值: auto:作者 (name:, email:, url:) 字典数组;auto 取 site.authors。Atom 要求在 feed 级或每个条目上指定作者。
  • entries array 默认值: ():按发布顺序排列的条目字典数组,默认 ()。

生成附带正文 HTML 的 RSS Feed

typst
#import "@tola/feed:0.0.0": feed

#let output = "notes/index.html"
#document(output, title: [第一则笔记])[
  #html.html[
    #html.head(html.title("第一则笔记"))
    #html.body[
      #html.article(id: "post-body")[
        = 第一则笔记
        包含在订阅源中的完整正文。
      ]
    ]
  ]
]

#feed(
  title: "Typst 笔记",
  entries: ((
    id: "urn:notes:first",
    target: output,
    published: datetime(year: 2026, month: 9, day: 1),
    summary: "订阅预览摘要。",
    content: (document: output, id: "post-body"),
  ),),
)

站内搜索

可以用上下方向键选择结果。

输入关键词开始搜索。