diff --git a/.changeset/stupid-donkeys-care.md b/.changeset/stupid-donkeys-care.md new file mode 100644 index 000000000..9fe8eebb8 --- /dev/null +++ b/.changeset/stupid-donkeys-care.md @@ -0,0 +1,5 @@ +--- +'astro': patch +--- + +Fixes issue with loading md pages in project with a space in folder name diff --git a/packages/astro/src/vite-plugin-markdown/index.ts b/packages/astro/src/vite-plugin-markdown/index.ts index 2bbd72ffa..8e702054d 100644 --- a/packages/astro/src/vite-plugin-markdown/index.ts +++ b/packages/astro/src/vite-plugin-markdown/index.ts @@ -9,8 +9,8 @@ import type { Plugin } from 'vite'; import type { AstroConfig } from '../@types/astro'; import { PAGE_SSR_SCRIPT_ID } from '../vite-plugin-scripts/index.js'; import { pagesVirtualModuleId } from '../core/app/index.js'; -import { appendForwardSlash } from '../core/path.js'; -import { resolvePages } from '../core/util.js'; +import { appendForwardSlash, prependForwardSlash } from '../core/path.js'; +import { resolvePages, viteID } from '../core/util.js'; interface AstroPluginOptions { config: AstroConfig; @@ -156,7 +156,9 @@ ${setup}`.trim(); site: config.site ? new URL(config.base, config.site).toString() : undefined, sourcefile: id, sourcemap: 'inline', - internalURL: `/@fs${new URL('../runtime/server/index.js', import.meta.url).pathname}`, + internalURL: `/@fs${prependForwardSlash( + viteID(new URL('../runtime/server/index.js', import.meta.url)) + )}`, }); tsResult = `\nexport const metadata = ${JSON.stringify(metadata)}; diff --git a/packages/astro/test/astro-pages.test.js b/packages/astro/test/astro-pages.test.js index 0539388dd..708836a64 100644 --- a/packages/astro/test/astro-pages.test.js +++ b/packages/astro/test/astro-pages.test.js @@ -1,19 +1,46 @@ import { expect } from 'chai'; import * as cheerio from 'cheerio'; -import { loadFixture } from './test-utils.js'; +import { loadFixture, isWindows} from './test-utils.js'; describe('Pages', () => { let fixture; before(async () => { - fixture = await loadFixture({ root: './fixtures/astro-pages/' }); + fixture = await loadFixture({ root: './fixtures/astro pages/' }); await fixture.build(); }); - it('Can find page with "index" at the end file name', async () => { - const html = await fixture.readFile('/posts/name-with-index/index.html'); - const $ = cheerio.load(html); + describe('Build', () => { + before(async () => { + await fixture.build(); + }); - expect($('h1').text()).to.equal('Name with index'); + it('Can find page with "index" at the end file name', async () => { + const html = await fixture.readFile('/posts/name-with-index/index.html'); + const $ = cheerio.load(html); + + expect($('h1').text()).to.equal('Name with index'); + }); + }); + + if(isWindows) return; + + describe('Development', () => { + let devServer; + + before(async () => { + devServer = await fixture.startDevServer(); + }); + + after(async () => { + await devServer.stop(); + }); + + it('Is able to load md pages', async () => { + const html = await fixture.fetch('/').then((res) => res.text()); + const $ = cheerio.load(html); + + expect($('#testing').length).to.be.greaterThan(0); + }); }); }); diff --git a/packages/astro/test/fixtures/astro-pages/package.json b/packages/astro/test/fixtures/astro pages/package.json similarity index 100% rename from packages/astro/test/fixtures/astro-pages/package.json rename to packages/astro/test/fixtures/astro pages/package.json diff --git a/packages/astro/test/fixtures/astro pages/src/pages/index.md b/packages/astro/test/fixtures/astro pages/src/pages/index.md new file mode 100644 index 000000000..f00b526a9 --- /dev/null +++ b/packages/astro/test/fixtures/astro pages/src/pages/index.md @@ -0,0 +1 @@ +# Testing diff --git a/packages/astro/test/fixtures/astro-pages/src/pages/posts/name-with-index.md b/packages/astro/test/fixtures/astro pages/src/pages/posts/name-with-index.md similarity index 100% rename from packages/astro/test/fixtures/astro-pages/src/pages/posts/name-with-index.md rename to packages/astro/test/fixtures/astro pages/src/pages/posts/name-with-index.md diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 3403dd091..59461efe9 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -689,6 +689,12 @@ importers: '@astrojs/svelte': link:../../../../integrations/svelte astro: link:../../.. + packages/astro/test/fixtures/astro pages: + specifiers: + astro: workspace:* + dependencies: + astro: link:../../.. + packages/astro/test/fixtures/astro-assets: specifiers: astro: workspace:* @@ -925,12 +931,6 @@ importers: dependencies: astro: link:../../.. - packages/astro/test/fixtures/astro-pages: - specifiers: - astro: workspace:* - dependencies: - astro: link:../../.. - packages/astro/test/fixtures/astro-pagination: specifiers: astro: workspace:*