docusaurus/lib/server/env.js
Erin Teo 5771549e75 Rename latestVersion to defaultVersion (#639)
* Rename lastVersion to defaultVersion

* Added defaultVersionShown to site-config doc

* Remove defaultVersionShown from siteConfig

* Update api-site-config.md
2018-05-05 17:24:39 -07:00

69 lines
1.4 KiB
JavaScript

/**
* 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.
*/
const CWD = process.cwd();
const fs = require('fs-extra');
const path = require('path');
const siteConfig = require(CWD + '/siteConfig.js');
const join = path.join;
const languages_js = join(CWD, 'languages.js');
const versions_json = join(CWD, 'versions.json');
class Translation {
constructor() {
this.enabled = false;
this.languages = [
{
enabled: true,
name: 'English',
tag: 'en',
},
];
this._load();
}
enabledLanguages() {
return this.languages.filter(lang => lang.enabled);
}
_load() {
if (fs.existsSync(languages_js)) {
this.enabled = true;
this.languages = require(languages_js);
}
}
}
class Versioning {
constructor() {
this.enabled = false;
this.defaultVersion = null;
this.versions = [];
this._load();
}
_load() {
if (fs.existsSync(versions_json)) {
this.enabled = true;
this.versions = JSON.parse(fs.readFileSync(versions_json, 'utf8'));
this.defaultVersion = siteConfig.defaultVersionShown
? siteConfig.defaultVersionShown
: this.versions[0]; // otherwise show the latest version (other than next/master)
}
}
}
const env = {
translation: new Translation(),
versioning: new Versioning(),
};
module.exports = env;