index.md.jsx 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  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 docs207Config from '../../../site_config/docs2-0-7';
  46. import docs300Config from '../../../site_config/docs3-0-0';
  47. import docs301Config from '../../../site_config/docs3-0-1';
  48. import docs302Config from '../../../site_config/docs3-0-2';
  49. import docs303Config from '../../../site_config/docs3-0-3';
  50. import docs304Config from '../../../site_config/docs3-0-4';
  51. import docs305Config from '../../../site_config/docs3-0-5';
  52. import docs306Config from '../../../site_config/docs3-0-6';
  53. import docs310Config from '../../../site_config/docs3-1-0';
  54. import docs311Config from '../../../site_config/docs3-1-1';
  55. import docs312Config from '../../../site_config/docs3-1-2';
  56. import docs313Config from '../../../site_config/docs3-1-3';
  57. import docs314Config from '../../../site_config/docs3-1-4';
  58. import docs315Config from '../../../site_config/docs3-1-5';
  59. import docs316Config from '../../../site_config/docs3-1-6';
  60. import docs317Config from '../../../site_config/docs3-1-7';
  61. import docs318Config from '../../../site_config/docs3-1-8';
  62. import docs319Config from '../../../site_config/docs3-1-9';
  63. import docs320Config from '../../../site_config/docs3-2-0';
  64. import docsDevConfig from '../../../site_config/docsdev';
  65. const docsSource = {
  66. '1.2.0': docs120Config,
  67. '1.2.1': docs121Config,
  68. '1.3.1': docs131Config,
  69. '1.3.2': docs132Config,
  70. '1.3.3': docs133Config,
  71. '1.3.4': docs134Config,
  72. '1.3.5': docs135Config,
  73. '1.3.6': docs136Config,
  74. '1.3.8': docs138Config,
  75. '1.3.9': docs139Config,
  76. '2.0.0': docs200Config,
  77. '2.0.1': docs201Config,
  78. '2.0.2': docs202Config,
  79. '2.0.3': docs203Config,
  80. '2.0.5': docs205Config,
  81. '2.0.6': docs206Config,
  82. '2.0.7': docs207Config,
  83. '3.0.0': docs300Config,
  84. '3.0.1': docs301Config,
  85. '3.0.2': docs302Config,
  86. '3.0.3': docs303Config,
  87. '3.0.4': docs304Config,
  88. '3.0.5': docs305Config,
  89. '3.0.6': docs306Config,
  90. '3.1.0': docs310Config,
  91. '3.1.1': docs311Config,
  92. '3.1.2': docs312Config,
  93. '3.1.3': docs313Config,
  94. '3.1.4': docs314Config,
  95. '3.1.5': docs315Config,
  96. '3.1.6': docs316Config,
  97. '3.1.7': docs317Config,
  98. '3.1.8': docs318Config,
  99. '3.1.9': docs319Config,
  100. '3.2.0': docs320Config,
  101. dev: docsDevConfig,
  102. };
  103. const isValidVersion = version => version && docsSource.hasOwnProperty(version);
  104. class Docs extends Md2Html(Language) {
  105. render() {
  106. const language = this.getLanguage();
  107. let dataSource = {};
  108. // from location path
  109. let version = window.location.pathname.split('/')[3];
  110. if (isValidVersion(version) || version === 'latest') {
  111. cookie.set('docs_version', version);
  112. }
  113. // from rendering html
  114. if (!version && this.props.subdir) {
  115. version = this.props.subdir.split('/')[0];
  116. }
  117. if (isValidVersion(version)) {
  118. dataSource = docsSource[version][language];
  119. } else if (isValidVersion(cookie.get('docs_version'))) {
  120. dataSource = docsSource[cookie.get('docs_version')][language];
  121. } else if (isValidVersion(siteConfig.docsLatest)) {
  122. dataSource = docsSource[siteConfig.docsLatest][language];
  123. dataSource.sidemenu.forEach((menu) => {
  124. menu.children.forEach((submenu) => {
  125. if (!submenu.children) {
  126. submenu.link = submenu.link.replace(`docs/${siteConfig.docsLatest}`, 'docs/latest');
  127. } else {
  128. submenu.children.forEach((menuLevel3) => {
  129. menuLevel3.link = menuLevel3.link.replace(`docs/${siteConfig.docsLatest}`, 'docs/latest');
  130. });
  131. }
  132. });
  133. });
  134. } else {
  135. return null;
  136. }
  137. const __html = this.props.__html || this.state.__html;
  138. return (
  139. <div className="md2html docs-page">
  140. <Header
  141. currentKey="docs"
  142. type="dark"
  143. logo="/img/hlogo_white.svg"
  144. language={language}
  145. onLanguageChange={this.onLanguageChange}
  146. />
  147. <section className="content-section">
  148. <Sidemenu dataSource={dataSource.sidemenu} />
  149. <div
  150. className="doc-content markdown-body"
  151. ref={(node) => { this.markdownContainer = node; }}
  152. dangerouslySetInnerHTML={{ __html }}
  153. />
  154. </section>
  155. <Footer logo="/img/ds_gray.svg" language={language} />
  156. </div>
  157. );
  158. }
  159. }
  160. document.getElementById('root') && ReactDOM.render(<Docs />, document.getElementById('root'));
  161. export default Docs;