collect-ancestor-paths.ts 497 B

1234567891011121314151617
  1. import { dirname } from 'node:path';
  2. import { isTopPage } from '@growi/core/dist/utils/page-path-utils';
  3. /**
  4. * returns ancestors paths
  5. * @param {string} path
  6. * @param {string[]} ancestorPaths
  7. * @returns {string[]}
  8. */
  9. export const collectAncestorPaths = (path: string, ancestorPaths: string[] = []): string[] => {
  10. if (isTopPage(path)) return ancestorPaths;
  11. const parentPath = dirname(path);
  12. ancestorPaths.push(parentPath);
  13. return collectAncestorPaths(parentPath, ancestorPaths);
  14. };