diff --git a/quartz/components/PageList.tsx b/quartz/components/PageList.tsx index 26593a797646d..b5e6de7e1a7ca 100644 --- a/quartz/components/PageList.tsx +++ b/quartz/components/PageList.tsx @@ -1,9 +1,11 @@ +import path from "path"; import { GlobalConfiguration } from "../cfg"; import { QuartzPluginData } from "../plugins/vfile"; -import { FullSlug, resolveRelative, sluggify } from "../util/path"; +import { FilePath, FullSlug, pathToRoot, resolveRelative, sluggify, slugifyFilePath } from "../util/path"; import { Date, getDate } from "./Date"; import { QuartzComponent, QuartzComponentProps } from "./types"; import fs from 'fs'; +import { pathToFileURL } from "url"; export function byDateAndAlphabetical( cfg: GlobalConfiguration, @@ -47,20 +49,16 @@ export const PageList: QuartzComponent = ({ cfg, fileData, allFiles, limit }: Pr const tags = page.frontmatter?.tags ?? []; const description = page.frontmatter?.description; let image : string | undefined = page.frontmatter?.image as string ?? undefined ; - if (cfg.ogImageDir) { - image = `${cfg.ogImageDir}/${image}` - image = resolveRelative(fileData.slug!, image as FullSlug); - //check if image exists - image = fs.existsSync(image) ? image : undefined; + if (cfg.ogImageDir && image) { + const imageFromOg = `${cfg.ogImageDir}/${image}` + const imageRelative = resolveRelative(fileData.slug!, imageFromOg as FullSlug); + //verify if image exists in `content/_assets/img` folder + image = fs.existsSync(path.resolve(`content/${imageFromOg}`)) ? imageRelative : undefined; } return (