Start working on responsiveness and about page.
This commit is contained in:
16
docs/src/parser/helpers.js
Normal file
16
docs/src/parser/helpers.js
Normal file
@@ -0,0 +1,16 @@
|
||||
|
||||
module.exports.contentAsText = async function(doc, rootLevel, includeCurrent = false) {
|
||||
const { level, next, line, head } = doc
|
||||
const linesAsArray = []
|
||||
if (includeCurrent) linesAsArray.push(line())
|
||||
let contentDepth = includeCurrent ? level() : -1
|
||||
|
||||
while(await next(rootLevel)) {
|
||||
if (contentDepth === -1 && !!line()) contentDepth = level()
|
||||
|
||||
const indent = ''.padStart(level() - contentDepth, ' ')
|
||||
linesAsArray.push(indent + line())
|
||||
}
|
||||
|
||||
return linesAsArray.join('\n')
|
||||
}
|
||||
23
docs/src/parser/nodes/Button.js
Normal file
23
docs/src/parser/nodes/Button.js
Normal file
@@ -0,0 +1,23 @@
|
||||
const { contentAsText } = require('../helpers.js')
|
||||
|
||||
module.exports = async function (doc, rootLevel) {
|
||||
const { next, line, match, tail, level, head } = doc
|
||||
|
||||
const node = {
|
||||
type: head(),
|
||||
variant: tail() || 'neutral',
|
||||
class: '',
|
||||
href: '',
|
||||
text: ''
|
||||
}
|
||||
|
||||
while (await next(rootLevel)) {
|
||||
if (match('class')) node.class = tail()
|
||||
else if (match('href')) node.href = tail()
|
||||
else {
|
||||
node.text = await contentAsText(doc, rootLevel, true)
|
||||
}
|
||||
}
|
||||
|
||||
return node
|
||||
}
|
||||
24
docs/src/parser/nodes/CodeExample.js
Normal file
24
docs/src/parser/nodes/CodeExample.js
Normal file
@@ -0,0 +1,24 @@
|
||||
const { contentAsText } = require('../helpers')
|
||||
|
||||
const languages = ['terrace', 'json', 'yaml', 'toml', 'javascript', 'typescript', 'c', 'python']
|
||||
|
||||
module.exports = async (doc, rootLevel) => {
|
||||
const { next, level, line, head, tail, match } = doc
|
||||
|
||||
const node = {
|
||||
type: head(),
|
||||
class: '',
|
||||
languages: {}
|
||||
}
|
||||
|
||||
while (await next(rootLevel)) {
|
||||
if (match('class')) node.class = tail()
|
||||
|
||||
const languageLevel = level()
|
||||
if (languages.includes(head())) {
|
||||
node.languages[head()] = await contentAsText(doc, languageLevel)
|
||||
}
|
||||
}
|
||||
|
||||
return node
|
||||
}
|
||||
16
docs/src/parser/nodes/Header.js
Normal file
16
docs/src/parser/nodes/Header.js
Normal file
@@ -0,0 +1,16 @@
|
||||
module.exports = async function (doc, rootLevel) {
|
||||
const { next, line, match, tail, level, head } = doc
|
||||
|
||||
const node = {
|
||||
type: head(),
|
||||
level: tail().split(' ')[0],
|
||||
text: tail().split(' ').slice(1).join(' '),
|
||||
class: ''
|
||||
}
|
||||
|
||||
while (await next(rootLevel)) {
|
||||
if (match('class')) node.class = tail()
|
||||
}
|
||||
|
||||
return node
|
||||
}
|
||||
10
docs/src/parser/nodes/Icon.js
Normal file
10
docs/src/parser/nodes/Icon.js
Normal file
@@ -0,0 +1,10 @@
|
||||
module.exports = async function (doc) {
|
||||
const { head, tail } = doc
|
||||
|
||||
const node = {
|
||||
type: head(),
|
||||
icon: tail()
|
||||
}
|
||||
|
||||
return node
|
||||
}
|
||||
21
docs/src/parser/nodes/Markdown.js
Normal file
21
docs/src/parser/nodes/Markdown.js
Normal file
@@ -0,0 +1,21 @@
|
||||
const { contentAsText } = require('../helpers.js')
|
||||
const marked = require('marked')
|
||||
|
||||
module.exports = async function (doc, rootLevel) {
|
||||
const { next, line, match, tail, level, head } = doc
|
||||
|
||||
const node = {
|
||||
type: head(),
|
||||
class: '',
|
||||
text: ''
|
||||
}
|
||||
|
||||
while (await next(rootLevel)) {
|
||||
if (match('class')) node.class = tail()
|
||||
else {
|
||||
node.text = marked.parse(await contentAsText(doc, rootLevel, true))
|
||||
}
|
||||
}
|
||||
|
||||
return node
|
||||
}
|
||||
26
docs/src/parser/nodes/Node.js
Normal file
26
docs/src/parser/nodes/Node.js
Normal file
@@ -0,0 +1,26 @@
|
||||
const knownNodes = require('./index.js')
|
||||
|
||||
module.exports = async function (doc, rootLevel) {
|
||||
const { next, line, match, tail, level, head } = doc
|
||||
|
||||
const node = {
|
||||
type: head(),
|
||||
class: '',
|
||||
children: []
|
||||
}
|
||||
|
||||
while (await next(rootLevel)) {
|
||||
if (!head()) continue
|
||||
const block = head()
|
||||
|
||||
if (match('class')) {
|
||||
node.class = tail()
|
||||
continue
|
||||
}
|
||||
|
||||
if (!knownNodes[block]) continue
|
||||
node.children.push(await knownNodes[block](doc, level()))
|
||||
}
|
||||
|
||||
return node
|
||||
}
|
||||
17
docs/src/parser/nodes/index.js
Normal file
17
docs/src/parser/nodes/index.js
Normal file
@@ -0,0 +1,17 @@
|
||||
const parseNode = require('./Node.js')
|
||||
|
||||
module.exports.Block = parseNode
|
||||
module.exports.Section = async (doc, rootLevel) => {
|
||||
const variant = doc.tail()
|
||||
return { variant, ...(await parseNode(doc, rootLevel)) }
|
||||
}
|
||||
module.exports.Header = require('./Header.js')
|
||||
module.exports.Button = require('./Button.js')
|
||||
module.exports.Icon = require('./Icon.js')
|
||||
|
||||
module.exports.Markdown = require('./Markdown.js')
|
||||
module.exports.CodeExample = require('./CodeExample.js')
|
||||
module.exports.Logo = doc => ({
|
||||
type: `Logo`,
|
||||
variant: doc.tail() || 'light'
|
||||
})
|
||||
32
docs/src/parser/page.js
Normal file
32
docs/src/parser/page.js
Normal file
@@ -0,0 +1,32 @@
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user