linked-page-path.js 788 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. const { pathUtils } = require('growi-commons');
  2. const { isTrashPage } = require('@commons/util/path-utils');
  3. const DevidedPagePath = require('./devided-page-path');
  4. /**
  5. * Linked Array Structured PagePath Model
  6. */
  7. 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. }
  27. module.exports = LinkedPagePath;