Skip to content

Commit

Permalink
fix: add levels to relative path in script tag
Browse files Browse the repository at this point in the history
fixes #129
  • Loading branch information
yassinedoghri committed Mar 5, 2023
1 parent da80a8d commit 1203d42
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/__tests__/cli/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,11 +217,18 @@ describe("resolveRelativePathsLevel(...)", () => {
actual: `const astroGlob = Astro.glob("../foo/*.mdx");`,
expected: `const astroGlob = Astro.glob("../../foo/*.mdx");`,
},
{
name: "with relative src pattern",
actual: `<src="../path/to/script"></script>`,
expected: `<src="../../path/to/script"></script>`,
},
];

codeStringTests.forEach((codeStringTest) => {
it(codeStringTest.name, () => {
resolveRelativePathsLevel(codeStringTest.actual, 1);
expect(resolveRelativePathsLevel(codeStringTest.actual, 1)).toBe(
codeStringTest.expected
);
});
});
});
5 changes: 5 additions & 0 deletions src/cli/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@ export const resolveRelativePathsLevel = (
(_, before, relativePath, after) =>
`${before}${addDepthToRelativePath(relativePath, fileDepth)}${after}`
);
fileContents = fileContents.replace(
/(<src=["'])(\..*)(["'])/g,
(_, before, relativePath, after) =>
`${before}${addDepthToRelativePath(relativePath, fileDepth)}${after}`
);

return fileContents;
};
Expand Down

0 comments on commit 1203d42

Please sign in to comment.