Skip to content

Commit

Permalink
Fix: Markdoc Integration build when root folder contains spaces (#8759)
Browse files Browse the repository at this point in the history
Co-authored-by: Arsh <69170106+lilnasy@users.noreply.github.com>
  • Loading branch information
lutaok and lilnasy authored Oct 27, 2023
1 parent 35c5265 commit 01c8011
Show file tree
Hide file tree
Showing 8 changed files with 90 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/seven-files-punch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@astrojs/markdoc': patch
---

Fix build process on markdoc integration when root folder contains spaces
4 changes: 2 additions & 2 deletions packages/integrations/markdoc/src/content-entry-type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {};'
}
Expand Down Expand Up @@ -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`;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { defineConfig } from 'astro/config';
import markdoc from '@astrojs/markdoc';

// https://astro.build/config
export default defineConfig({
integrations: [markdoc()],
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"name": "@test/markdoc-render-with-space",
"version": "0.0.0",
"private": true,
"dependencies": {
"@astrojs/markdoc": "workspace:*",
"astro": "workspace:*"
}
}
Original file line number Diff line number Diff line change
@@ -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.
Original file line number Diff line number Diff line change
@@ -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>
32 changes: 32 additions & 0 deletions packages/integrations/markdoc/test/render.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down Expand Up @@ -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);
});
});
});

Expand Down Expand Up @@ -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.'
);
}
9 changes: 9 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 01c8011

Please sign in to comment.