index.md.jsx 5.8 KB

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