import React from 'react';
import {NavLink} from 'react-router-dom';
import Search from '@theme/Search';
import styles from './styles.module.css';
function Navbar(props) {
const {siteConfig = {}, env = {}, metadata = {}, docsMetadatas = {}} = props;
const {baseUrl, headerLinks, headerIcon, algolia} = siteConfig;
const {language: thisLanguage, version: thisVersion} = metadata;
const translationEnabled = env.translation.enabled;
const versioningEnabled = env.versioning.enabled;
// function to generate each header link
const makeLinks = link => {
if (link.search && algolia) {
// return algolia search bar
return (
);
}
if (link.languages) {
// TODO in the future for like in v1
return null;
}
if (link.doc) {
// set link to document with current page's language/version
const langPart = translationEnabled ? `${thisLanguage}-` : '';
const versionPart =
versioningEnabled && thisVersion !== 'next'
? `version-${thisVersion || env.versioning.defaultVersion}-`
: '';
const id = langPart + versionPart + link.doc;
if (!docsMetadatas[id]) {
const errorStr = `We could not find the doc wih id: ${id}. Please check your headerLinks correctly\n`;
throw new Error(errorStr);
}
return (
{link.label}
);
}
if (link.page) {
// set link to page with current page's language if appropriate
const pageHref = `${baseUrl}${thisLanguage ? `${thisLanguage}/` : ''}${
link.page
}`;
return (
{link.label}
);
}
if (link.href) {
// set link to specified href
return (