33 lines
731 B
JavaScript
33 lines
731 B
JavaScript
const knownNodes = require('./nodes/index.js')
|
|
|
|
module.exports = async function(doc) {
|
|
const { next, line, match, tail, level, head } = doc
|
|
|
|
const pageData = {
|
|
type: `Page`,
|
|
title: '',
|
|
description: [],
|
|
layout: '',
|
|
children: []
|
|
}
|
|
|
|
while(await next()) {
|
|
if (!line()) continue
|
|
if (match('title')) pageData.title = tail()
|
|
else if (match('layout')) pageData.layout = tail()
|
|
else if (match('description')) {
|
|
const l = level()
|
|
while(await next(l)) {
|
|
pageData.description.push(line(l))
|
|
}
|
|
}
|
|
else if (match('Section')) {
|
|
pageData.children.push(await knownNodes.Section(doc, level()))
|
|
}
|
|
}
|
|
|
|
console.dir(pageData, { depth: null })
|
|
|
|
return pageData
|
|
}
|