linked-page-path.js 727 B

1234567891011121314151617181920212223242526272829303132
  1. import { DevidedPagePath } from '@growi/core/dist/models';
  2. import { pagePathUtils, pathUtils } from '@growi/core/dist/utils';
  3. const { isTrashPage } = pagePathUtils;
  4. /**
  5. * Linked Array Structured PagePath Model
  6. */
  7. export default class LinkedPagePath {
  8. constructor(path) {
  9. const pagePath = new DevidedPagePath(path);
  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. }