Terrace/docs/parser/page.js
2023-02-11 22:30:10 -05:00

32 lines
705 B
JavaScript

const parseSection = require('./section.js')
module.exports = async function(doc) {
const { next, line, match, tail, level, head } = doc
const pageData = {
title: '',
description: [],
layout: '',
sections: []
}
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.sections.push(await parseSection(doc, level()))
}
}
console.dir(pageData, { depth: null })
return pageData
}