mirror of
https://github.com/withastro/astro.git
synced 2025-01-06 22:10:10 -05:00
fix(ssg): consider trailingSlash for url (#9878)
* fix(ssg): consider trailingSlash for url * add changeset
This commit is contained in:
parent
e9027f194b
commit
a40a0ff588
3 changed files with 12 additions and 3 deletions
5
.changeset/wet-rivers-do.md
Normal file
5
.changeset/wet-rivers-do.md
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
---
|
||||||
|
"astro": patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Fixes an issue where setting trailingSlash to "never" had no effect on `Astro.url`.
|
|
@ -5,6 +5,7 @@ import { fileURLToPath } from 'node:url';
|
||||||
import PQueue from 'p-queue';
|
import PQueue from 'p-queue';
|
||||||
import type { OutputAsset, OutputChunk } from 'rollup';
|
import type { OutputAsset, OutputChunk } from 'rollup';
|
||||||
import type {
|
import type {
|
||||||
|
AstroConfig,
|
||||||
AstroSettings,
|
AstroSettings,
|
||||||
ComponentInstance,
|
ComponentInstance,
|
||||||
GetStaticPathsItem,
|
GetStaticPathsItem,
|
||||||
|
@ -455,7 +456,8 @@ function getUrlForPath(
|
||||||
pathname: string,
|
pathname: string,
|
||||||
base: string,
|
base: string,
|
||||||
origin: string,
|
origin: string,
|
||||||
format: 'directory' | 'file',
|
format: AstroConfig["build"]["format"],
|
||||||
|
trailingSlash: AstroConfig["trailingSlash"],
|
||||||
routeType: RouteType
|
routeType: RouteType
|
||||||
): URL {
|
): URL {
|
||||||
/**
|
/**
|
||||||
|
@ -463,7 +465,7 @@ function getUrlForPath(
|
||||||
* pathname: /, /foo
|
* pathname: /, /foo
|
||||||
* base: /
|
* base: /
|
||||||
*/
|
*/
|
||||||
const ending = format === 'directory' ? '/' : '.html';
|
const ending = format === 'directory' ? trailingSlash === 'never' ? '' : '/' : '.html';
|
||||||
let buildPathname: string;
|
let buildPathname: string;
|
||||||
if (pathname === '/' || pathname === '') {
|
if (pathname === '/' || pathname === '') {
|
||||||
buildPathname = base;
|
buildPathname = base;
|
||||||
|
@ -538,6 +540,7 @@ async function generatePath(
|
||||||
pipeline.getConfig().base,
|
pipeline.getConfig().base,
|
||||||
pipeline.getStaticBuildOptions().origin,
|
pipeline.getStaticBuildOptions().origin,
|
||||||
pipeline.getConfig().build.format,
|
pipeline.getConfig().build.format,
|
||||||
|
pipeline.getConfig().trailingSlash,
|
||||||
route.type
|
route.type
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -10,6 +10,7 @@ describe('getStaticPaths - build calls', () => {
|
||||||
fixture = await loadFixture({
|
fixture = await loadFixture({
|
||||||
root: './fixtures/astro-get-static-paths/',
|
root: './fixtures/astro-get-static-paths/',
|
||||||
site: 'https://mysite.dev/',
|
site: 'https://mysite.dev/',
|
||||||
|
trailingSlash: 'never',
|
||||||
base: '/blog',
|
base: '/blog',
|
||||||
});
|
});
|
||||||
await fixture.build();
|
await fixture.build();
|
||||||
|
@ -29,7 +30,7 @@ describe('getStaticPaths - build calls', () => {
|
||||||
const html = await fixture.readFile('/food/tacos/index.html');
|
const html = await fixture.readFile('/food/tacos/index.html');
|
||||||
const $ = cheerio.load(html);
|
const $ = cheerio.load(html);
|
||||||
|
|
||||||
expect($('#url').text()).to.equal('/blog/food/tacos/');
|
expect($('#url').text()).to.equal('/blog/food/tacos');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue