nfp_sites/base/page/util.mjs

34 lines
678 B
JavaScript
Raw Normal View History

import { contentToBlocks, parseMediaAndBanner } from '../util.mjs'
2022-07-27 08:41:18 +00:00
export function parsePagesToTree(pages) {
let out = []
let children = []
let map = new Map()
for (let page of pages) {
if (!page.parent_id) {
out.push(page)
} else {
children.push(page)
}
map.set(page.id, page)
}
for (let page of children) {
let parent = map.get(page.parent_id)
if (!parent.children) {
parent.children = []
}
parent.children.push(page)
}
return {
tree: out
}
}
export function parsePage(page) {
if (!page) {
return null
}
page.content = contentToBlocks(page.content)
parseMediaAndBanner(page)
return page
2022-07-27 08:41:18 +00:00
}