Fix image in meta tags
This commit is contained in:
@ -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
13
src/utils/getAllImages.js
Normal 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;
|
||||
};
|
11
src/utils/getRelativeUrlByFilePath.js
Normal file
11
src/utils/getRelativeUrlByFilePath.js
Normal 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;
|
||||
};
|
Reference in New Issue
Block a user