index.md.jsx 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. /*
  2. * Licensed to the Apache Software Foundation (ASF) under one
  3. * or more contributor license agreements. See the NOTICE file
  4. * distributed with this work for additional information
  5. * regarding copyright ownership. The ASF licenses this file
  6. * to you under the Apache License, Version 2.0 (the
  7. * "License"); you may not use this file except in compliance
  8. * with the License. You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing,
  13. * software distributed under the License is distributed on an
  14. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  15. * KIND, either express or implied. See the License for the
  16. * specific language governing permissions and limitations
  17. * under the License.
  18. *
  19. */
  20. import React from 'react';
  21. import ReactDOM from 'react-dom';
  22. import cookie from 'js-cookie';
  23. import Language from '../../components/language';
  24. import Header from '../../components/header';
  25. import Footer from '../../components/footer';
  26. import Md2Html from '../../components/md2html';
  27. import Sidemenu from '../../components/sidemenu';
  28. import siteConfig from '../../../site_config/site';
  29. import docs120Config from '../../../site_config/docs1-2-0';
  30. import docs121Config from '../../../site_config/docs1-2-1';
  31. import docs131Config from '../../../site_config/docs1-3-1';
  32. import docs132Config from '../../../site_config/docs1-3-2';
  33. import docs133Config from '../../../site_config/docs1-3-3';
  34. import docs134Config from '../../../site_config/docs1-3-4';
  35. import docs135Config from '../../../site_config/docs1-3-5';
  36. import docs136Config from '../../../site_config/docs1-3-6';
  37. import docs138Config from '../../../site_config/docs1-3-8';
  38. import docs139Config from '../../../site_config/docs1-3-9';
  39. import docs200Config from '../../../site_config/docs2-0-0';
  40. import docs201Config from '../../../site_config/docs2-0-1';
  41. import docs202Config from '../../../site_config/docs2-0-2';
  42. import docs203Config from '../../../site_config/docs2-0-3';
  43. import docs205Config from '../../../site_config/docs2-0-5';
  44. import docs206Config from '../../../site_config/docs2-0-6';
  45. import docs300Config from '../../../site_config/docs3-0-0';
  46. import docsDevConfig from '../../../site_config/docsdev';
  47. const docsSource = {
  48. '1.2.0': docs120Config,
  49. '1.2.1': docs121Config,
  50. '1.3.1': docs131Config,
  51. '1.3.2': docs132Config,
  52. '1.3.3': docs133Config,
  53. '1.3.4': docs134Config,
  54. '1.3.5': docs135Config,
  55. '1.3.6': docs136Config,
  56. '1.3.8': docs138Config,
  57. '1.3.9': docs139Config,
  58. '2.0.0': docs200Config,
  59. '2.0.1': docs201Config,
  60. '2.0.2': docs202Config,
  61. '2.0.3': docs203Config,
  62. '2.0.5': docs205Config,
  63. '2.0.6': docs206Config,
  64. '3.0.0': docs300Config,
  65. dev: docsDevConfig,
  66. };
  67. const isValidVersion = version => version && docsSource.hasOwnProperty(version);
  68. class Docs extends Md2Html(Language) {
  69. render() {
  70. const language = this.getLanguage();
  71. let dataSource = {};
  72. // from location path
  73. let version = window.location.pathname.split('/')[3];
  74. if (isValidVersion(version) || version === 'latest') {
  75. cookie.set('docs_version', version);
  76. }
  77. // from rendering html
  78. if (!version && this.props.subdir) {
  79. version = this.props.subdir.split('/')[0];
  80. }
  81. if (isValidVersion(version)) {
  82. dataSource = docsSource[version][language];
  83. } else if (isValidVersion(cookie.get('docs_version'))) {
  84. dataSource = docsSource[cookie.get('docs_version')][language];
  85. } else if (isValidVersion(siteConfig.docsLatest)) {
  86. dataSource = docsSource[siteConfig.docsLatest][language];
  87. dataSource.sidemenu.forEach((menu) => {
  88. menu.children.forEach((submenu) => {
  89. if (!submenu.children) {
  90. submenu.link = submenu.link.replace(`docs/${siteConfig.docsLatest}`, 'docs/latest');
  91. } else {
  92. submenu.children.forEach((menuLevel3) => {
  93. menuLevel3.link = menuLevel3.link.replace(`docs/${siteConfig.docsLatest}`, 'docs/latest');
  94. });
  95. }
  96. });
  97. });
  98. } else {
  99. return null;
  100. }
  101. const __html = this.props.__html || this.state.__html;
  102. return (
  103. <div className="md2html docs-page">
  104. <Header
  105. currentKey="docs"
  106. type="dark"
  107. logo="/img/hlogo_white.svg"
  108. language={language}
  109. onLanguageChange={this.onLanguageChange}
  110. />
  111. <section className="content-section">
  112. <Sidemenu dataSource={dataSource.sidemenu} />
  113. <div
  114. className="doc-content markdown-body"
  115. ref={(node) => { this.markdownContainer = node; }}
  116. dangerouslySetInnerHTML={{ __html }}
  117. />
  118. </section>
  119. <Footer logo="/img/ds_gray.svg" language={language} />
  120. </div>
  121. );
  122. }
  123. }
  124. document.getElementById('root') && ReactDOM.render(<Docs />, document.getElementById('root'));
  125. export default Docs;