-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
11 changed files
with
314 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,3 +9,5 @@ lib_map.json | |
.jekyll-metadata | ||
.netlify | ||
__pycache__/ | ||
node_modules | ||
.vercel |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
20 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
3.2.2 | ||
3.3.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { makeRoutes } from "./routes.mjs"; | ||
|
||
const makeConfig = () => ({ | ||
version: 3, | ||
routes: makeRoutes(), | ||
}); | ||
|
||
console.log(JSON.stringify(makeConfig(), null, 2)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import { getTransformedRoutes } from "@vercel/routing-utils"; | ||
import { convertTrailingSlash } from "@vercel/routing-utils/dist/superstatic.js"; | ||
import { readFileSync } from "node:fs"; | ||
import path from "node:path"; | ||
|
||
const DEFAULT_REDIRECT_CODE = 301; | ||
|
||
const makeRedirectsFromFile = () => { | ||
const redirectsFile = path.join( | ||
import.meta.dirname, | ||
"..", | ||
"..", | ||
"_redirects" | ||
); | ||
const redirectsFileContents = readFileSync(redirectsFile, "utf8"); | ||
const redirects = redirectsFileContents | ||
.split("\n") | ||
.filter(Boolean) | ||
.map((line) => { | ||
const [source, destination] = line.split(/\s+/).filter(Boolean); | ||
return { | ||
source, | ||
destination, | ||
statusCode: DEFAULT_REDIRECT_CODE, | ||
}; | ||
}); | ||
return redirects; | ||
}; | ||
|
||
const makeRedirects = () => { | ||
const redirects = []; | ||
redirects.push(...makeRedirectsFromFile()); | ||
return redirects; | ||
}; | ||
|
||
export const makeRoutes = () => { | ||
const { routes, error } = getTransformedRoutes({ | ||
redirects: makeRedirects(), | ||
}); | ||
|
||
if (error) throw error; | ||
return [ | ||
...convertTrailingSlash(true, 301), | ||
...routes, | ||
{ | ||
handle: "error", | ||
}, | ||
{ | ||
status: 404, | ||
src: "^.*$", | ||
dest: "/404.html", | ||
}, | ||
]; | ||
}; |
Oops, something went wrong.