Start working on responsiveness and about page.

This commit is contained in:
Joshua Bemenderfer
2023-02-13 22:09:29 -05:00
parent 6dce7ff031
commit 8b9a136d88
22 changed files with 106 additions and 47 deletions

View 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')
}

View 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
}

View 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
}

View 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
}

View File

@@ -0,0 +1,10 @@
module.exports = async function (doc) {
const { head, tail } = doc
const node = {
type: head(),
icon: tail()
}
return node
}

View 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
}

View 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
}

View 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
View 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
}