Fix image in meta tags

This commit is contained in:
prototypa
2022-08-24 20:03:23 -04:00
parent bd90eaf841
commit 2738dd1db9
4 changed files with 40 additions and 8 deletions

View File

@ -1,7 +1,9 @@
export const findImage = async (imageRoute) => {
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" &&

13
src/utils/getAllImages.js Normal file
View File

@ -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;
};

View File

@ -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;
};