get breadcrumbs moved to separate controller
This commit is contained in:
1 parent
95caa3bac5
commit
f35f628aed
2 files changed
+25
-22
No files matched your search
@@ -0,0 +1,23 @@
|
||||
import { getPathWaterfall } from '../lib/url'
|
||||
import { Breadcrumb } from '../types'
|
||||
import Page from '../core/Page'
|
||||
|
||||
export async function getItems(path: string): Promise<Breadcrumb> {
|
||||
const bc = getPathWaterfall(path)
|
||||
const parts = await Promise.all(bc.map(async href => {
|
||||
const resource = await Page.findByUrl(href)
|
||||
|
||||
if (!resource) {
|
||||
return null
|
||||
}
|
||||
|
||||
const name = resource.title
|
||||
|
||||
return {
|
||||
name,
|
||||
href,
|
||||
}
|
||||
}))
|
||||
|
||||
return parts.filter(Boolean)
|
||||
}
|
||||
@@ -2,31 +2,11 @@ import { Request, Response } from 'express'
|
||||
import Page from '../core/Page'
|
||||
import { dropTrailingSlash, getPathWaterfall } from '../lib/url'
|
||||
import { encodePage } from '../factory/page'
|
||||
import { Breadcrumb } from '../types'
|
||||
|
||||
async function getBreadcrumbs(path: string): Promise<Breadcrumb> {
|
||||
const bc = getPathWaterfall(path)
|
||||
const parts = await Promise.all(bc.map(async href => {
|
||||
const resource = await Page.findByUrl(href)
|
||||
|
||||
if (!resource) {
|
||||
return null
|
||||
}
|
||||
|
||||
const name = resource.title
|
||||
|
||||
return {
|
||||
name,
|
||||
href,
|
||||
}
|
||||
}))
|
||||
|
||||
return parts.filter(Boolean)
|
||||
}
|
||||
import * as breadcrumb from './breadcrumb'
|
||||
|
||||
export async function getItem(req: Request, res: Response) {
|
||||
const page = dropTrailingSlash(req.query.page)
|
||||
const breadcrumbs = await getBreadcrumbs(page)
|
||||
const breadcrumbs = await breadcrumb.getItems(page)
|
||||
const resource = await Page.findByUrl(page)
|
||||
|
||||
if (resource) {
|
||||
|
||||
Reference in new issue
Block a user