/** * 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 React = require('react'); const classNames = require('classnames'); const siteConfig = require(`${process.cwd()}/siteConfig.js`); const translation = require('../../server/translation.js'); const {getPath, idx} = require('../utils.js'); class SideNav extends React.Component { // return appropriately translated category string getLocalizedCategoryString(category) { const categoryString = idx(translation, [ this.props.language, 'localized-strings', 'categories', category, ]) || category; return categoryString; } // return appropriately translated label to use for doc/blog in sidebar getLocalizedString(metadata) { let localizedString; const i18n = translation[this.props.language]; const id = metadata.localized_id; const sbTitle = metadata.sidebar_label; if (sbTitle) { localizedString = idx(i18n, ['localized-strings', 'docs', id, 'sidebar_label']) || sbTitle; } else { localizedString = idx(i18n, ['localized-strings', 'docs', id, 'title']) || metadata.title; } return localizedString; } // return link to doc in sidebar getLink(metadata) { if (metadata.permalink) { const targetLink = getPath(metadata.permalink, siteConfig.cleanUrl); if (targetLink.match(/^https?:/)) { return targetLink; } return siteConfig.baseUrl + targetLink; } if (metadata.path) { return `${siteConfig.baseUrl}blog/${getPath( metadata.path, siteConfig.cleanUrl, )}`; } return null; } renderCategory(category) { return (

{this.getLocalizedCategoryString(category.name)}

); } renderItemLink(link) { const itemClasses = classNames('navListItem', { navListItemActive: link.id === this.props.current.id, }); return (
  • {this.getLocalizedString(link)}
  • ); } render() { return (