1 | "use strict";
|
2 |
|
3 | exports.__esModule = true;
|
4 | exports.withBasePath = withBasePath;
|
5 | exports.withTrailingSlash = withTrailingSlash;
|
6 | exports.getCommonDir = getCommonDir;
|
7 |
|
8 | const path = require(`path`);
|
9 |
|
10 | const {
|
11 | joinPath
|
12 | } = require(`gatsby-core-utils`);
|
13 |
|
14 | function withBasePath(basePath) {
|
15 | return (...paths) => joinPath(basePath, ...paths);
|
16 | }
|
17 |
|
18 | function withTrailingSlash(basePath) {
|
19 | return `${basePath}/`;
|
20 | }
|
21 |
|
22 | const posixJoinWithLeadingSlash = paths => path.posix.join(...paths.map((segment, index) => segment === `` && index === 0 ? `/` : segment));
|
23 |
|
24 | function getCommonDir(path1, path2) {
|
25 | const path1Segments = path1.split(/[/\\]/);
|
26 | const path2Segments = path2.split(/[/\\]/);
|
27 |
|
28 | for (let i = 0; i < path1Segments.length; i++) {
|
29 | if (i >= path2Segments.length) {
|
30 | return posixJoinWithLeadingSlash(path2Segments);
|
31 | } else if (path1Segments[i].toLowerCase() !== path2Segments[i].toLowerCase()) {
|
32 | const joined = path1Segments.slice(0, i);
|
33 | return posixJoinWithLeadingSlash(joined);
|
34 | }
|
35 | }
|
36 |
|
37 | return posixJoinWithLeadingSlash(path1Segments);
|
38 | }
|
39 |
|
\ | No newline at end of file |