跳至內容
Fumadocs

最後修改時間

取得 GitHub 儲存庫中檔案的最後編輯時間

使用方式

請傳入您的儲存庫名稱及檔案路徑。

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

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

Github Token

請注意,在開發模式下很容易就會達到速率限制,因此建議您傳入 Github token,以取得較高的速率限制。

進一步了解 向 REST API 進行驗證。

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

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

此外,若您在開發模式下不需要此功能,也可以略過這個步驟。

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

自訂 GitHub 基礎 URL

如果您需要存取的 GitHub 執行個體位於 https://api.github.com 以外的 URL,可以覆寫基礎 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', // 您的自訂 GitHub API URL
});

若未指定,baseUrl 參數的預設值為 'https://api.github.com'。

How is this guide?

最後更新於