public-apis/utils/db/group-row-content.js
2022-11-18 18:51:59 +01:00

25 lines
732 B
JavaScript

module.exports = function (tables) {
return tables.map(({ name, rows }) => {
const content = []
rows.forEach((child, i) => {
if (i === 0) return // Table header
if (child.type === 'link') {
content.push({
link: child.url,
name: child.children[0].value,
description: '',
})
} else {
const lastContentItem = content.pop()
content.push({
...lastContentItem,
description: `${lastContentItem.description} ${child.value}`,
})
}
})
return { name, rows: content }
})
}