Fumadocs

最后修改时间

获取 GitHub 仓库中文件的最后编辑时间

使用

🌐 Usage

提供你的仓库名称和文件路径。

🌐 Pass your repository name, and the path to file.

import { getGithubLastEdit } from 'fumadocs-core/content/github';

const time = await getGithubLastEdit({
  owner: 'fuma-nama',
  repo: 'fumadocs',
  // example: "content/docs/index.mdx"
  path: `content/docs/${page.path}`,
});

GitHub 令牌

🌐 Github Token

请注意,在开发模式下,你可能很容易达到速率限制。因此,你应该传递一个 GitHub 令牌以获得更高的速率限制。

🌐 Notice that you may easily reach the rate limit in development mode. Hence, you should pass a Github token for a higher rate limit.

了解更多关于认证到 REST API的信息。

🌐 Learn more about Authenticating to the REST API.

import { getGithubLastEdit } from 'fumadocs-core/content/github'

 const time = await getGithubLastEdit({
    ...,
    token: `Bearer ${process.env.GIT_TOKEN}`
  })

此外,如果你在开发模式下不需要该功能,可以跳过这一步。

🌐 Also, you can skip this in development mode if you don't need that functionality.

process.env.NODE_ENV === 'development'? null : getGithubLastEdit(...)

自定义 GitHub 基础 URL

🌐 Custom GitHub Base URL

如果你需要访问位于除 https://api.github.com 之外的 URL 的 GitHub 实例,你可以覆盖基础 URL:

🌐 If you need to access GitHub a instance at a url other than https://api.github.com, you can override the base URL:

import { getGithubLastEdit } from 'fumadocs-core/content/github';

const time = await getGithubLastEdit({
  owner: 'your-org',
  repo: 'your-repo',
  path: `content/docs/${page.path}`,
  baseUrl: 'https://api.octocorp.ghe.com', // Your custom GitHub API URL
});

baseUrl 参数如果未指定,则默认为 'https://api.github.com'

🌐 The baseUrl parameter defaults to 'https://api.github.com' if not specified.

Last updated on

On this page