linked-page-path.js 754 B

123456789101112131415161718192021222324252627282930313233343536
  1. import { pathUtils } from 'growi-commons';
  2. import { isTrashPage } from '@commons/util/path-utils';
  3. import DevidedPagePath from './devided-page-path';
  4. /**
  5. * Linked Array Structured PagePath Model
  6. */
  7. export default class LinkedPagePath {
  8. constructor(path, skipNormalize = false) {
  9. const pagePath = new DevidedPagePath(path, skipNormalize);
  10. this.path = path;
  11. this.pathName = pagePath.latter;
  12. this.isRoot = pagePath.isRoot;
  13. this.parent = pagePath.isRoot
  14. ? null
  15. : new LinkedPagePath(pagePath.former, true);
  16. }
  17. get href() {
  18. if (this.isRoot) {
  19. return '';
  20. }
  21. return pathUtils.normalizePath(`${this.parent.href}/${this.pathName}`);
  22. }
  23. get isInTrash() {
  24. return isTrashPage(this.path);
  25. }
  26. }