Skip to content

Commit 363497c

Browse files
committed
fix: import getRelativePath and remove unused getPath function in fetchSrc.js
1 parent fd04107 commit 363497c

File tree

1 file changed

+5
-13
lines changed

1 file changed

+5
-13
lines changed

src/fetchSrc.js

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import observer from "@cocreate/observer";
2-
import { ObjectId } from "@cocreate/utils";
2+
import { getRelativePath, ObjectId } from "@cocreate/utils";
33

44
const selector =
55
"[src]:not(img, video, audio, script, input, iframe, frame, link, source), [source], [stream]";
@@ -44,9 +44,11 @@ async function initElements(elements) {
4444
let path = "";
4545
let pathElement = element.closest("[path]");
4646
if (pathElement) {
47-
path = pathElement.getAttribute("path") || getPath();
47+
path =
48+
pathElement.getAttribute("path") ||
49+
getRelativePath();
4850
} else {
49-
path = getPath();
51+
path = getRelativePath();
5052
}
5153
// Replace $relativePath in the fetched text
5254
if (path) {
@@ -66,16 +68,6 @@ async function initElements(elements) {
6668
}
6769
}
6870

69-
function getPath() {
70-
let currentPath = window.location.pathname.replace(/\/[^\/]*$/, ""); // Remove file from path
71-
if (!currentPath.endsWith("/")) {
72-
currentPath += "/";
73-
}
74-
let depth = currentPath.split("/").filter(Boolean).length; // Count depth levels
75-
76-
return depth > 0 ? "../".repeat(depth) : "./"; // Return the correct relative path
77-
}
78-
7971
async function initMediaSource(element, src) {
8072
try {
8173
let mediaConfig = await response.json();

0 commit comments

Comments
 (0)