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`