aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Luca Di Gianventura <lucadig.1994@gmail.com> 2023-10-27 11:45:02 +0200
committerGravatar GitHub <noreply@github.com> 2023-10-27 17:45:02 +0800
commit01c801108f1f5429436e4fc930018bf96ed31f79 (patch)
tree8fd6273aebe6a19336cdce4c21f0411ffa7b3848
parent35c5265dc2b1e5940e14eebc50c7ccff98fe5f3b (diff)
downloadastro-01c801108f1f5429436e4fc930018bf96ed31f79.tar.gz
astro-01c801108f1f5429436e4fc930018bf96ed31f79.tar.zst
astro-01c801108f1f5429436e4fc930018bf96ed31f79.zip
Fix: Markdoc Integration build when root folder contains spaces (#8759)
Co-authored-by: Arsh <69170106+lilnasy@users.noreply.github.com>
-rw-r--r--.changeset/seven-files-punch.md5
-rw-r--r--packages/integrations/markdoc/src/content-entry-type.ts4
-rw-r--r--packages/integrations/markdoc/test/fixtures/render with-space/astro.config.mjs7
-rw-r--r--packages/integrations/markdoc/test/fixtures/render with-space/package.json9
-rw-r--r--packages/integrations/markdoc/test/fixtures/render with-space/src/content/blog/simple.mdoc7
-rw-r--r--packages/integrations/markdoc/test/fixtures/render with-space/src/pages/index.astro19
-rw-r--r--packages/integrations/markdoc/test/render.test.js32
-rw-r--r--pnpm-lock.yaml9
8 files changed, 90 insertions, 2 deletions
diff --git a/.changeset/seven-files-punch.md b/.changeset/seven-files-punch.md
new file mode 100644
index 000000000..d46a27422
--- /dev/null
+++ b/.changeset/seven-files-punch.md
@@ -0,0 +1,5 @@
+---
+'@astrojs/markdoc': patch
+---
+
+Fix build process on markdoc integration when root folder contains spaces
diff --git a/packages/integrations/markdoc/src/content-entry-type.ts b/packages/integrations/markdoc/src/content-entry-type.ts
index f682e114f..07c5268e4 100644
--- a/packages/integrations/markdoc/src/content-entry-type.ts
+++ b/packages/integrations/markdoc/src/content-entry-type.ts
@@ -106,7 +106,7 @@ export async function getContentEntryType({
import { createGetHeadings, createContentComponent } from '@astrojs/markdoc/runtime';
${
markdocConfigUrl
- ? `import markdocConfig from ${JSON.stringify(markdocConfigUrl.pathname)};`
+ ? `import markdocConfig from ${JSON.stringify(fileURLToPath(markdocConfigUrl))};`
: 'const markdocConfig = {};'
}
@@ -230,7 +230,7 @@ function getStringifiedImports(
? `{ ${config.namedExport} as ${componentNamePrefix + toImportName(key)} }`
: componentNamePrefix + toImportName(key);
const resolvedPath =
- config.type === 'local' ? new URL(config.path, root).pathname : config.path;
+ config.type === 'local' ? fileURLToPath(new URL(config.path, root)) : config.path;
stringifiedComponentImports += `import ${importName} from ${JSON.stringify(resolvedPath)};\n`;
}
diff --git a/packages/integrations/markdoc/test/fixtures/render with-space/astro.config.mjs b/packages/integrations/markdoc/test/fixtures/render with-space/astro.config.mjs
new file mode 100644
index 000000000..29d846359
--- /dev/null
+++ b/packages/integrations/markdoc/test/fixtures/render with-space/astro.config.mjs
@@ -0,0 +1,7 @@
+import { defineConfig } from 'astro/config';
+import markdoc from '@astrojs/markdoc';
+
+// https://astro.build/config
+export default defineConfig({
+ integrations: [markdoc()],
+});
diff --git a/packages/integrations/markdoc/test/fixtures/render with-space/package.json b/packages/integrations/markdoc/test/fixtures/render with-space/package.json
new file mode 100644
index 000000000..daae65443
--- /dev/null
+++ b/packages/integrations/markdoc/test/fixtures/render with-space/package.json
@@ -0,0 +1,9 @@
+{
+ "name": "@test/markdoc-render-with-space",
+ "version": "0.0.0",
+ "private": true,
+ "dependencies": {
+ "@astrojs/markdoc": "workspace:*",
+ "astro": "workspace:*"
+ }
+}
diff --git a/packages/integrations/markdoc/test/fixtures/render with-space/src/content/blog/simple.mdoc b/packages/integrations/markdoc/test/fixtures/render with-space/src/content/blog/simple.mdoc
new file mode 100644
index 000000000..2dbe492fe
--- /dev/null
+++ b/packages/integrations/markdoc/test/fixtures/render with-space/src/content/blog/simple.mdoc
@@ -0,0 +1,7 @@
+---
+title: Simple post with root folder containing a space
+---
+
+## Simple post with root folder containing a space
+
+This is a simple Markdoc post with root folder containing a space.
diff --git a/packages/integrations/markdoc/test/fixtures/render with-space/src/pages/index.astro b/packages/integrations/markdoc/test/fixtures/render with-space/src/pages/index.astro
new file mode 100644
index 000000000..940eef154
--- /dev/null
+++ b/packages/integrations/markdoc/test/fixtures/render with-space/src/pages/index.astro
@@ -0,0 +1,19 @@
+---
+import { getEntryBySlug } from "astro:content";
+
+const post = await getEntryBySlug('blog', 'simple');
+const { Content } = await post.render();
+---
+
+<!DOCTYPE html>
+<html lang="en">
+<head>
+ <meta charset="UTF-8">
+ <meta http-equiv="X-UA-Compatible" content="IE=edge">
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
+ <title>Content</title>
+</head>
+<body>
+ <Content />
+</body>
+</html>
diff --git a/packages/integrations/markdoc/test/render.test.js b/packages/integrations/markdoc/test/render.test.js
index 3ac9c3ac4..f1760a8e6 100644
--- a/packages/integrations/markdoc/test/render.test.js
+++ b/packages/integrations/markdoc/test/render.test.js
@@ -69,6 +69,18 @@ describe('Markdoc - render', () => {
await server.stop();
});
+
+ it('renders content - with root folder containing space', async () => {
+ const fixture = await getFixture('render with-space');
+ const server = await fixture.startDevServer();
+
+ const res = await fixture.fetch('/');
+ const html = await res.text();
+
+ renderWithRootFolderContainingSpace(html);
+
+ await server.stop();
+ });
});
describe('build', () => {
@@ -116,6 +128,15 @@ describe('Markdoc - render', () => {
renderNullChecks(html);
});
+
+ it('renders content - with root folder containing space', async () => {
+ const fixture = await getFixture('render with-space');
+ await fixture.build();
+
+ const html = await fixture.readFile('/index.html');
+
+ renderWithRootFolderContainingSpace(html);
+ });
});
});
@@ -189,3 +210,14 @@ function renderSimpleChecks(html) {
const p = document.querySelector('p');
expect(p.textContent).to.equal('This is a simple Markdoc post.');
}
+
+/** @param {string} html */
+function renderWithRootFolderContainingSpace(html) {
+ const { document } = parseHTML(html);
+ const h2 = document.querySelector('h2');
+ expect(h2.textContent).to.equal('Simple post with root folder containing a space');
+ const p = document.querySelector('p');
+ expect(p.textContent).to.equal(
+ 'This is a simple Markdoc post with root folder containing a space.'
+ );
+}
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 7e6527923..86f4cee5b 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -3836,6 +3836,15 @@ importers:
specifier: workspace:*
version: link:../../../../../astro
+ packages/integrations/markdoc/test/fixtures/render with-space:
+ dependencies:
+ '@astrojs/markdoc':
+ specifier: workspace:*
+ version: link:../../..
+ astro:
+ specifier: workspace:*
+ version: link:../../../../../astro
+
packages/integrations/markdoc/test/fixtures/render-html:
dependencies:
'@astrojs/markdoc':