Skip to content

Commit 2584288

Browse files
committed
add VCS documentation
1 parent 541a0ac commit 2584288

1 file changed

Lines changed: 91 additions & 1 deletion

File tree

website/docs/api/docusaurus.config.js.mdx

Lines changed: 91 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,10 +266,100 @@ export default {
266266
- [`rspackPersistentCache`](https://github.com/facebook/docusaurus/pull/10931): Use [Rspack Persistent Cache](https://rspack.dev/config/cache) to re-build your app faster on subsequent builds. Requires `rspackBundler: true`. Requires persisting `./node_modules/.cache` across rebuilds.
267267
- [`mdxCrossCompilerCache`](https://github.com/facebook/docusaurus/pull/10479): Compile MDX files only once for both browser/Node.js environments instead of twice.
268268
- [`ssgWorkerThreads`](https://github.com/facebook/docusaurus/pull/10826): Using a Node.js worker thread pool to execute the static site generation phase faster. Requires `future.v4.removeLegacyPostBuildHeadAttribute` to be turned on.
269+
- [`gitEagerVcs`](https://github.com/facebook/docusaurus/pull/11512): Upgrades the default [VCS strategy](#vcs) to `default-v2`, that reads your whole Git repository at once instead of per-file, making Git operations faster on large repositories.
269270
- `experimental_storage`: Site-wide browser storage options that theme authors should strive to respect.
270271
- `type`: The browser storage theme authors should use. Possible values are `localStorage` and `sessionStorage`. Defaults to `localStorage`.
271272
- `namespace`: Whether to namespace the browser storage keys to avoid storage key conflicts when Docusaurus sites are hosted under the same domain, or on localhost. Possible values are `string | boolean`. The namespace is appended at the end of the storage keys `key-namespace`. Use `true` to automatically generate a random namespace from your site `url + baseUrl`. Defaults to `false` (no namespace, historical behavior).
272273
- `experimental_router`: The router type to use. Possible values are `browser` and `hash`. Defaults to `browser`. The `hash` router is only useful for rare cases where you want to opt-out of static site generation, have a fully client-side app with a single `index.html` entrypoint file. This can be useful to distribute a Docusaurus site as a `.zip` archive that you can [browse locally without running a web server](https://github.com/facebook/docusaurus/issues/3825).
274+
- [`experimental_vcs`](#vcs): The Version Control System (VCS) implementation to use to read file info (creation/last update date/author). Read the [dedicated section](#vcs) below for details.
275+
276+
#### `experimental_vcs` {#vcs}
277+
278+
This exposes an API that lets you provide your own Version Control System (VCS) implementation to read file info (creation/last update date/author).
279+
280+
```ts
281+
export default {
282+
future: {
283+
experimental_vcs: {
284+
initialize: ({siteDir}) => {
285+
// Initialize your VCS client here.
286+
// If you want to read your VCS eagerly/incrementally on startup,
287+
// this is the place to do it.
288+
// This function is synchronous on purpose and not awaited
289+
// It should not delay Docusaurus startup, but be run in parallel.
290+
},
291+
getFileCreationInfo: async (filePath: string) => {
292+
// Provide your own implementation to read file creation info.
293+
return getFileCreationInfo(filePath);
294+
},
295+
getFileLastUpdateInfo: async (filePath: string) => {
296+
// Provide your own implementation to read file creation info.
297+
return getFileLastUpdateInfo(filePath);
298+
},
299+
},
300+
},
301+
};
302+
```
303+
304+
##### VCS Presets {#vcs-presets}
305+
306+
It is possible to pass a boolean VCS value:
307+
308+
- `true`: enables the default VCS preset (`default-v1` or `default-v2`, depending on the Docusaurus Faster `gitEagerVcs` flag value)
309+
- `false`: disables the VCS, always returns `null` for all files
310+
311+
```ts
312+
export default {
313+
future: {
314+
experimental_vcs: true, // Enables the default VCS preset
315+
},
316+
};
317+
```
318+
319+
It is also possible to choose VCS preset we provide out of the box by its name.
320+
321+
```ts
322+
export default {
323+
future: {
324+
experimental_vcs: 'presetName',
325+
},
326+
};
327+
```
328+
329+
The available preset names are:
330+
331+
- `git-ad-hoc`: the historical `git log <filename>` based strategy.
332+
- `git-eager`: the new Git strategy that reads your whole repository upfront.
333+
- `hardcoded`: returns hardcoded value, useful in dev/tests to speed up developer experience.
334+
- `disabled`: returns `null` for all files, considering them untracked.
335+
- `default-v1`: the historical default (`git-ad-hoc` in prod, `hardcoded` in dev)
336+
- `default-v2`: the upcoming default (`git-eager` in prod, `hardcoded` in dev)
337+
338+
Unless you have specific needs, we recommend using the default presets (`default-v1` or `default-v2`), that skip reading file info in development mode for better performance.
339+
340+
##### VCS Types {#vcs-types}
341+
342+
```ts
343+
type VcsChangeInfo = {timestamp: number; author: string};
344+
345+
type VscInitializeParams = {
346+
siteDir: string;
347+
};
348+
349+
type VcsConfig = {
350+
initialize: (params: VscInitializeParams) => void;
351+
getFileCreationInfo: (filePath: string) => Promise<VcsChangeInfo | null>;
352+
getFileLastUpdateInfo: (filePath: string) => Promise<VcsChangeInfo | null>;
353+
};
354+
355+
type VcsPreset =
356+
| 'git-ad-hoc'
357+
| 'git-eager'
358+
| 'hardcoded'
359+
| 'disabled'
360+
| 'default-v1'
361+
| 'default-v2';
362+
```
273363

274364
### `noIndex` {#noIndex}
275365

@@ -540,7 +630,7 @@ type MDX1CompatOptions =
540630
headingIds: boolean;
541631
};
542632

543-
export type ParseFrontMatter = (params: {
633+
type ParseFrontMatter = (params: {
544634
filePath: string;
545635
fileContent: string;
546636
defaultParseFrontMatter: ParseFrontMatter;

0 commit comments

Comments
 (0)