Skip to content

Commit

Permalink
fix: Resolve generic includer paths relative to toc.yaml
Browse files Browse the repository at this point in the history
  • Loading branch information
3y3k0 authored and 3y3 committed Jun 27, 2023
1 parent 8759847 commit bc97e6e
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions src/services/includers/batteries/generic.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -42,31 +42,32 @@ async function includerFunction(params: IncluderFunctionParams<Params>) {

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,
}));

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, []);

Expand Down

0 comments on commit bc97e6e

Please sign in to comment.