summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar matthewp <matthewp@users.noreply.github.com> 2021-04-05 18:18:39 +0000
committerGravatar GitHub Actions <actions@github.com> 2021-04-05 18:18:39 +0000
commit71e5de76f136a0ef76253c05bb8072898bcf08f7 (patch)
tree2de52ac6fce9fb02bda74f3478e5ca12d61ac271 /src
parentc9bc6ffef7be0e068acb1b36475c4ab3d12fd5d5 (diff)
downloadastro-71e5de76f136a0ef76253c05bb8072898bcf08f7.tar.gz
astro-71e5de76f136a0ef76253c05bb8072898bcf08f7.tar.zst
astro-71e5de76f136a0ef76253c05bb8072898bcf08f7.zip
[ci] npm run format
Diffstat (limited to 'src')
-rw-r--r--src/build.ts4
-rw-r--r--src/runtime.ts6
-rw-r--r--src/search.ts49
3 files changed, 31 insertions, 28 deletions
diff --git a/src/build.ts b/src/build.ts
index aef96b918..f746ceb26 100644
--- a/src/build.ts
+++ b/src/build.ts
@@ -45,8 +45,8 @@ async function writeFilep(outPath: URL, bytes: string | Buffer, encoding: 'utf-8
/** Utility for writing a build result to disk */
async function writeResult(result: LoadResult, outPath: URL, encoding: null | 'utf-8') {
if (result.statusCode === 500 || result.statusCode === 404) {
- error(logging, 'build', result.error || result.statusCode);
- } else if(result.statusCode !== 200) {
+ error(logging, 'build', result.error || result.statusCode);
+ } else if (result.statusCode !== 200) {
error(logging, 'build', `Unexpected load result (${result.statusCode}) for ${outPath.pathname}`);
} else {
const bytes = result.contents;
diff --git a/src/runtime.ts b/src/runtime.ts
index 62bbdb09c..800c4d40a 100644
--- a/src/runtime.ts
+++ b/src/runtime.ts
@@ -26,7 +26,7 @@ type LoadResultSuccess = {
contentType?: string | false;
};
type LoadResultNotFound = { statusCode: 404; error: Error };
-type LoadResultRedirect = { statusCode: 301 | 302; location: string; };
+type LoadResultRedirect = { statusCode: 301 | 302; location: string };
type LoadResultError = { statusCode: 500 } & ({ type: 'parse-error'; error: CompileError } | { type: 'unknown'; error: Error });
export type LoadResult = LoadResultSuccess | LoadResultNotFound | LoadResultRedirect | LoadResultError;
@@ -45,7 +45,7 @@ async function load(config: RuntimeConfig, rawPathname: string | undefined): Pro
info(logging, 'access', reqPath);
const searchResult = searchForPage(fullurl, astroRoot);
- if(searchResult.statusCode === 404) {
+ if (searchResult.statusCode === 404) {
try {
const result = await frontendSnowpack.loadUrl(reqPath);
@@ -65,7 +65,7 @@ async function load(config: RuntimeConfig, rawPathname: string | undefined): Pro
}
}
- if(searchResult.statusCode === 301) {
+ if (searchResult.statusCode === 301) {
return { statusCode: 301, location: searchResult.pathname };
}
diff --git a/src/search.ts b/src/search.ts
index d9e2fa00c..043b5c347 100644
--- a/src/search.ts
+++ b/src/search.ts
@@ -6,54 +6,57 @@ interface PageLocation {
}
function findAnyPage(candidates: Array<string>, astroRoot: URL): PageLocation | false {
- for(let candidate of candidates) {
+ for (let candidate of candidates) {
const url = new URL(`./pages/${candidate}`, astroRoot);
- if(existsSync(url)) {
+ if (existsSync(url)) {
return {
fileURL: url,
- snowpackURL: `/_astro/pages/${candidate}.js`
+ snowpackURL: `/_astro/pages/${candidate}.js`,
};
}
}
return false;
}
-type SearchResult = {
- statusCode: 200;
- location: PageLocation;
- pathname: string;
-} | {
- statusCode: 301;
- location: null;
- pathname: string;
-} | {
- statusCode: 404;
-};
+type SearchResult =
+ | {
+ statusCode: 200;
+ location: PageLocation;
+ pathname: string;
+ }
+ | {
+ statusCode: 301;
+ location: null;
+ pathname: string;
+ }
+ | {
+ statusCode: 404;
+ };
export function searchForPage(url: URL, astroRoot: URL): SearchResult {
const reqPath = decodeURI(url.pathname);
const base = reqPath.substr(1);
// Try to find index.astro/md paths
- if(reqPath.endsWith('/')) {
+ if (reqPath.endsWith('/')) {
const candidates = [`${base}index.astro`, `${base}index.md`];
const location = findAnyPage(candidates, astroRoot);
- if(location) {
+ if (location) {
return {
statusCode: 200,
location,
- pathname: reqPath
+ pathname: reqPath,
};
}
} else {
// Try to find the page by its name.
const candidates = [`${base}.astro`, `${base}.md`];
let location = findAnyPage(candidates, astroRoot);
- if(location) {
+ if (location) {
return {
statusCode: 200,
location,
- pathname: reqPath
+ pathname: reqPath,
};
}
}
@@ -61,15 +64,15 @@ export function searchForPage(url: URL, astroRoot: URL): SearchResult {
// Try to find name/index.astro/md
const candidates = [`${base}/index.astro`, `${base}/index.md`];
const location = findAnyPage(candidates, astroRoot);
- if(location) {
+ if (location) {
return {
statusCode: 301,
location: null,
- pathname: reqPath + '/'
+ pathname: reqPath + '/',
};
}
return {
- statusCode: 404
+ statusCode: 404,
};
-} \ No newline at end of file
+}