From 6ace28d87c24aa82e6c1c7b240dadfbf2f12f216 Mon Sep 17 00:00:00 2001 From: okadurin Date: Mon, 6 Nov 2023 13:42:30 +0100 Subject: [PATCH] chore: fix dynamic imports --- src/pages/[top]/[...slug].astro | 7 +++++++ src/pages/components/[component].astro | 8 ++++---- .../remark-plugings/copyMdjsStories/copyMdjsStories.js | 5 ++--- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/pages/[top]/[...slug].astro b/src/pages/[top]/[...slug].astro index d3d2074794..d1d4faf454 100644 --- a/src/pages/[top]/[...slug].astro +++ b/src/pages/[top]/[...slug].astro @@ -1,5 +1,6 @@ --- import MainLayout from '../../layouts/MainLayout.astro'; +import * as path from 'path'; import { fundamentalsEntries } from '../../content'; import { blogEntries } from '../../content'; import { guideEntries } from '../../content'; @@ -37,6 +38,11 @@ const { entry } = Astro.props; const { Content } = await entry.render(); const blogData = Astro.props.entry.data; + +const getPathMdjsStroriesFile = (entry) => { + const mdjsStroriesFileDirectory = path.dirname(entry.slug); + return `/public/docs/${mdjsStroriesFileDirectory}/__mdjs-stories.js`; +} --- @@ -46,4 +52,5 @@ const blogData = Astro.props.entry.data; {blogData.tags} {blogData.author} + diff --git a/src/pages/components/[component].astro b/src/pages/components/[component].astro index bcea475b54..c6769aa30a 100644 --- a/src/pages/components/[component].astro +++ b/src/pages/components/[component].astro @@ -40,9 +40,9 @@ const parseEntries = async () => { await parseEntries(); -const getPathForComponentMdjsStrories = () => { - const componentDirectory = path.dirname(componentEntries[0].slug); - return `/public/docs/${componentDirectory}/__mdjs-stories.js`; +const getPathMdjsStroriesFile = (entry) => { + const mdjsStroriesFileDirectory = path.dirname(entry.slug); + return `/public/docs/${mdjsStroriesFileDirectory}/__mdjs-stories.js`; } --- @@ -54,7 +54,7 @@ const getPathForComponentMdjsStrories = () => { )) } - + \ No newline at end of file diff --git a/src/utils/remark-plugings/copyMdjsStories/copyMdjsStories.js b/src/utils/remark-plugings/copyMdjsStories/copyMdjsStories.js index 3242727a61..d25b076383 100644 --- a/src/utils/remark-plugings/copyMdjsStories/copyMdjsStories.js +++ b/src/utils/remark-plugings/copyMdjsStories/copyMdjsStories.js @@ -27,15 +27,14 @@ async function processImports(source) { for (const importObj of imports) { newSource += source.substring(lastPos, importObj.s); const importSrc = source.substring(importObj.s, importObj.e); + const isDyncamicImport = importObj.d > -1; - if (importSrc.startsWith('.')) { + if (importSrc.startsWith('.') || importSrc.startsWith('/') || isDyncamicImport) { newSource += importSrc; } else if (importSrc === `'@mdjs/mdjs-preview/define'`) { newSource += `'${nodeModulesText}/@mdjs/mdjs-preview/src/define/define.js'`; } else if (importSrc === `'@mdjs/mdjs-story/define'`) { newSource += `'${nodeModulesText}/@mdjs/mdjs-story/src/define.js'`; - } else if (importSrc.startsWith('/')) { - newSource += importSrc; } else { newSource += nodeModulesText + require.resolve(importSrc).split(nodeModulesText)[1]; }