Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Markdoc Integration build when root folder contains spaces #8759

Merged
merged 6 commits into from
Oct 27, 2023
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.'
);
}
Loading