mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-10 07:37:19 +02:00
feat(v2): add disableVersioning config to docs plugin (#2989)
* add disableVersioning config to docs plugin * fix test * fix test
This commit is contained in:
parent
9265de982b
commit
a5b2b6056b
8 changed files with 44 additions and 16 deletions
|
@ -24,6 +24,13 @@ describe('loadEnv', () => {
|
|||
expect(env.versioning.versions).toStrictEqual(['1.0.1', '1.0.0']);
|
||||
});
|
||||
|
||||
test('website with versioning but disabled', () => {
|
||||
const siteDir = path.join(__dirname, '__fixtures__', 'versioned-site');
|
||||
const env = loadEnv(siteDir, {disableVersioning: true});
|
||||
expect(env.versioning.enabled).toBe(false);
|
||||
expect(env.versioning.versions).toStrictEqual([]);
|
||||
});
|
||||
|
||||
test('website with invalid versions.json file', () => {
|
||||
const siteDir = path.join(__dirname, '__fixtures__', 'versioned-site');
|
||||
const mock = jest.spyOn(JSON, 'parse').mockImplementationOnce(() => {
|
||||
|
|
|
@ -39,6 +39,7 @@ describe('normalizeDocsPluginOptions', () => {
|
|||
showLastUpdateAuthor: true,
|
||||
admonitions: {},
|
||||
excludeNextVersionDocs: true,
|
||||
disableVersioning: true,
|
||||
};
|
||||
|
||||
const {value} = await PluginOptionSchema.validate(userOptions);
|
||||
|
|
|
@ -26,7 +26,12 @@ export function getVersionsJSONFile(siteDir: string): string {
|
|||
return path.join(siteDir, VERSIONS_JSON_FILE);
|
||||
}
|
||||
|
||||
export default function (siteDir: string): Env {
|
||||
type EnvOptions = Partial<{disableVersioning: boolean}>;
|
||||
|
||||
export default function (
|
||||
siteDir: string,
|
||||
options: EnvOptions = {disableVersioning: false},
|
||||
): Env {
|
||||
const versioning: VersioningEnv = {
|
||||
enabled: false,
|
||||
versions: [],
|
||||
|
@ -37,6 +42,7 @@ export default function (siteDir: string): Env {
|
|||
|
||||
const versionsJSONFile = getVersionsJSONFile(siteDir);
|
||||
if (fs.existsSync(versionsJSONFile)) {
|
||||
if (!options.disableVersioning) {
|
||||
const parsedVersions = JSON.parse(
|
||||
fs.readFileSync(versionsJSONFile, 'utf8'),
|
||||
);
|
||||
|
@ -49,6 +55,7 @@ export default function (siteDir: string): Env {
|
|||
versioning.sidebarsDir = getVersionedSidebarsDir(siteDir);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
versioning,
|
||||
|
|
|
@ -95,7 +95,7 @@ export default function pluginContentDocs(
|
|||
);
|
||||
|
||||
// Versioning.
|
||||
const env = loadEnv(siteDir);
|
||||
const env = loadEnv(siteDir, {disableVersioning: options.disableVersioning});
|
||||
const {versioning} = env;
|
||||
const {
|
||||
versions,
|
||||
|
|
|
@ -23,6 +23,7 @@ export const DEFAULT_OPTIONS: PluginOptions = {
|
|||
showLastUpdateAuthor: false,
|
||||
admonitions: {},
|
||||
excludeNextVersionDocs: false,
|
||||
disableVersioning: false,
|
||||
};
|
||||
|
||||
export const PluginOptionSchema = Joi.object({
|
||||
|
@ -51,4 +52,5 @@ export const PluginOptionSchema = Joi.object({
|
|||
excludeNextVersionDocs: Joi.bool().default(
|
||||
DEFAULT_OPTIONS.excludeNextVersionDocs,
|
||||
),
|
||||
disableVersioning: Joi.bool().default(DEFAULT_OPTIONS.disableVersioning),
|
||||
});
|
||||
|
|
|
@ -25,6 +25,7 @@ export interface PluginOptions extends MetadataOptions, PathOptions {
|
|||
remarkPlugins: ([Function, object] | Function)[];
|
||||
rehypePlugins: string[];
|
||||
admonitions: any;
|
||||
disableVersioning: boolean;
|
||||
excludeNextVersionDocs: boolean;
|
||||
}
|
||||
|
||||
|
|
|
@ -100,8 +100,12 @@ module.exports = function(context, options) {
|
|||
// ...
|
||||
return {
|
||||
name: 'my-docusaurus-plugin',
|
||||
async loadContent() { ... },
|
||||
async contentLoaded({content, actions}) { ... },
|
||||
async loadContent() {
|
||||
/* ... */
|
||||
},
|
||||
async contentLoaded({content, actions}) {
|
||||
/* ... */
|
||||
},
|
||||
/* other lifecycle API */
|
||||
};
|
||||
};
|
||||
|
@ -113,7 +117,7 @@ The `my-plugin` folder could also be a fully fledged package with it's own packa
|
|||
|
||||
`context` is plugin-agnostic and the same object will be passed into all plugins used for a Docusaurus website. The `context` object contains the following fields:
|
||||
|
||||
```js
|
||||
```ts
|
||||
interface LoadContext {
|
||||
siteDir: string;
|
||||
generatedFilesDir: string;
|
||||
|
@ -288,6 +292,11 @@ module.exports = {
|
|||
* Whether to display the last date the doc was updated.
|
||||
*/
|
||||
showLastUpdateTime: false,
|
||||
/**
|
||||
* By default, versioning is enabled on versioned sites.
|
||||
* This is a way to explicitly disable the versioning feature.
|
||||
*/
|
||||
disableVersioning: false,
|
||||
/**
|
||||
* Skip the next release docs when versioning is enabled.
|
||||
* This will not generate HTML files in the production build for documents
|
||||
|
|
|
@ -63,6 +63,7 @@ module.exports = {
|
|||
showLastUpdateAuthor: true,
|
||||
showLastUpdateTime: true,
|
||||
remarkPlugins: [require('./src/plugins/remark-npm2yarn')],
|
||||
disableVersioning: !!process.env.DISABLE_VERSIONING,
|
||||
},
|
||||
blog: {
|
||||
path: '../website-1.x/blog',
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue