Skip to content

Commit

Permalink
fix-is-route-index-prerender-util (#132)
Browse files Browse the repository at this point in the history
  • Loading branch information
Willy Brauner authored Jul 28, 2023
1 parent 2ebc54b commit cddddb4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
8 changes: 8 additions & 0 deletions apps/front/prerender/__tests__/isRouterIndex.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ it("should detect if URL is a route index", () => {
"/en/thanks",
"/en/thanks/form",
"/en/thanks/form/test",

"/fr/",
"/fr",
"/fr-xp",
]

// url "/" always need to return true
Expand All @@ -47,4 +51,8 @@ it("should detect if URL is a route index", () => {
expect(isRouteIndex("/en/thanks/test", urls)).toBe(false)
expect(isRouteIndex("/en/thanks/form", urls)).toBe(true)
expect(isRouteIndex("/en/thanks/form/test", urls)).toBe(false)

// if url end with "/" it's a route index
expect(isRouteIndex("/fr/", urls)).toBe(true)
expect(isRouteIndex("/fr", urls)).toBe(true)
})
5 changes: 4 additions & 1 deletion apps/front/prerender/helpers/isRouteIndex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,17 @@
*/
export const isRouteIndex = (url, urls, log = false): boolean => {
if (!urls.includes(url)) {
console.warn(`isRouteIndex > ${url} isn't in the list, return false.`)
// console.warn(`isRouteIndex > ${url} isn't in the list, return false.`)
return false
}

log && console.log("url", url)
// if URL is "/" we want to generate /index.html
if (url === "/") return true

// If /url/ we want to generate /url/index.html
if (url.endsWith("/")) return true

// get every URL of the list witch starting with same base
const group = urls.filter((e) => e.startsWith(url))
log && console.log("group", group)
Expand Down

0 comments on commit cddddb4

Please sign in to comment.