Page History

Advanced API

Read Git history yourself for custom layouts and content pipelines.

The compiler plugin covers most sites. Use these APIs when you need history somewhere the plugin doesn't run, such as a custom layout or a page that isn't compiled from Markdown.

Read history

Read the history in a server component or build script, then render it:

components/page-history.tsx
import 'server-only';
import { readPageHistory } from 'fumadocs-page-history/git';
import { GitChangelog } from 'fumadocs-page-history/ui';

export async function PageHistory({ path }: { path: string }) {
  const commits = await readPageHistory(path, {
    repository: { url: 'https://github.com/owner/repository' },
  });

  return <GitChangelog commits={commits} />;
}

path is the file's path relative to the Git root, such as content/docs/guide.mdx, not a URL or slug. The options are the same as the plugin's; see Advanced Git controls. Without repository.directory, Git is found from the current working directory.

This needs Git and a full checkout wherever the code runs, and it throws if the clone is shallow or a Git command fails. If your server doesn't have Git, read the history during the build, save it as JSON, and import that file instead.

Reuse a reader

Each readPageHistory() call reads the repository's metadata again. If a build processes many files, create one reader and reuse it:

import { createHistoryReader } from 'fumadocs-page-history/git';

const history = createHistoryReader({ repository: { url: 'https://github.com/owner/repository' } });
const commits = await history.read('content/docs/guide.mdx');

Create a new reader for each build so it doesn't keep outdated data. The compiler plugins already do this.

Components

GitChangelog takes commits, optional extra authors, and the display options as props. If your commit records don't include repositoryUrl, pass repository={{ url }} so that #123 issue links work.

To show only contributors:

import { GitContributors } from 'fumadocs-page-history/ui';

<GitContributors commits={commits} authors={authors} />;

A few helpers match what the plugins do:

  • resolveAuthors(names, authorMappings) from fumadocs-page-history/git turns frontmatter authors into author records.
  • shouldShowChangelog(frontmatter) and shouldShowContributors(frontmatter) from fumadocs-page-history apply the per-page settings.

Workspace changes

The Workspace changes guide covers the normal setup. For your own integration, readPageChanges(options, sourcePath) from fumadocs-page-history/workspace returns the comparison as JSON-serializable data.

GitPageChangesView, GitChangeList, GitChangeBlock, and GitChangeText from fumadocs-page-history/ui render that data. They don't access Git or refresh anything themselves; the demo uses them with saved examples.

Contributors

Page history