index.md.jsx 5.7 KB

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