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 for loading markdown pages with spaces in the name #3379

Merged
merged 2 commits into from
May 16, 2022
Merged
Show file tree
Hide file tree
Changes from all 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/stupid-donkeys-care.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'astro': patch
---

Fixes issue with loading md pages in project with a space in folder name
8 changes: 5 additions & 3 deletions packages/astro/src/vite-plugin-markdown/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)};
Expand Down
39 changes: 33 additions & 6 deletions packages/astro/test/astro-pages.test.js
Original file line number Diff line number Diff line change
@@ -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);
});
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Testing
12 changes: 6 additions & 6 deletions pnpm-lock.yaml

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