Get includes working relatively.
This commit is contained in:
parent
f42225bd13
commit
79d044ebac
1
docs/pages/docs/c.tce
Normal file
1
docs/pages/docs/c.tce
Normal file
@ -0,0 +1 @@
|
|||||||
|
Include ../../../packages/c/docs/index.tce
|
1
docs/pages/docs/javascript.tce
Normal file
1
docs/pages/docs/javascript.tce
Normal file
@ -0,0 +1 @@
|
|||||||
|
Include ../../../packages/js/docs/index.tce
|
@ -2,13 +2,16 @@ import knownNodes from './nodes/index.js'
|
|||||||
import { useDocument } from '@terrace-lang/js'
|
import { useDocument } from '@terrace-lang/js'
|
||||||
import { createFileReader } from '@terrace-lang/js/readers/node-readline'
|
import { createFileReader } from '@terrace-lang/js/readers/node-readline'
|
||||||
|
|
||||||
export default async function(inputPath) {
|
import process from 'node:process'
|
||||||
const doc = useDocument(createFileReader(inputPath))
|
import path from 'node:path'
|
||||||
|
|
||||||
|
export default async function(filePath) {
|
||||||
|
filePath = path.resolve(filePath)
|
||||||
|
const doc = useDocument(createFileReader(filePath))
|
||||||
const { next, line, match, tail, level, head } = doc
|
const { next, line, match, tail, level, head } = doc
|
||||||
|
|
||||||
const pageData = {
|
const page = {
|
||||||
type: `Page`,
|
type: `Page`,
|
||||||
path: inputPath,
|
|
||||||
title: '',
|
title: '',
|
||||||
description: [],
|
description: [],
|
||||||
layout: '',
|
layout: '',
|
||||||
@ -16,27 +19,37 @@ export default async function(inputPath) {
|
|||||||
children: []
|
children: []
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const context = {
|
||||||
|
page,
|
||||||
|
filePath
|
||||||
|
}
|
||||||
|
|
||||||
|
const originalCWD = process.cwd()
|
||||||
while(await next()) {
|
while(await next()) {
|
||||||
if (!line()) continue
|
if (!line()) continue
|
||||||
if (match('title')) pageData.title = tail()
|
if (match('title')) page.title = tail()
|
||||||
else if (match('layout')) pageData.layout = tail()
|
else if (match('layout')) page.layout = tail()
|
||||||
else if (match('description')) {
|
else if (match('description')) {
|
||||||
const l = level()
|
const l = level()
|
||||||
while(await next(l)) {
|
while(await next(l)) {
|
||||||
pageData.description.push(line(l))
|
page.description.push(line(l))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (match('Section')) {
|
else if (match('Section')) {
|
||||||
pageData.children.push(await knownNodes.Section(doc, level(), pageData))
|
page.children.push(await knownNodes.Section(doc, level(), context))
|
||||||
|
}
|
||||||
|
else if (match('Include')) {
|
||||||
|
page.children.push(await knownNodes.Include(doc, level(), context))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
process.chdir(originalCWD)
|
||||||
|
|
||||||
// Structure headings into tree.
|
// Structure headings into tree.
|
||||||
pageData.headings.forEach((heading, index) => {
|
page.headings.forEach((heading, index) => {
|
||||||
let parent = null
|
let parent = null
|
||||||
for (let i = index; i > 0; --i) {
|
for (let i = index; i > 0; --i) {
|
||||||
if (pageData.headings[i].level === heading.level - 1) {
|
if (page.headings[i].level === heading.level - 1) {
|
||||||
parent = pageData.headings[i]
|
parent = page.headings[i]
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -44,7 +57,7 @@ export default async function(inputPath) {
|
|||||||
if (parent) parent.children.push(heading)
|
if (parent) parent.children.push(heading)
|
||||||
})
|
})
|
||||||
|
|
||||||
pageData.headings = pageData.headings.filter(h => h.level === 2)
|
page.headings = page.headings.filter(h => h.level === 2)
|
||||||
|
|
||||||
return pageData
|
return page
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import slugify from '@sindresorhus/slugify'
|
import slugify from '@sindresorhus/slugify'
|
||||||
|
|
||||||
export default async function (doc, rootLevel, pageData) {
|
export default async function (doc, rootLevel, context) {
|
||||||
const { next, line, match, tail, level, head } = doc
|
const { next, line, match, tail, level, head } = doc
|
||||||
|
|
||||||
const headingLevel = +tail().split(' ')[0]
|
const headingLevel = +tail().split(' ')[0]
|
||||||
@ -22,7 +22,7 @@ export default async function (doc, rootLevel, pageData) {
|
|||||||
if (match('href')) node.href = tail()
|
if (match('href')) node.href = tail()
|
||||||
}
|
}
|
||||||
|
|
||||||
pageData.headings.push(node)
|
context.page.headings.push(node)
|
||||||
|
|
||||||
return node
|
return node
|
||||||
}
|
}
|
||||||
|
@ -2,10 +2,12 @@ import { useDocument } from '@terrace-lang/js/document'
|
|||||||
import { createFileReader } from '@terrace-lang/js/readers/node-readline'
|
import { createFileReader } from '@terrace-lang/js/readers/node-readline'
|
||||||
import fs from 'fs/promises'
|
import fs from 'fs/promises'
|
||||||
import path from 'path'
|
import path from 'path'
|
||||||
|
import process from 'node:process'
|
||||||
import knownNodes from './index.js'
|
import knownNodes from './index.js'
|
||||||
|
|
||||||
export default async function (originalDoc, rootLevel, ...args) {
|
export default async function (originalDoc, rootLevel, context) {
|
||||||
const includedDoc = useDocument(createFileReader(originalDoc.tail()))
|
const includePath = originalDoc.tail()
|
||||||
|
const includedDoc = useDocument(createFileReader(includePath))
|
||||||
const { next, head, tail, level } = includedDoc
|
const { next, head, tail, level } = includedDoc
|
||||||
|
|
||||||
const node = {
|
const node = {
|
||||||
@ -14,13 +16,21 @@ export default async function (originalDoc, rootLevel, ...args) {
|
|||||||
children: []
|
children: []
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
const root = path.dirname(context.filePath)
|
||||||
|
const originalFilepath = context.filePath
|
||||||
|
context.filePath = includePath
|
||||||
|
|
||||||
|
process.chdir(path.dirname(originalFilepath))
|
||||||
while (await next()) {
|
while (await next()) {
|
||||||
if (!head()) continue
|
if (!head()) continue
|
||||||
const block = head()
|
const block = head()
|
||||||
|
|
||||||
if (!knownNodes[block]) continue
|
if (!knownNodes[block]) continue
|
||||||
node.children.push(await knownNodes[block](includedDoc, level(), ...args))
|
node.children.push(await knownNodes[block](includedDoc, level(), context))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
process.chdir(path.dirname(originalFilepath))
|
||||||
|
|
||||||
return node
|
return node
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,7 @@
|
|||||||
<meta name="description" content="{{ page.description | join(' ') }}"/>
|
<meta name="description" content="{{ page.description | join(' ') }}"/>
|
||||||
<link rel="stylesheet" href="/main.css"/>
|
<link rel="stylesheet" href="/main.css"/>
|
||||||
<link rel="stylesheet" href="/public/styles/highlightjs-theme.css"/>
|
<link rel="stylesheet" href="/public/styles/highlightjs-theme.css"/>
|
||||||
{{ googleFonts('https://fonts.googleapis.com/css2?family=Fredoka:wght@300;400;500&display=swap') }}
|
{{ 'https://fonts.googleapis.com/css2?family=Fredoka:wght@300;400;500&display=swap' | googleFonts }}
|
||||||
</head>
|
</head>
|
||||||
<body class="text-base pt-16">
|
<body class="text-base pt-16">
|
||||||
{{ Node('Navbar', {}, { headings: page.headings, url: url }) }}
|
{{ Node('Navbar', {}, { headings: page.headings, url: url }) }}
|
||||||
|
@ -8,7 +8,9 @@ import featherIcons from './util/feather-icons.js'
|
|||||||
|
|
||||||
const pages = {
|
const pages = {
|
||||||
'/': './pages/index.tce',
|
'/': './pages/index.tce',
|
||||||
'/about/': './pages/about.tce'
|
'/about/': './pages/about.tce',
|
||||||
|
'/docs/javascript/': './pages/docs/javascript.tce',
|
||||||
|
'/docs/c/': './pages/docs/c.tce'
|
||||||
}
|
}
|
||||||
|
|
||||||
async function render() {
|
async function render() {
|
||||||
@ -17,7 +19,14 @@ async function render() {
|
|||||||
for (const [urlPath, filePath] of Object.entries(pages)) {
|
for (const [urlPath, filePath] of Object.entries(pages)) {
|
||||||
const env = nunjucks.configure('renderer/', { autoescape: false })
|
const env = nunjucks.configure('renderer/', { autoescape: false })
|
||||||
|
|
||||||
env.addGlobal('googleFonts', googleFonts)
|
env.addFilter('googleFonts', async (val, cb) => {
|
||||||
|
try {
|
||||||
|
cb(null, await googleFonts(val))
|
||||||
|
} catch (e) {
|
||||||
|
cb(e)
|
||||||
|
}
|
||||||
|
}, true)
|
||||||
|
|
||||||
env.addGlobal('featherIcons', featherIcons)
|
env.addGlobal('featherIcons', featherIcons)
|
||||||
|
|
||||||
HighlightJS.registerLanguage('terrace', () => ({
|
HighlightJS.registerLanguage('terrace', () => ({
|
||||||
@ -36,7 +45,13 @@ async function render() {
|
|||||||
})
|
})
|
||||||
|
|
||||||
const page = await readPage(filePath)
|
const page = await readPage(filePath)
|
||||||
const result = env.render('layout.njk', { page, url: urlPath, file: filePath })
|
|
||||||
|
const result = await new Promise((resolve, reject) => {
|
||||||
|
env.render('layout.njk', { page, url: urlPath, file: filePath }, (err, res) => {
|
||||||
|
if (err) return reject(err)
|
||||||
|
resolve(res)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
await fs.mkdir(path.join('dist', urlPath), { recursive: true })
|
await fs.mkdir(path.join('dist', urlPath), { recursive: true })
|
||||||
await fs.writeFile(path.join('dist', urlPath, 'index.html'), result)
|
await fs.writeFile(path.join('dist', urlPath, 'index.html'), result)
|
||||||
|
@ -77,8 +77,8 @@ Section light
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
Include ./src/docs/c/core-api.inc.tce
|
Include ./core-api.inc.tce
|
||||||
Include ./src/docs/c/document-api.inc.tce
|
Include ./document-api.inc.tce
|
||||||
|
|
||||||
Heading 2 Contributing
|
Heading 2 Contributing
|
||||||
class mt-12
|
class mt-12
|
||||||
|
@ -35,10 +35,10 @@ Section light
|
|||||||
# Yarn (https://yarnpkg.com/)
|
# Yarn (https://yarnpkg.com/)
|
||||||
$ yarn add @terrace-lang/js
|
$ yarn add @terrace-lang/js
|
||||||
|
|
||||||
Include ./src/docs/javascript/core-api.inc.tce
|
Include ./core-api.inc.tce
|
||||||
Include ./src/docs/javascript/document-api.inc.tce
|
Include ./document-api.inc.tce
|
||||||
Include ./src/docs/javascript/reader-api.inc.tce
|
Include ./reader-api.inc.tce
|
||||||
Include ./src/docs/javascript/recipes.inc.tce
|
Include ./recipes.inc.tce
|
||||||
|
|
||||||
Heading 2 Contributing
|
Heading 2 Contributing
|
||||||
class mt-12
|
class mt-12
|
||||||
|
Loading…
x
Reference in New Issue
Block a user