For AI agents: the complete documentation index is available at https://rspress.rs/zh/llms.txt, the full documentation bundle is available at https://rspress.rs/zh/llms-full.txt, and this page is available as Markdown at https://rspress.rs/zh/ui/layout-components/last-updated.md.
close

LastUpdated

Warning

该组件主要配合 自定义主题 中的 wrap/eject 使用 ,与 MDX 里直接导入使用的组件不同,你可以通过传递组件 props 或直接覆盖该组件达到修改样式和功能的目的。如果通过 eject 覆盖整个组件,需注意组件对应配置项的读取会失效,需要自行控制。

LastUpdated 展示页面的最后更新时间,并可选择显示最后的作者。通常配合主题的 lastUpdated 配置使用。

用法

最后更新于: 2026/12/4 09:03:41

import { LastUpdated as BasicLastUpdated } from '@rspress/core/theme-original';

export default function LastUpdated() {
  return <BasicLastUpdated />;
}

该组件不接受任何 props,会自动从页面元数据中读取最后更新时间。

相关配置

在 rspress.config.ts 中开启 lastUpdated:

rspress.config.ts
import { defineConfig } from '@rspress/core';

export default defineConfig({
  themeConfig: {
    lastUpdated: true,
  },
});

当启用 lastUpdated 时,组件会自动读取页面元数据并格式化显示。

显示作者

配置 lastUpdated.author 可以展示最后一次提交的作者:

rspress.config.ts
export default defineConfig({
  themeConfig: {
    lastUpdated: {
      // 展示提交作者名称:
      // author: true,

      // 或使用自定义展示文本:
      author: ({ name, email }) => `${name} <${email}>`,
    },
  },
});

回调函数会收到 { name, email, filePath }(来自 git log 的作者信息以及源文件路径),返回值即为要展示的字符串。

如需自定义展示文案或时间格式,可通过 rspress eject LastUpdated 导出并修改 theme/components/LastUpdated/index.tsx。