mirror of
https://github.com/facebook/docusaurus.git
synced 2025-12-28 12:33:10 +00:00
* wip: versioning * wip again * nits lint * refactor metadata code so that we can have inobject properties optimization, fix typing * remove buggy permalink code * modify versioned docs fixture such that foo/baz only exists in v1.0.0 * refactor metadata.ts so that there is less transformon object * more refactoring * reduce test fixtures, refactoring * refactoring readability * finish metadata part * refactor with readdir * first pass of implementation * fix mdx laoder * split generated routes by version for performance & smaller bundle * test data for demo * refactor with set * more tests * typo * fix typo * better temporary ui * stronger typing & docsVersion command * add 100% test coverage for docsVersion command * more test and delete manual docs cut * cut 2.0.0-alpha.35 docs * cut alpha.36 instead * copyright * delete versioned docs * stronger test on metadata * update typo
56 lines
1.4 KiB
TypeScript
56 lines
1.4 KiB
TypeScript
/**
|
|
* Copyright (c) 2017-present, Facebook, Inc.
|
|
*
|
|
* This source code is licensed under the MIT license found in the
|
|
* LICENSE file in the root directory of this source tree.
|
|
*/
|
|
|
|
import path from 'path';
|
|
import fs from 'fs-extra';
|
|
import {VersioningEnv, Env} from './types';
|
|
import {
|
|
VERSIONS_JSON_FILE,
|
|
VERSIONED_DOCS_DIR,
|
|
VERSIONED_SIDEBARS_DIR,
|
|
} from './constants';
|
|
|
|
export function getVersionedDocsDir(siteDir: string) {
|
|
return path.join(siteDir, VERSIONED_DOCS_DIR);
|
|
}
|
|
|
|
export function getVersionedSidebarsDir(siteDir: string) {
|
|
return path.join(siteDir, VERSIONED_SIDEBARS_DIR);
|
|
}
|
|
|
|
export function getVersionsJSONFile(siteDir: string) {
|
|
return path.join(siteDir, VERSIONS_JSON_FILE);
|
|
}
|
|
|
|
export default function(siteDir: string): Env {
|
|
const versioning: VersioningEnv = {
|
|
enabled: false,
|
|
versions: [],
|
|
latestVersion: null,
|
|
docsDir: '',
|
|
sidebarsDir: '',
|
|
};
|
|
|
|
const versionsJSONFile = getVersionsJSONFile(siteDir);
|
|
if (fs.existsSync(versionsJSONFile)) {
|
|
const parsedVersions = JSON.parse(
|
|
fs.readFileSync(versionsJSONFile, 'utf8'),
|
|
);
|
|
if (parsedVersions && parsedVersions.length > 0) {
|
|
versioning.latestVersion = parsedVersions[0];
|
|
versioning.enabled = true;
|
|
versioning.versions = parsedVersions;
|
|
versioning.docsDir = getVersionedDocsDir(siteDir);
|
|
versioning.sidebarsDir = getVersionedSidebarsDir(siteDir);
|
|
}
|
|
}
|
|
|
|
return {
|
|
versioning,
|
|
};
|
|
}
|