From 447fec2ceb362a15e4926deaaa4e4376cc0892c5 Mon Sep 17 00:00:00 2001 From: Timothy Lin Date: Sat, 27 Apr 2024 16:05:35 +0800 Subject: [PATCH] fix absolute image file path for windows --- .../source-files/src/fetchData/mapping/field-image.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/@contentlayer/source-files/src/fetchData/mapping/field-image.ts b/packages/@contentlayer/source-files/src/fetchData/mapping/field-image.ts index b961f280..6468728f 100644 --- a/packages/@contentlayer/source-files/src/fetchData/mapping/field-image.ts +++ b/packages/@contentlayer/source-files/src/fetchData/mapping/field-image.ts @@ -4,6 +4,7 @@ import { fs, unknownToRelativePosixFilePath } from '@contentlayer2/utils' import { identity, OT, pipe, T } from '@contentlayer2/utils/effect' import type * as ImageScript from 'imagescript' import type sharp from 'sharp' +import * as URL from 'url' import { FetchDataError } from '../../errors/index.js' import type { HasDocumentContext } from '../DocumentContext.js' @@ -56,7 +57,7 @@ const getImageFieldData = ({ const documentDirPath = utils.dirname(documentFilePath) const filePath = utils.filePathJoin(documentDirPath, imagePath) - const absoluteFilePath = utils.filePathJoin(contentDirPath, documentDirPath, imagePath) + const absoluteFilePath = URL.pathToFileURL(utils.filePathJoin(contentDirPath, documentDirPath, imagePath)).href const relativeFilePath = utils.relative(utils.filePathJoin(contentDirPath, documentDirPath), absoluteFilePath) const fileBuffer = yield* $(fs.readFileBuffer(absoluteFilePath))