versions.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /**
  2. * Copyright (c) 2017-present, Facebook, Inc.
  3. *
  4. * This source code is licensed under the MIT license found in the
  5. * LICENSE file in the root directory of this source tree.
  6. */
  7. const React = require('react');
  8. const CompLibrary = require('../../core/CompLibrary');
  9. const Container = CompLibrary.Container;
  10. const GridBlock = CompLibrary.GridBlock;
  11. const CWD = process.cwd();
  12. const siteConfig = require(CWD + '/siteConfig.js');
  13. const versions = require(CWD + '/versions.json');
  14. const repoUrl = `https://github.com/${siteConfig.repoPath}`;
  15. const docsUrl = `${siteConfig.baseUrl}docs`;
  16. const VersionsTable = ({ versions }) => (
  17. <table className="versions">
  18. <tbody>
  19. {versions.map(version => (
  20. <tr key={version.name}>
  21. <th>{version.name}</th>
  22. <td>
  23. <a href={version.docs}>Documentation</a>
  24. </td>
  25. <td>
  26. <a href={version.infoUrl}>{version.infoLabel}</a>
  27. </td>
  28. </tr>
  29. ))}
  30. </tbody>
  31. </table>
  32. );
  33. class Versions extends React.Component {
  34. get latestVersion() {
  35. const name = versions[0];
  36. return [{
  37. name,
  38. docs: docsUrl,
  39. infoLabel: 'Release Notes',
  40. infoUrl: `${repoUrl}/releases/v${name}`
  41. }];
  42. }
  43. get nextVersion() {
  44. return [{
  45. name: 'master',
  46. docs: `${docsUrl}/next`,
  47. infoLabel: 'Source code',
  48. infoUrl: repoUrl
  49. }];
  50. }
  51. get olderVersions() {
  52. return versions.slice(1).map(version => ({
  53. name: version,
  54. docs: `${docsUrl}/${version}/`,
  55. infoLabel: 'Release Notes',
  56. infoUrl: `${repoUrl}/releases/v${version}`
  57. }));
  58. }
  59. render() {
  60. return (
  61. <div className="docMainWrapper wrapper">
  62. <Container className="mainContainer versionsContainer">
  63. <div className="post">
  64. <header className="postHeader">
  65. <h2>{siteConfig.title + ' Versions'}</h2>
  66. </header>
  67. <h3 id="latest">Current version (Stable)</h3>
  68. <p>Latest version of express-validator.</p>
  69. <VersionsTable versions={this.latestVersion}/>
  70. <h3 id="latest">Latest version</h3>
  71. <p>Here you can find the latest documentation and unreleased code.</p>
  72. <VersionsTable versions={this.nextVersion}/>
  73. {this.olderVersions.length > 0 && (
  74. <div>
  75. <h3 id="archive">Past versions</h3>
  76. <p>Here you can find documentation for previous versions of express-validator.</p>
  77. <VersionsTable versions={this.olderVersions}/>
  78. <p>
  79. You can find past versions of this project{' '}
  80. <a href={this.repoUrl}> on GitHub </a>.
  81. </p>
  82. </div>
  83. )}
  84. </div>
  85. </Container>
  86. </div>
  87. );
  88. }
  89. }
  90. module.exports = Versions;