From bc97e6ee89426a2a1d9f57f9cc87608e9e9fd81d Mon Sep 17 00:00:00 2001 From: 3y3k0 <3y3k0@yandex-team.ru> Date: Sun, 25 Jun 2023 20:16:18 +0300 Subject: [PATCH] fix: Resolve generic includer paths relative to toc.yaml --- src/services/includers/batteries/generic.ts | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/services/includers/batteries/generic.ts b/src/services/includers/batteries/generic.ts index 60c12afe..4057714d 100644 --- a/src/services/includers/batteries/generic.ts +++ b/src/services/includers/batteries/generic.ts @@ -1,5 +1,5 @@ import {readFile, writeFile, mkdir} from 'fs/promises'; -import {parse, join, dirname, relative} from 'path'; +import {parse, join, dirname} from 'path'; import {updateWith} from 'lodash'; import {dump} from 'js-yaml'; @@ -42,12 +42,15 @@ async function includerFunction(params: IncluderFunctionParams) { const tocDirPath = dirname(tocPath); - const contentPath = index === 0 ? join(writeBasePath, input) : join(readBasePath, input); + const contentPath = index === 0 + ? join(writeBasePath, tocDirPath, input) + : join(readBasePath, tocDirPath, input); let cache = {}; let found = []; - ({state: {found, cache}} = await glob(join(contentPath, MD_GLOB), { + ({state: {found, cache}} = await glob(MD_GLOB, { + cwd: contentPath, nosort: true, nocase: true, cache, @@ -55,18 +58,16 @@ async function includerFunction(params: IncluderFunctionParams) { const writePath = join(writeBasePath, tocDirPath, item.include.path); - const filePaths = found.map((path) => relative(contentPath, path)); - await mkdir(writePath, {recursive: true}); - for (const filePath of filePaths) { + for (const filePath of found) { const file = await readFile(join(contentPath, filePath)); await mkdir(dirname(join(writePath, filePath)), {recursive: true}); await writeFile(join(writePath, filePath), file); } - const graph = createGraphFromPaths(filePaths); + const graph = createGraphFromPaths(found); const toc = createToc(leadingPageName, item.include.path)(graph, []);