feat(v2): headerlinks (#1074)

* feat(v2): headerlinks

* fix test

* nits

* remove tictactoe:

* headerIcon

* nits

* remove lang dropdown

* fix failing test

* search box

* algolia search

* use babel-eslint to resolve dynamic import

* nits

* favicon and title

* Update .eslintignore
This commit is contained in:
Endilie Yacop Sucipto 2018-10-28 16:32:19 +08:00 committed by GitHub
parent d4458b394c
commit 85336649d3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
66 changed files with 1205 additions and 2292 deletions

View file

@ -25,6 +25,9 @@ module.exports = function loadConfig(siteDir, deleteCache = true) {
'projectName',
'baseUrl',
'url',
'headerLinks',
'headerIcon',
'favicon',
];
const optionalFields = [
'customDocsPath',
@ -36,6 +39,7 @@ module.exports = function loadConfig(siteDir, deleteCache = true) {
'docsUrl',
'customFields',
'githubHost',
'algolia',
];
const missingFields = requiredFields.filter(field => !config[field]);
if (missingFields && missingFields.length > 0) {
@ -55,6 +59,30 @@ module.exports = function loadConfig(siteDir, deleteCache = true) {
}
});
/* Build final headerLinks based on siteConfig */
const {headerLinks} = config;
// add language drop down to end if location not specified
let languages = false;
headerLinks.forEach(link => {
if (link.languages) {
languages = true;
}
});
if (!languages) {
headerLinks.push({languages: true});
}
let search = false;
headerLinks.forEach(link => {
// We will add search bar to end if location not specified
if (link.search) {
search = true;
}
});
if (!search && config.algolia) {
headerLinks.push({search: true});
}
config.headerLinks = headerLinks;
/*
User's own array of custom fields,
e.g: if they want to include some field so they can access it later from `props.siteConfig`

View file

@ -18,6 +18,7 @@ module.exports = function loadEnv({siteDir, siteConfig}) {
};
const languagesFile = path.join(siteDir, 'languages.js');
delete require.cache[languagesFile];
if (fs.existsSync(languagesFile)) {
const languages = require(languagesFile); // eslint-disable-line
@ -52,6 +53,7 @@ module.exports = function loadEnv({siteDir, siteConfig}) {
};
const versionsJSONFile = path.join(siteDir, 'versions.json');
delete require.cache[versionsJSONFile];
if (fs.existsSync(versionsJSONFile)) {
versioning.enabled = true;
versioning.versions = JSON.parse(fs.readFileSync(versionsJSONFile, 'utf8'));

View file

@ -25,6 +25,7 @@ module.exports = async function load(siteDir) {
// @tested - env
const env = loadEnv({siteDir, siteConfig});
await generate('env.js', `export default ${JSON.stringify(env, null, 2)};`);
// docs
const docsDir = path.resolve(siteDir, '..', siteConfig.customDocsPath);

View file

@ -22,6 +22,7 @@ module.exports = function loadConfig(siteDir) {
'Loading',
'NotFound',
'Markdown',
'Search',
];
themeComponents.forEach(component => {
if (!require.resolve(path.join(themePath, component))) {