fix: minify HTML for redirects when emitted as HTML files (#8504)

This commit is contained in:
Emanuele Stoppa 2023-09-11 15:11:57 +01:00 committed by GitHub
parent c934b087d7
commit 5e1099f686
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 0 deletions

View file

@ -0,0 +1,5 @@
---
'astro': patch
---
Minify the HTML of the redicts emitted during the build.

View file

@ -584,6 +584,9 @@ async function generatePath(pathname: string, gopts: GeneratePathOptions, pipeli
<body> <body>
<a href="${location}">Redirecting from <code>${fromPath}</code> to <code>${location}</code></a> <a href="${location}">Redirecting from <code>${fromPath}</code> to <code>${location}</code></a>
</body>`; </body>`;
if (pipeline.getConfig().compressHTML === true) {
body = body.replaceAll('\n', '');
}
// A dynamic redirect, set the location so that integrations know about it. // A dynamic redirect, set the location so that integrations know about it.
if (pageData.route.type !== 'redirect') { if (pageData.route.type !== 'redirect') {
pageData.route.redirect = location; pageData.route.redirect = location;

View file

@ -69,6 +69,7 @@ describe('Astro.redirect', () => {
root: './fixtures/ssr-redirect/', root: './fixtures/ssr-redirect/',
output: 'static', output: 'static',
redirects: { redirects: {
'/old': '/test',
'/': '/test', '/': '/test',
'/one': '/test', '/one': '/test',
'/two': '/test', '/two': '/test',
@ -82,6 +83,11 @@ describe('Astro.redirect', () => {
await fixture.build(); await fixture.build();
}); });
it("Minifies the HTML emitted when a page that doesn't exist is emitted", async () => {
const html = await fixture.readFile('/old/index.html');
expect(html).to.not.include('\n');
});
it('Includes the meta refresh tag in Astro.redirect pages', async () => { it('Includes the meta refresh tag in Astro.redirect pages', async () => {
const html = await fixture.readFile('/secret/index.html'); const html = await fixture.readFile('/secret/index.html');
expect(html).to.include('http-equiv="refresh'); expect(html).to.include('http-equiv="refresh');