-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Reinaldy Rafli
committed
Oct 22, 2021
1 parent
31fd8a2
commit 8de9f99
Showing
8 changed files
with
163 additions
and
63 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 |
---|---|---|
@@ -1 +1,5 @@ | ||
<p>Index page</p> | ||
<p>Index page</p> | ||
<a href="/about">About</a> | ||
<a href="/contact">Contact</a> | ||
<a href="/projects">Projects</a> | ||
<a href="/projects/asd">Projects slug</a> |
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
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,14 +1,21 @@ | ||
import type { Route } from '../types/route'; | ||
import type { PreRoute } from '../types/route'; | ||
|
||
export const routeBlockCache = new Map<string, Record<string, any>>(); | ||
|
||
export function findRouteByFilename(routes: Route, filename: string): Route | null { | ||
const routeEntries = Object.entries(routes); | ||
let result = null; | ||
for (const route of routeEntries) { | ||
if (typeof route[1] === 'string' && filename.endsWith(route[1])) result = { [route[0]]: route[1] }; | ||
|
||
if (result) return result; | ||
} | ||
return null; | ||
/** | ||
* Sort function for prioritizing routes. | ||
* / only should be prioritized | ||
* Then, it should prioritize /about /contact | ||
* Then it should prioritize /:slug /:something | ||
* Then just return 1 for every other edge case | ||
* @param {PreRoute} a | ||
* @returns {Number} | ||
* @example | ||
* // Just put the function inside of an array sort function. | ||
* array.sort(sortRoute); | ||
* | ||
*/ | ||
export function sortRoute(a: PreRoute): number { | ||
if (a.name === '/') return -1; | ||
if (/^\/[A-Za-z0-9]/.test(a.name)) return -1; | ||
if (/^\/:/.test(a.name)) return 1; | ||
return 1; | ||
} |
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