mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-28 00:17:14 +02:00
feat(v2): blog + docs multi-instance plugins (#3204)
* stable createData namespacing + second-blog dogfooding * Docs: support multi-instance + make community docs a separate instance * tests: add 2nd docs instance to versioned site * fix docs version cli tests * fix docs versioning cli * typo * team: add link to my site * better extendCli integration * fix metadata tests * tests for versioned site with second docs instance * move some validation code to utils-validation * fix missing dependency * fix bad compiled output due to importing constants in ./client folder * make docs tests easier to maintain * refactors * prevent lodash imports in client bundle * redirect old community docs to new urls
This commit is contained in:
parent
e944f35640
commit
59f705ee66
67 changed files with 2025 additions and 2059 deletions
packages/docusaurus-plugin-content-docs/src
|
@ -14,24 +14,49 @@ import {
|
|||
VERSIONED_SIDEBARS_DIR,
|
||||
} from './constants';
|
||||
|
||||
export function getVersionedDocsDir(siteDir: string): string {
|
||||
return path.join(siteDir, VERSIONED_DOCS_DIR);
|
||||
import {DEFAULT_PLUGIN_ID} from '@docusaurus/core/lib/constants';
|
||||
|
||||
// retro-compatibility: no prefix for the default plugin id
|
||||
function addPluginIdPrefix(fileOrDir: string, pluginId: string): string {
|
||||
if (pluginId === DEFAULT_PLUGIN_ID) {
|
||||
return fileOrDir;
|
||||
} else {
|
||||
return `${pluginId}_${fileOrDir}`;
|
||||
}
|
||||
}
|
||||
|
||||
export function getVersionedSidebarsDir(siteDir: string): string {
|
||||
return path.join(siteDir, VERSIONED_SIDEBARS_DIR);
|
||||
export function getVersionedDocsDir(siteDir: string, pluginId: string): string {
|
||||
return path.join(siteDir, addPluginIdPrefix(VERSIONED_DOCS_DIR, pluginId));
|
||||
}
|
||||
|
||||
export function getVersionsJSONFile(siteDir: string): string {
|
||||
return path.join(siteDir, VERSIONS_JSON_FILE);
|
||||
export function getVersionedSidebarsDir(
|
||||
siteDir: string,
|
||||
pluginId: string,
|
||||
): string {
|
||||
return path.join(
|
||||
siteDir,
|
||||
addPluginIdPrefix(VERSIONED_SIDEBARS_DIR, pluginId),
|
||||
);
|
||||
}
|
||||
|
||||
export function getVersionsJSONFile(siteDir: string, pluginId: string): string {
|
||||
return path.join(siteDir, addPluginIdPrefix(VERSIONS_JSON_FILE, pluginId));
|
||||
}
|
||||
|
||||
type EnvOptions = Partial<{disableVersioning: boolean}>;
|
||||
|
||||
export default function (
|
||||
siteDir: string,
|
||||
pluginId: string,
|
||||
options: EnvOptions = {disableVersioning: false},
|
||||
): Env {
|
||||
if (!siteDir) {
|
||||
throw new Error('unexpected, missing siteDir');
|
||||
}
|
||||
if (!pluginId) {
|
||||
throw new Error('unexpected, missing pluginId');
|
||||
}
|
||||
|
||||
const versioning: VersioningEnv = {
|
||||
enabled: false,
|
||||
versions: [],
|
||||
|
@ -40,7 +65,7 @@ export default function (
|
|||
sidebarsDir: '',
|
||||
};
|
||||
|
||||
const versionsJSONFile = getVersionsJSONFile(siteDir);
|
||||
const versionsJSONFile = getVersionsJSONFile(siteDir, pluginId);
|
||||
if (fs.existsSync(versionsJSONFile)) {
|
||||
if (!options.disableVersioning) {
|
||||
const parsedVersions = JSON.parse(
|
||||
|
@ -51,8 +76,8 @@ export default function (
|
|||
versioning.latestVersion = parsedVersions[0];
|
||||
versioning.enabled = true;
|
||||
versioning.versions = parsedVersions;
|
||||
versioning.docsDir = getVersionedDocsDir(siteDir);
|
||||
versioning.sidebarsDir = getVersionedSidebarsDir(siteDir);
|
||||
versioning.docsDir = getVersionedDocsDir(siteDir, pluginId);
|
||||
versioning.sidebarsDir = getVersionedSidebarsDir(siteDir, pluginId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue