2022-08-02 12:34:52 +00:00
|
|
|
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
|
|
|
|
}
|
2022-08-02 12:34:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
}
|