summaryrefslogtreecommitdiff
path: root/packages/markdown/remark/src/rehype-images.ts
diff options
context:
space:
mode:
authorGravatar Erika <3019731+Princesseuh@users.noreply.github.com> 2023-04-04 10:21:13 +0200
committerGravatar GitHub <noreply@github.com> 2023-04-04 10:21:13 +0200
commita1a4f45b51a80215fa7598da83bd0d9c5acd20d2 (patch)
treecc6a7ff9586548f1f0f8b3c96746636ec3e060c2 /packages/markdown/remark/src/rehype-images.ts
parent366decbe335d3a84a8b76caac443f07b8a85a6a0 (diff)
downloadastro-a1a4f45b51a80215fa7598da83bd0d9c5acd20d2.tar.gz
astro-a1a4f45b51a80215fa7598da83bd0d9c5acd20d2.tar.zst
astro-a1a4f45b51a80215fa7598da83bd0d9c5acd20d2.zip
fix(images): Simpler logic for collecting images in Markdown (#6744)
Diffstat (limited to 'packages/markdown/remark/src/rehype-images.ts')
-rw-r--r--packages/markdown/remark/src/rehype-images.ts25
1 files changed, 1 insertions, 24 deletions
diff --git a/packages/markdown/remark/src/rehype-images.ts b/packages/markdown/remark/src/rehype-images.ts
index 72f475700..fd1e8f70f 100644
--- a/packages/markdown/remark/src/rehype-images.ts
+++ b/packages/markdown/remark/src/rehype-images.ts
@@ -9,9 +9,7 @@ export function rehypeImages() {
if (node.tagName !== 'img') return;
if (node.properties?.src) {
- if (file.dirname) {
- if (!isRelativePath(node.properties.src) && !isAliasedPath(node.properties.src)) return;
-
+ if (file.data.imagePaths?.has(node.properties.src)) {
node.properties['__ASTRO_IMAGE_'] = node.properties.src;
delete node.properties.src;
}
@@ -19,24 +17,3 @@ export function rehypeImages() {
});
};
}
-
-function isAliasedPath(path: string) {
- return path.startsWith('~/assets');
-}
-
-function isRelativePath(path: string) {
- return startsWithDotDotSlash(path) || startsWithDotSlash(path);
-}
-
-function startsWithDotDotSlash(path: string) {
- const c1 = path[0];
- const c2 = path[1];
- const c3 = path[2];
- return c1 === '.' && c2 === '.' && c3 === '/';
-}
-
-function startsWithDotSlash(path: string) {
- const c1 = path[0];
- const c2 = path[1];
- return c1 === '.' && c2 === '/';
-}