Get includes working relatively.
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
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 headingLevel = +tail().split(' ')[0]
|
||||
@@ -22,7 +22,7 @@ export default async function (doc, rootLevel, pageData) {
|
||||
if (match('href')) node.href = tail()
|
||||
}
|
||||
|
||||
pageData.headings.push(node)
|
||||
context.page.headings.push(node)
|
||||
|
||||
return node
|
||||
}
|
||||
|
||||
@@ -2,10 +2,12 @@ import { useDocument } from '@terrace-lang/js/document'
|
||||
import { createFileReader } from '@terrace-lang/js/readers/node-readline'
|
||||
import fs from 'fs/promises'
|
||||
import path from 'path'
|
||||
import process from 'node:process'
|
||||
import knownNodes from './index.js'
|
||||
|
||||
export default async function (originalDoc, rootLevel, ...args) {
|
||||
const includedDoc = useDocument(createFileReader(originalDoc.tail()))
|
||||
export default async function (originalDoc, rootLevel, context) {
|
||||
const includePath = originalDoc.tail()
|
||||
const includedDoc = useDocument(createFileReader(includePath))
|
||||
const { next, head, tail, level } = includedDoc
|
||||
|
||||
const node = {
|
||||
@@ -14,13 +16,21 @@ export default async function (originalDoc, rootLevel, ...args) {
|
||||
children: []
|
||||
}
|
||||
|
||||
|
||||
const root = path.dirname(context.filePath)
|
||||
const originalFilepath = context.filePath
|
||||
context.filePath = includePath
|
||||
|
||||
process.chdir(path.dirname(originalFilepath))
|
||||
while (await next()) {
|
||||
if (!head()) continue
|
||||
const block = head()
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user