Fix code generation quotes handling (#5678)
This commit is contained in:
parent
376f67011d
commit
f8f5768294
9 changed files with 25 additions and 10 deletions
5
.changeset/purple-hounds-decide.md
Normal file
5
.changeset/purple-hounds-decide.md
Normal file
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
'astro': patch
|
||||
---
|
||||
|
||||
Fix code generation quotes handling
|
|
@ -27,8 +27,8 @@ export function vitePluginPages(opts: StaticBuildOptions, internals: BuildIntern
|
|||
let i = 0;
|
||||
for (const pageData of eachPageData(internals)) {
|
||||
const variable = `_page${i}`;
|
||||
imports.push(`import * as ${variable} from '${pageData.moduleSpecifier}';`);
|
||||
importMap += `['${pageData.component}', ${variable}],`;
|
||||
imports.push(`import * as ${variable} from ${JSON.stringify(pageData.moduleSpecifier)};`);
|
||||
importMap += `[${JSON.stringify(pageData.component)}, ${variable}],`;
|
||||
i++;
|
||||
}
|
||||
|
||||
|
|
|
@ -133,7 +133,9 @@ export async function createVite(
|
|||
root: fileURLToPath(settings.config.root),
|
||||
envPrefix: 'PUBLIC_',
|
||||
define: {
|
||||
'import.meta.env.SITE': settings.config.site ? `'${settings.config.site}'` : 'undefined',
|
||||
'import.meta.env.SITE': settings.config.site
|
||||
? JSON.stringify(settings.config.site)
|
||||
: 'undefined',
|
||||
},
|
||||
server: {
|
||||
hmr:
|
||||
|
|
|
@ -82,7 +82,7 @@ export async function createContainer(params: CreateContainerParams = {}): Promi
|
|||
},
|
||||
define: {
|
||||
'import.meta.env.BASE_URL': settings.config.base
|
||||
? `'${settings.config.base}'`
|
||||
? JSON.stringify(settings.config.base)
|
||||
: 'undefined',
|
||||
},
|
||||
},
|
||||
|
|
|
@ -37,9 +37,9 @@ function getPrivateEnv(
|
|||
}
|
||||
}
|
||||
}
|
||||
privateEnv.SITE = astroConfig.site ? `'${astroConfig.site}'` : 'undefined';
|
||||
privateEnv.SITE = astroConfig.site ? JSON.stringify(astroConfig.site) : 'undefined';
|
||||
privateEnv.SSR = JSON.stringify(true);
|
||||
privateEnv.BASE_URL = astroConfig.base ? `'${astroConfig.base}'` : 'undefined';
|
||||
privateEnv.BASE_URL = astroConfig.base ? JSON.stringify(astroConfig.base) : 'undefined';
|
||||
return privateEnv;
|
||||
}
|
||||
|
||||
|
|
|
@ -174,8 +174,8 @@ export default function markdown({ settings }: AstroPluginOptions): Plugin {
|
|||
|
||||
const prelude = `---
|
||||
import Slugger from 'github-slugger';
|
||||
${layout ? `import Layout from '${layout}';` : ''}
|
||||
${components ? `import * from '${components}';` : ''}
|
||||
${layout ? `import Layout from ${JSON.stringify(layout)};` : ''}
|
||||
${components ? `import * from ${JSON.stringify(components)};` : ''}
|
||||
${setup}
|
||||
|
||||
const slugger = new Slugger();
|
||||
|
@ -193,7 +193,7 @@ Object.defineProperty($$content.astro, 'headers', {
|
|||
});
|
||||
---`;
|
||||
|
||||
const imports = `${layout ? `import Layout from '${layout}';` : ''}
|
||||
const imports = `${layout ? `import Layout from ${JSON.stringify(layout)};` : ''}
|
||||
${setup}`.trim();
|
||||
|
||||
// If the user imported "Layout", wrap the content in a Layout
|
||||
|
|
|
@ -95,7 +95,7 @@ export default function markdown({ settings, logging }: AstroPluginOptions): Plu
|
|||
}
|
||||
|
||||
const code = escapeViteEnvReferences(`
|
||||
import { Fragment, jsx as h } from '${astroJsxRuntimeModulePath}';
|
||||
import { Fragment, jsx as h } from ${JSON.stringify(astroJsxRuntimeModulePath)};
|
||||
${layout ? `import Layout from ${JSON.stringify(layout)};` : ''}
|
||||
|
||||
const html = ${JSON.stringify(html)};
|
||||
|
|
|
@ -21,6 +21,13 @@ describe('Pages', () => {
|
|||
|
||||
expect($('h1').text()).to.equal('Name with index');
|
||||
});
|
||||
|
||||
it('Can find page with quotes in file name', async () => {
|
||||
const html = await fixture.readFile("/quotes'-work-too/index.html");
|
||||
const $ = cheerio.load(html);
|
||||
|
||||
expect($('h1').text()).to.equal("Quotes work too");
|
||||
});
|
||||
});
|
||||
|
||||
if (isWindows) return;
|
||||
|
|
1
packages/astro/test/fixtures/astro pages/src/pages/quotes'-work-too.md
vendored
Normal file
1
packages/astro/test/fixtures/astro pages/src/pages/quotes'-work-too.md
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
# Quotes work too
|
Loading…
Reference in a new issue