@ndla/ui 55.0.6-alpha.0 → 55.0.6-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/es/utils/relativeUrl.js
CHANGED
|
@@ -23,13 +23,15 @@ export const getPossiblyRelativeUrl = (url, path) => {
|
|
|
23
23
|
// If the host is the same, return the relative path
|
|
24
24
|
if (urlObj.hostname.replace(REPLACE_WWW, "") === pathObj.hostname.replace(REPLACE_WWW, "")) {
|
|
25
25
|
// Replace the language part of the url with the language part of the path
|
|
26
|
+
// Keep the search params if they exist
|
|
27
|
+
const search = urlObj.search;
|
|
26
28
|
// If the path language part does not exist, remove it.
|
|
27
29
|
const urlMatch = urlObj.pathname.match(LANGUAGE_REGEX);
|
|
28
30
|
const pathMatch = pathObj.pathname.match(LANGUAGE_REGEX);
|
|
29
31
|
if (urlMatch !== null && urlMatch !== void 0 && urlMatch[1] && (urlMatch === null || urlMatch === void 0 ? void 0 : urlMatch[1]) !== (pathMatch === null || pathMatch === void 0 ? void 0 : pathMatch[1])) {
|
|
30
|
-
return urlObj.pathname.replace(urlMatch[1], (pathMatch === null || pathMatch === void 0 ? void 0 : pathMatch[1]) || "");
|
|
32
|
+
return "".concat(urlObj.pathname.replace(urlMatch[1], (pathMatch === null || pathMatch === void 0 ? void 0 : pathMatch[1]) || "")).concat(search);
|
|
31
33
|
}
|
|
32
|
-
return urlObj.pathname;
|
|
34
|
+
return "".concat(urlObj.pathname).concat(search);
|
|
33
35
|
}
|
|
34
36
|
return url;
|
|
35
37
|
};
|
package/lib/utils/relativeUrl.js
CHANGED
|
@@ -29,13 +29,15 @@ const getPossiblyRelativeUrl = (url, path) => {
|
|
|
29
29
|
// If the host is the same, return the relative path
|
|
30
30
|
if (urlObj.hostname.replace(REPLACE_WWW, "") === pathObj.hostname.replace(REPLACE_WWW, "")) {
|
|
31
31
|
// Replace the language part of the url with the language part of the path
|
|
32
|
+
// Keep the search params if they exist
|
|
33
|
+
const search = urlObj.search;
|
|
32
34
|
// If the path language part does not exist, remove it.
|
|
33
35
|
const urlMatch = urlObj.pathname.match(LANGUAGE_REGEX);
|
|
34
36
|
const pathMatch = pathObj.pathname.match(LANGUAGE_REGEX);
|
|
35
37
|
if (urlMatch !== null && urlMatch !== void 0 && urlMatch[1] && (urlMatch === null || urlMatch === void 0 ? void 0 : urlMatch[1]) !== (pathMatch === null || pathMatch === void 0 ? void 0 : pathMatch[1])) {
|
|
36
|
-
return urlObj.pathname.replace(urlMatch[1], (pathMatch === null || pathMatch === void 0 ? void 0 : pathMatch[1]) || "");
|
|
38
|
+
return "".concat(urlObj.pathname.replace(urlMatch[1], (pathMatch === null || pathMatch === void 0 ? void 0 : pathMatch[1]) || "")).concat(search);
|
|
37
39
|
}
|
|
38
|
-
return urlObj.pathname;
|
|
40
|
+
return "".concat(urlObj.pathname).concat(search);
|
|
39
41
|
}
|
|
40
42
|
return url;
|
|
41
43
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ndla/ui",
|
|
3
|
-
"version": "55.0.6-alpha.
|
|
3
|
+
"version": "55.0.6-alpha.1",
|
|
4
4
|
"description": "UI component library for NDLA.",
|
|
5
5
|
"license": "GPL-3.0",
|
|
6
6
|
"main": "lib/index.js",
|
|
@@ -76,5 +76,5 @@
|
|
|
76
76
|
"publishConfig": {
|
|
77
77
|
"access": "public"
|
|
78
78
|
},
|
|
79
|
-
"gitHead": "
|
|
79
|
+
"gitHead": "63a1e8dbc12f6d268aa3140f408d1b1241c36a80"
|
|
80
80
|
}
|
|
@@ -75,4 +75,16 @@ describe("getPossibleRelativeUrl", () => {
|
|
|
75
75
|
|
|
76
76
|
expect(getPossiblyRelativeUrl(url, pathname)).toEqual("mailto:test@ndla.no");
|
|
77
77
|
});
|
|
78
|
+
it("handles params in url", () => {
|
|
79
|
+
const url = "https://ndla.no/search?grepCodes=KM123";
|
|
80
|
+
const pathname = "https://ndla.no/article/666";
|
|
81
|
+
|
|
82
|
+
expect(getPossiblyRelativeUrl(url, pathname)).toEqual("/search?grepCodes=KM123");
|
|
83
|
+
});
|
|
84
|
+
it("handles params in url including language tag", () => {
|
|
85
|
+
const url = "https://ndla.no/nb/search?grepCodes=KM123";
|
|
86
|
+
const pathname = "https://ndla.no/en/article/666";
|
|
87
|
+
|
|
88
|
+
expect(getPossiblyRelativeUrl(url, pathname)).toEqual("/en/search?grepCodes=KM123");
|
|
89
|
+
});
|
|
78
90
|
});
|
package/src/utils/relativeUrl.ts
CHANGED
|
@@ -26,14 +26,16 @@ export const getPossiblyRelativeUrl = (url: string, path?: string) => {
|
|
|
26
26
|
// If the host is the same, return the relative path
|
|
27
27
|
if (urlObj.hostname.replace(REPLACE_WWW, "") === pathObj.hostname.replace(REPLACE_WWW, "")) {
|
|
28
28
|
// Replace the language part of the url with the language part of the path
|
|
29
|
+
// Keep the search params if they exist
|
|
30
|
+
const search = urlObj.search;
|
|
29
31
|
// If the path language part does not exist, remove it.
|
|
30
32
|
const urlMatch = urlObj.pathname.match(LANGUAGE_REGEX);
|
|
31
33
|
const pathMatch = pathObj.pathname.match(LANGUAGE_REGEX);
|
|
32
34
|
if (urlMatch?.[1] && urlMatch?.[1] !== pathMatch?.[1]) {
|
|
33
|
-
return urlObj.pathname.replace(urlMatch[1], pathMatch?.[1] || "")
|
|
35
|
+
return `${urlObj.pathname.replace(urlMatch[1], pathMatch?.[1] || "")}${search}`;
|
|
34
36
|
}
|
|
35
37
|
|
|
36
|
-
return urlObj.pathname
|
|
38
|
+
return `${urlObj.pathname}${search}`;
|
|
37
39
|
}
|
|
38
40
|
return url;
|
|
39
41
|
};
|