PagePath.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. import React from 'react';
  2. import PropTypes from 'prop-types';
  3. export default class PagePath extends React.Component {
  4. // Original Crowi.linkPath
  5. /*
  6. Crowi.linkPath = function(revisionPath) {
  7. var $revisionPath = revisionPath || '#revision-path';
  8. var $title = $($revisionPath);
  9. var pathData = $('#content-main').data('path');
  10. if (!pathData) {
  11. return ;
  12. }
  13. var realPath = pathData.trim();
  14. if (realPath.substr(-1, 1) == '/') {
  15. realPath = realPath.substr(0, realPath.length - 1);
  16. }
  17. var path = '';
  18. var pathHtml = '';
  19. var splittedPath = realPath.split(/\//);
  20. splittedPath.shift();
  21. splittedPath.forEach(function(sub) {
  22. path += '/';
  23. pathHtml += ' <a href="' + path + '">/</a> ';
  24. if (sub) {
  25. path += sub;
  26. pathHtml += '<a href="' + path + '">' + sub + '</a>';
  27. }
  28. });
  29. if (path.substr(-1, 1) != '/') {
  30. path += '/';
  31. pathHtml += ' <a href="' + path + '" class="last-path">/</a>';
  32. }
  33. $title.html(pathHtml);
  34. };
  35. */
  36. linkPath(path) {
  37. return path;
  38. }
  39. render() {
  40. const page = this.props.page;
  41. const shortPath = this.getShortPath(page.path);
  42. const pathPrefix = page.path.replace(new RegExp(shortPath + '(/)?$'), '');
  43. return (
  44. <span className="page-path">
  45. {pathPrefix}<strong>{shortPath}</strong>
  46. </span>
  47. );
  48. }
  49. }
  50. PagePath.propTypes = {
  51. page: PropTypes.object.isRequired,
  52. };
  53. PagePath.defaultProps = {
  54. page: {},
  55. };