Ensure base configuration appended to content collection styles (#6182)
* Fix, base appended to propagated scripts * Test scripts
This commit is contained in:
parent
e4b2a2e3c7
commit
938ad514cd
10 changed files with 108 additions and 2 deletions
5
.changeset/late-poets-own.md
Normal file
5
.changeset/late-poets-own.md
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
---
|
||||||
|
'astro': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Ensure base configuration appended to content collection styles
|
|
@ -98,6 +98,7 @@ export function astroConfigBuildPlugin(
|
||||||
},
|
},
|
||||||
'build:post': ({ ssrOutputs, clientOutputs, mutate }) => {
|
'build:post': ({ ssrOutputs, clientOutputs, mutate }) => {
|
||||||
const outputs = ssrOutputs.flatMap((o) => o.output);
|
const outputs = ssrOutputs.flatMap((o) => o.output);
|
||||||
|
const prependBase = (src: string) => prependForwardSlash(npath.posix.join(options.settings.config.base, src));
|
||||||
for (const chunk of outputs) {
|
for (const chunk of outputs) {
|
||||||
if (
|
if (
|
||||||
chunk.type === 'chunk' &&
|
chunk.type === 'chunk' &&
|
||||||
|
@ -133,7 +134,7 @@ export function astroConfigBuildPlugin(
|
||||||
if (entryCSS.size) {
|
if (entryCSS.size) {
|
||||||
newCode = newCode.replace(
|
newCode = newCode.replace(
|
||||||
JSON.stringify(LINKS_PLACEHOLDER),
|
JSON.stringify(LINKS_PLACEHOLDER),
|
||||||
JSON.stringify([...entryCSS])
|
JSON.stringify(Array.from(entryCSS).map(prependBase))
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
if (entryScripts.size) {
|
if (entryScripts.size) {
|
||||||
|
@ -153,7 +154,7 @@ export function astroConfigBuildPlugin(
|
||||||
JSON.stringify(
|
JSON.stringify(
|
||||||
[...entryFileNames].map((src) => ({
|
[...entryFileNames].map((src) => ({
|
||||||
props: {
|
props: {
|
||||||
src: prependForwardSlash(npath.posix.join(options.settings.config.base, src)),
|
src: prependBase(src),
|
||||||
type: 'module',
|
type: 'module',
|
||||||
},
|
},
|
||||||
children: '',
|
children: '',
|
||||||
|
|
|
@ -243,4 +243,27 @@ describe('Content Collections', () => {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('Base configuration', () => {
|
||||||
|
let fixture;
|
||||||
|
|
||||||
|
before(async () => {
|
||||||
|
fixture = await loadFixture({
|
||||||
|
root: './fixtures/content-collections-base/',
|
||||||
|
});
|
||||||
|
await fixture.build();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Includes base in links', async () => {
|
||||||
|
const html = await fixture.readFile('/docs/index.html');
|
||||||
|
const $ = cheerio.load(html);
|
||||||
|
expect($('link').attr('href')).to.satisfies(a => a.startsWith('/docs'))
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Includes base in hoisted scripts', async () => {
|
||||||
|
const html = await fixture.readFile('/docs/index.html');
|
||||||
|
const $ = cheerio.load(html);
|
||||||
|
expect($('script').attr('src')).to.satisfies(a => a.startsWith('/docs'))
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
13
packages/astro/test/fixtures/content-collections-base/astro.config.mjs
vendored
Normal file
13
packages/astro/test/fixtures/content-collections-base/astro.config.mjs
vendored
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
import { defineConfig } from 'astro/config';
|
||||||
|
import mdx from '@astrojs/mdx';
|
||||||
|
|
||||||
|
// https://astro.build/config
|
||||||
|
export default defineConfig({
|
||||||
|
base: '/docs',
|
||||||
|
integrations: [mdx()],
|
||||||
|
vite: {
|
||||||
|
build: {
|
||||||
|
assetsInlineLimit: 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
9
packages/astro/test/fixtures/content-collections-base/package.json
vendored
Normal file
9
packages/astro/test/fixtures/content-collections-base/package.json
vendored
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
{
|
||||||
|
"name": "@test/content-collections-base",
|
||||||
|
"version": "0.0.0",
|
||||||
|
"private": true,
|
||||||
|
"dependencies": {
|
||||||
|
"astro": "workspace:*",
|
||||||
|
"@astrojs/mdx": "workspace:*"
|
||||||
|
}
|
||||||
|
}
|
7
packages/astro/test/fixtures/content-collections-base/src/components/One.astro
vendored
Normal file
7
packages/astro/test/fixtures/content-collections-base/src/components/One.astro
vendored
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
<style>
|
||||||
|
div { color: blue; }
|
||||||
|
</style>
|
||||||
|
<script>
|
||||||
|
console.log('hi');
|
||||||
|
</script>
|
||||||
|
<div>Testing</div>
|
12
packages/astro/test/fixtures/content-collections-base/src/content/config.ts
vendored
Normal file
12
packages/astro/test/fixtures/content-collections-base/src/content/config.ts
vendored
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
import { z, defineCollection } from 'astro:content';
|
||||||
|
|
||||||
|
|
||||||
|
const docs = defineCollection({
|
||||||
|
schema: z.object({
|
||||||
|
title: z.string(),
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
|
||||||
|
export const collections = {
|
||||||
|
docs,
|
||||||
|
}
|
11
packages/astro/test/fixtures/content-collections-base/src/content/docs/one.mdx
vendored
Normal file
11
packages/astro/test/fixtures/content-collections-base/src/content/docs/one.mdx
vendored
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
---
|
||||||
|
title: One
|
||||||
|
---
|
||||||
|
|
||||||
|
import One from '../../components/One.astro';
|
||||||
|
|
||||||
|
# Title
|
||||||
|
|
||||||
|
stuff
|
||||||
|
|
||||||
|
<One />
|
17
packages/astro/test/fixtures/content-collections-base/src/pages/docs.astro
vendored
Normal file
17
packages/astro/test/fixtures/content-collections-base/src/pages/docs.astro
vendored
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
---
|
||||||
|
import { getEntryBySlug } from 'astro:content';
|
||||||
|
const entry = await getEntryBySlug('docs', 'one');
|
||||||
|
const { Content } = await entry.render();
|
||||||
|
---
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8" />
|
||||||
|
<meta name="viewport" content="width=device-width" />
|
||||||
|
<title>It's content time!</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<main>
|
||||||
|
<Content />
|
||||||
|
</main>
|
||||||
|
</body>
|
||||||
|
</html>
|
|
@ -1663,6 +1663,14 @@ importers:
|
||||||
'@astrojs/mdx': link:../../../../integrations/mdx
|
'@astrojs/mdx': link:../../../../integrations/mdx
|
||||||
astro: link:../../..
|
astro: link:../../..
|
||||||
|
|
||||||
|
packages/astro/test/fixtures/content-collections-base:
|
||||||
|
specifiers:
|
||||||
|
'@astrojs/mdx': workspace:*
|
||||||
|
astro: workspace:*
|
||||||
|
dependencies:
|
||||||
|
'@astrojs/mdx': link:../../../../integrations/mdx
|
||||||
|
astro: link:../../..
|
||||||
|
|
||||||
packages/astro/test/fixtures/content-ssr-integration:
|
packages/astro/test/fixtures/content-ssr-integration:
|
||||||
specifiers:
|
specifiers:
|
||||||
'@astrojs/mdx': workspace:*
|
'@astrojs/mdx': workspace:*
|
||||||
|
|
Loading…
Reference in a new issue