diff --git a/src/components/core/MetaTags.astro b/src/components/core/MetaTags.astro
index 8e5f1c6..59dc897 100644
--- a/src/components/core/MetaTags.astro
+++ b/src/components/core/MetaTags.astro
@@ -1,5 +1,6 @@
---
import { getImage } from "@astrojs/image";
+import { getRelativeUrlByFilePath } from "~/utils/getRelativeUrlByFilePath";
const { src: defaultImage } = await getImage({
src: import("~/assets/images/default.png"),
@@ -10,11 +11,16 @@ const { src: defaultImage } = await getImage({
const {
title = "AstroWind",
description = "",
- image = defaultImage,
+ image: _image = defaultImage,
canonical,
} = Astro.props;
-const absoluteImageUrl = new URL(image, Astro.site);
+const image =
+ typeof _image === "string"
+ ? new URL(_image, Astro.site)
+ : typeof _image["src"] !== "undefined"
+ ? new URL(getRelativeUrlByFilePath(_image.src), Astro.site)
+ : null;
---
@@ -28,21 +34,21 @@ const absoluteImageUrl = new URL(image, Astro.site);
-
+{image && }
{canonical && }
-
+{image && }
{canonical && }
-
+{image && }
{
- const images = import.meta.glob("../assets/images/*");
+import { getAllImages } from "~/utils/getAllImages";
- const key = imageRoute.replace("~/", "../");
+export const findImage = async (imageRoute) => {
+ const images = await getAllImages();
+
+ const key = imageRoute.replace("~/", "/src/");
const image =
typeof imageRoute === "string" &&
diff --git a/src/utils/getAllImages.js b/src/utils/getAllImages.js
new file mode 100644
index 0000000..6654ae8
--- /dev/null
+++ b/src/utils/getAllImages.js
@@ -0,0 +1,13 @@
+const load = async function () {
+ const images = import.meta.glob("~/assets/images/*");
+
+ return images;
+};
+
+let _images;
+
+export const getAllImages = async () => {
+ _images = _images || load();
+
+ return await _images;
+};
diff --git a/src/utils/getRelativeUrlByFilePath.js b/src/utils/getRelativeUrlByFilePath.js
new file mode 100644
index 0000000..49b73c9
--- /dev/null
+++ b/src/utils/getRelativeUrlByFilePath.js
@@ -0,0 +1,11 @@
+import * as url from "url";
+
+const __src = url.fileURLToPath(new URL("../", import.meta.url));
+
+export const getRelativeUrlByFilePath = (filepath) => {
+ if (filepath) {
+ return "/" + filepath.substring(__src.length);
+ }
+
+ return null;
+};