linked-page-path.js 716 B

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