Fix for loading markdown pages with spaces in the name (#3379)
* Fix for loading markdown pages with spaces in the name * Adds a changeset
This commit is contained in:
parent
9d01f93b1c
commit
0259d7658b
7 changed files with 50 additions and 15 deletions
5
.changeset/stupid-donkeys-care.md
Normal file
5
.changeset/stupid-donkeys-care.md
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
---
|
||||||
|
'astro': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Fixes issue with loading md pages in project with a space in folder name
|
|
@ -9,8 +9,8 @@ import type { Plugin } from 'vite';
|
||||||
import type { AstroConfig } from '../@types/astro';
|
import type { AstroConfig } from '../@types/astro';
|
||||||
import { PAGE_SSR_SCRIPT_ID } from '../vite-plugin-scripts/index.js';
|
import { PAGE_SSR_SCRIPT_ID } from '../vite-plugin-scripts/index.js';
|
||||||
import { pagesVirtualModuleId } from '../core/app/index.js';
|
import { pagesVirtualModuleId } from '../core/app/index.js';
|
||||||
import { appendForwardSlash } from '../core/path.js';
|
import { appendForwardSlash, prependForwardSlash } from '../core/path.js';
|
||||||
import { resolvePages } from '../core/util.js';
|
import { resolvePages, viteID } from '../core/util.js';
|
||||||
|
|
||||||
interface AstroPluginOptions {
|
interface AstroPluginOptions {
|
||||||
config: AstroConfig;
|
config: AstroConfig;
|
||||||
|
@ -156,7 +156,9 @@ ${setup}`.trim();
|
||||||
site: config.site ? new URL(config.base, config.site).toString() : undefined,
|
site: config.site ? new URL(config.base, config.site).toString() : undefined,
|
||||||
sourcefile: id,
|
sourcefile: id,
|
||||||
sourcemap: 'inline',
|
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)};
|
tsResult = `\nexport const metadata = ${JSON.stringify(metadata)};
|
||||||
|
|
|
@ -1,19 +1,46 @@
|
||||||
import { expect } from 'chai';
|
import { expect } from 'chai';
|
||||||
import * as cheerio from 'cheerio';
|
import * as cheerio from 'cheerio';
|
||||||
import { loadFixture } from './test-utils.js';
|
import { loadFixture, isWindows} from './test-utils.js';
|
||||||
|
|
||||||
describe('Pages', () => {
|
describe('Pages', () => {
|
||||||
let fixture;
|
let fixture;
|
||||||
|
|
||||||
before(async () => {
|
before(async () => {
|
||||||
fixture = await loadFixture({ root: './fixtures/astro-pages/' });
|
fixture = await loadFixture({ root: './fixtures/astro pages/' });
|
||||||
await fixture.build();
|
await fixture.build();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Can find page with "index" at the end file name', async () => {
|
describe('Build', () => {
|
||||||
const html = await fixture.readFile('/posts/name-with-index/index.html');
|
before(async () => {
|
||||||
const $ = cheerio.load(html);
|
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);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
1
packages/astro/test/fixtures/astro pages/src/pages/index.md
vendored
Normal file
1
packages/astro/test/fixtures/astro pages/src/pages/index.md
vendored
Normal file
|
@ -0,0 +1 @@
|
||||||
|
# Testing
|
|
@ -689,6 +689,12 @@ importers:
|
||||||
'@astrojs/svelte': link:../../../../integrations/svelte
|
'@astrojs/svelte': link:../../../../integrations/svelte
|
||||||
astro: link:../../..
|
astro: link:../../..
|
||||||
|
|
||||||
|
packages/astro/test/fixtures/astro pages:
|
||||||
|
specifiers:
|
||||||
|
astro: workspace:*
|
||||||
|
dependencies:
|
||||||
|
astro: link:../../..
|
||||||
|
|
||||||
packages/astro/test/fixtures/astro-assets:
|
packages/astro/test/fixtures/astro-assets:
|
||||||
specifiers:
|
specifiers:
|
||||||
astro: workspace:*
|
astro: workspace:*
|
||||||
|
@ -925,12 +931,6 @@ importers:
|
||||||
dependencies:
|
dependencies:
|
||||||
astro: link:../../..
|
astro: link:../../..
|
||||||
|
|
||||||
packages/astro/test/fixtures/astro-pages:
|
|
||||||
specifiers:
|
|
||||||
astro: workspace:*
|
|
||||||
dependencies:
|
|
||||||
astro: link:../../..
|
|
||||||
|
|
||||||
packages/astro/test/fixtures/astro-pagination:
|
packages/astro/test/fixtures/astro-pagination:
|
||||||
specifiers:
|
specifiers:
|
||||||
astro: workspace:*
|
astro: workspace:*
|
||||||
|
|
Loading…
Reference in a new issue