From 95caa3bac50135854bb7d2b3d0c24320d1686a4b Mon Sep 17 00:00:00 2001 From: Roman Timashev Date: Sun, 23 Feb 2020 03:48:45 +0300 Subject: [PATCH] get breadcrumbs implemented --- modules/hudozka-api/src/controllers/page.ts | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/modules/hudozka-api/src/controllers/page.ts b/modules/hudozka-api/src/controllers/page.ts index 3e043ea9..7425caf7 100644 --- a/modules/hudozka-api/src/controllers/page.ts +++ b/modules/hudozka-api/src/controllers/page.ts @@ -6,11 +6,22 @@ import { Breadcrumb } from '../types' async function getBreadcrumbs(path: string): Promise { const bc = getPathWaterfall(path) + const parts = await Promise.all(bc.map(async href => { + const resource = await Page.findByUrl(href) - return bc.map(href => ({ - name: href, - href, + if (!resource) { + return null + } + + const name = resource.title + + return { + name, + href, + } })) + + return parts.filter(Boolean) } export async function getItem(req: Request, res: Response) {