From 448e91a97085c2aae0e7f0303f5e909301dd53db Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Fri, 20 Jul 2018 11:41:37 -0400 Subject: [PATCH] update find_page API --- src/api/find_page.ts | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/api/find_page.ts b/src/api/find_page.ts index 2e843bd..8a90c8f 100644 --- a/src/api/find_page.ts +++ b/src/api/find_page.ts @@ -2,15 +2,14 @@ import * as glob from 'glob'; import { locations } from '../config'; import { create_routes } from '../core'; -export function find_page(pathname: string, files: string[] = glob.sync('**/*.*', { cwd: locations.routes(), dot: true, nodir: true })) { - const routes = create_routes({ files }); +export function find_page(pathname: string, cwd = locations.routes()) { + const { pages } = create_routes(cwd); - for (let i = 0; i < routes.length; i += 1) { - const route = routes[i]; + for (let i = 0; i < pages.length; i += 1) { + const page = pages[i]; - if (route.pattern.test(pathname)) { - const page = route.handlers.find(handler => handler.type === 'page'); - if (page) return page.file; + if (page.pattern.test(pathname)) { + return page.parts[page.parts.length - 1].component.file; } } } \ No newline at end of file