From 79f910cda2e08dd44a7139cde71193f775113e70 Mon Sep 17 00:00:00 2001 From: Antoine BERNIER Date: Sun, 11 Aug 2024 13:20:27 +0200 Subject: [PATCH] fix: inline images bug --- src/utils/docs.tsx | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/utils/docs.tsx b/src/utils/docs.tsx index 06c76180..24bcb9d7 100644 --- a/src/utils/docs.tsx +++ b/src/utils/docs.tsx @@ -128,10 +128,20 @@ async function _getDocs( // root: "/Users/abernier/code/pmndrs/uikit/docs" // file: "/Users/abernier/code/pmndrs/uikit/docs/advanced/performance.md" // - const relativePath = file.substring(root.length) // "/advanced/performance.md" - const folderPath = relativePath.split('/').slice(0, -1).join('/') // "/advanced" - const url = `${inlineImagesOrigin}${folderPath}/${src}` // "https://github.com/pmndrs/uikit/raw/main/advanced/./basic-example.gif" + // Remove trailing slash from root if it exists + const normalizedRoot = root.endsWith('/') ? root.slice(0, -1) : root + // Extract the last folder name from the root path + const lastFolderName = normalizedRoot.split('/').pop() // "docs" + + // Calculate the relative path from the file path after the root + const relativePath = file.substring(normalizedRoot.length) // "/advanced/performance.md" + // Extract the directory path from the relative path (excluding the file name) + const directoryPath = relativePath.split('/').slice(0, -1).join('/') // "advanced" + // Combine the lastFolderName with the directoryPath using template literals + const folderPath = `/${lastFolderName}/${directoryPath}` // "/docs/advanced" + + const url = `${inlineImagesOrigin}${folderPath}/${src}` // "https://github.com/pmndrs/uikit/raw/main/docs/advanced/./basic-example.gif" return `${prefix}${url}${suffix}` }