mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-20 04:27:04 +02:00
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:
parent
d4458b394c
commit
85336649d3
66 changed files with 1205 additions and 2292 deletions
|
@ -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`
|
||||
|
|
|
@ -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'));
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -22,6 +22,7 @@ module.exports = function loadConfig(siteDir) {
|
|||
'Loading',
|
||||
'NotFound',
|
||||
'Markdown',
|
||||
'Search',
|
||||
];
|
||||
themeComponents.forEach(component => {
|
||||
if (!require.resolve(path.join(themePath, component))) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue