[ci] format
This commit is contained in:
parent
213e10991a
commit
4ce2ba972a
4 changed files with 19 additions and 16 deletions
|
@ -21,6 +21,7 @@ import { isServerLikeOutput } from '../../prerender/utils.js';
|
||||||
import { PAGE_SCRIPT_ID } from '../../vite-plugin-scripts/index.js';
|
import { PAGE_SCRIPT_ID } from '../../vite-plugin-scripts/index.js';
|
||||||
import { AstroError, AstroErrorData } from '../errors/index.js';
|
import { AstroError, AstroErrorData } from '../errors/index.js';
|
||||||
import { info } from '../logger/core.js';
|
import { info } from '../logger/core.js';
|
||||||
|
import { routeIsRedirect } from '../redirects/index.js';
|
||||||
import { getOutDirWithinCwd } from './common.js';
|
import { getOutDirWithinCwd } from './common.js';
|
||||||
import { generatePages } from './generate.js';
|
import { generatePages } from './generate.js';
|
||||||
import { trackPageData } from './internal.js';
|
import { trackPageData } from './internal.js';
|
||||||
|
@ -32,7 +33,6 @@ import { RESOLVED_SPLIT_MODULE_ID, SSR_VIRTUAL_MODULE_ID } from './plugins/plugi
|
||||||
import { ASTRO_PAGE_EXTENSION_POST_PATTERN } from './plugins/util.js';
|
import { ASTRO_PAGE_EXTENSION_POST_PATTERN } from './plugins/util.js';
|
||||||
import type { PageBuildData, StaticBuildOptions } from './types';
|
import type { PageBuildData, StaticBuildOptions } from './types';
|
||||||
import { getTimeStat } from './util.js';
|
import { getTimeStat } from './util.js';
|
||||||
import { routeIsRedirect } from '../redirects/index.js';
|
|
||||||
|
|
||||||
export async function viteBuild(opts: StaticBuildOptions) {
|
export async function viteBuild(opts: StaticBuildOptions) {
|
||||||
const { allPages, settings } = opts;
|
const { allPages, settings } = opts;
|
||||||
|
@ -61,7 +61,7 @@ export async function viteBuild(opts: StaticBuildOptions) {
|
||||||
// Track the page data in internals
|
// Track the page data in internals
|
||||||
trackPageData(internals, component, pageData, astroModuleId, astroModuleURL);
|
trackPageData(internals, component, pageData, astroModuleId, astroModuleURL);
|
||||||
|
|
||||||
if(!routeIsRedirect(pageData.route)) {
|
if (!routeIsRedirect(pageData.route)) {
|
||||||
pageInput.add(astroModuleId);
|
pageInput.add(astroModuleId);
|
||||||
facadeIdToPageDataMap.set(fileURLToPath(astroModuleURL), pageData);
|
facadeIdToPageDataMap.set(fileURLToPath(astroModuleURL), pageData);
|
||||||
}
|
}
|
||||||
|
|
|
@ -463,16 +463,16 @@ export function createRouteManifest(
|
||||||
const redirBase = path.posix.dirname(route);
|
const redirBase = path.posix.dirname(route);
|
||||||
const dynamicRedir = lastSegmentIsDynamic(routeData);
|
const dynamicRedir = lastSegmentIsDynamic(routeData);
|
||||||
let i = 0;
|
let i = 0;
|
||||||
for(const existingRoute of routes) {
|
for (const existingRoute of routes) {
|
||||||
// An exact match, prefer the page/endpoint. This matches hosts.
|
// An exact match, prefer the page/endpoint. This matches hosts.
|
||||||
if(existingRoute.route === route) {
|
if (existingRoute.route === route) {
|
||||||
routes.splice(i+1, 0, routeData);
|
routes.splice(i + 1, 0, routeData);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the existing route is dynamic, prefer the static redirect.
|
// If the existing route is dynamic, prefer the static redirect.
|
||||||
const base = path.posix.dirname(existingRoute.route);
|
const base = path.posix.dirname(existingRoute.route);
|
||||||
if(base === redirBase && !dynamicRedir && lastSegmentIsDynamic(existingRoute)) {
|
if (base === redirBase && !dynamicRedir && lastSegmentIsDynamic(existingRoute)) {
|
||||||
routes.splice(i, 0, routeData);
|
routes.splice(i, 0, routeData);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -109,13 +109,13 @@ describe('Astro.redirect', () => {
|
||||||
const html = await fixture.readFile('/secret/index.html');
|
const html = await fixture.readFile('/secret/index.html');
|
||||||
expect(html).to.include('<link rel="canonical" href="/login">');
|
expect(html).to.include('<link rel="canonical" href="/login">');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('A 302 status generates a "temporary redirect" through a short delay', async () => {
|
it('A 302 status generates a "temporary redirect" through a short delay', async () => {
|
||||||
// https://developers.google.com/search/docs/crawling-indexing/301-redirects#metarefresh
|
// https://developers.google.com/search/docs/crawling-indexing/301-redirects#metarefresh
|
||||||
const html = await fixture.readFile('/secret/index.html');
|
const html = await fixture.readFile('/secret/index.html');
|
||||||
expect(html).to.include('content="2;url=/login"');
|
expect(html).to.include('content="2;url=/login"');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Includes the meta refresh tag in `redirect` config pages', async () => {
|
it('Includes the meta refresh tag in `redirect` config pages', async () => {
|
||||||
let html = await fixture.readFile('/one/index.html');
|
let html = await fixture.readFile('/one/index.html');
|
||||||
expect(html).to.include('http-equiv="refresh');
|
expect(html).to.include('http-equiv="refresh');
|
||||||
|
|
|
@ -66,7 +66,7 @@ describe('routing - createRouteManifest', () => {
|
||||||
it('static redirect route is prioritized over dynamic file route', async () => {
|
it('static redirect route is prioritized over dynamic file route', async () => {
|
||||||
const fs = createFs(
|
const fs = createFs(
|
||||||
{
|
{
|
||||||
'/src/pages/[...slug].astro': `<h1>test</h1>`
|
'/src/pages/[...slug].astro': `<h1>test</h1>`,
|
||||||
},
|
},
|
||||||
root
|
root
|
||||||
);
|
);
|
||||||
|
@ -74,16 +74,19 @@ describe('routing - createRouteManifest', () => {
|
||||||
{
|
{
|
||||||
trailingSlash: 'never',
|
trailingSlash: 'never',
|
||||||
redirects: {
|
redirects: {
|
||||||
'/foo': '/bar'
|
'/foo': '/bar',
|
||||||
}
|
},
|
||||||
},
|
},
|
||||||
root
|
root
|
||||||
);
|
);
|
||||||
const manifest = createRouteManifest({
|
const manifest = createRouteManifest(
|
||||||
cwd: fileURLToPath(root),
|
{
|
||||||
settings,
|
cwd: fileURLToPath(root),
|
||||||
fsMod: fs,
|
settings,
|
||||||
}, defaultLogging);
|
fsMod: fs,
|
||||||
|
},
|
||||||
|
defaultLogging
|
||||||
|
);
|
||||||
|
|
||||||
expect(manifest.routes[0].route).to.equal('/foo');
|
expect(manifest.routes[0].route).to.equal('/foo');
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue