[ci] format
This commit is contained in:
parent
efe4f1a3ef
commit
3bb07a01e0
2 changed files with 24 additions and 24 deletions
|
@ -2,30 +2,30 @@ import type { RouteData } from 'astro';
|
||||||
import fs from 'fs';
|
import fs from 'fs';
|
||||||
|
|
||||||
export async function createRedirects(
|
export async function createRedirects(
|
||||||
routes: RouteData[],
|
routes: RouteData[],
|
||||||
dir: URL,
|
dir: URL,
|
||||||
entryFile: string,
|
entryFile: string,
|
||||||
edge: boolean
|
edge: boolean
|
||||||
) {
|
) {
|
||||||
const _redirectsURL = new URL('./_redirects', dir);
|
const _redirectsURL = new URL('./_redirects', dir);
|
||||||
const kind = edge ? 'edge-functions' : 'functions'
|
const kind = edge ? 'edge-functions' : 'functions';
|
||||||
|
|
||||||
// Create the redirects file that is used for routing.
|
// Create the redirects file that is used for routing.
|
||||||
let _redirects = '';
|
let _redirects = '';
|
||||||
for (const route of routes) {
|
for (const route of routes) {
|
||||||
if (route.pathname) {
|
if (route.pathname) {
|
||||||
_redirects += `
|
_redirects += `
|
||||||
${route.pathname} /.netlify/${kind}/${entryFile} 200`;
|
${route.pathname} /.netlify/${kind}/${entryFile} 200`;
|
||||||
} else {
|
} else {
|
||||||
const pattern =
|
const pattern =
|
||||||
'/' + route.segments.map(([part]) => (part.dynamic ? '*' : part.content)).join('/');
|
'/' + route.segments.map(([part]) => (part.dynamic ? '*' : part.content)).join('/');
|
||||||
_redirects += `
|
_redirects += `
|
||||||
${pattern} /.netlify/${kind}/${entryFile} 200`;
|
${pattern} /.netlify/${kind}/${entryFile} 200`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Always use appendFile() because the redirects file could already exist,
|
// Always use appendFile() because the redirects file could already exist,
|
||||||
// e.g. due to a `/public/_redirects` file that got copied to the output dir.
|
// e.g. due to a `/public/_redirects` file that got copied to the output dir.
|
||||||
// If the file does not exist yet, appendFile() automatically creates it.
|
// If the file does not exist yet, appendFile() automatically creates it.
|
||||||
await fs.promises.appendFile(_redirectsURL, _redirects, 'utf-8');
|
await fs.promises.appendFile(_redirectsURL, _redirects, 'utf-8');
|
||||||
}
|
}
|
Loading…
Reference in a new issue