Skip to content

Commit

Permalink
fix(index): handle index files
Browse files Browse the repository at this point in the history
  • Loading branch information
ph1p committed Sep 2, 2021
1 parent f59edb3 commit a65e631
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
5 changes: 3 additions & 2 deletions src/lib/list-folder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,17 @@ export const listFolder = async (srcPath: string, exclude: string[] = [], mainPa
const isDir = dirent.isDirectory();
const ext = path.extname(filePath);
let name = path.basename(filePath).replace(ext, '');
const folder = filePath.replace(name, '').replace(ext, '');

if (name === 'index') {
name = '_index';
name = '__index__';
}

const file = {
isDir,
name,
path: filePath,
...(!isDir ? { ext, folder: filePath.replace(name, '').replace(ext, '') } : {})
...(!isDir ? { ext, folder } : {})
};

// skip readmes as they are automatically resolved
Expand Down
20 changes: 12 additions & 8 deletions src/lib/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,13 @@ export const parseFile = async (
// parse file
try {
let content = '';
let fileName = file.name;
if (fileName === '__index__') {
fileName = 'index';
}

content = await jsdoc2md.render({
files: [join(file.folder, file.name + file.ext)],
files: [join(process.cwd(), file.folder, fileName + file.ext)],
configure: configPath,
partial: [
resolve(__filename, '../../../template/header.hbs'),
Expand All @@ -44,7 +48,7 @@ export const parseFile = async (
});

fileContent = parseVuepressFileHeader(
await fs.readFile(`${join(folderInSrc, file.name + file.ext)}`, 'utf-8'),
await fs.readFile(`${join(folderInSrc, fileName + file.ext)}`, 'utf-8'),
file
);

Expand Down Expand Up @@ -92,15 +96,15 @@ export const parseVueFile = async (
let fileContent = '';

try {
let fileName = file.name;
if (fileName === '__index__') {
fileName = 'index';
}
// parse file
const data = await compileTemplates(
join(config.componentsRoot, file.name + file.ext),
config,
file.name + file.ext
);
const data = await compileTemplates(join(config.componentsRoot, fileName + file.ext), config, fileName + file.ext);

fileContent = parseVuepressFileHeader(
await fs.readFile(`${join(folderInSrc, file.name + file.ext)}`, 'utf-8'),
await fs.readFile(`${join(folderInSrc, fileName + file.ext)}`, 'utf-8'),
file
);

Expand Down

0 comments on commit a65e631

Please sign in to comment.