Skip to content
This repository has been archived by the owner on Jan 8, 2025. It is now read-only.

Commit

Permalink
Remove the filepath from (!toc!) syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
ptgott committed Jul 8, 2024
1 parent fbaa336 commit 3d40d7f
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
2 changes: 1 addition & 1 deletion server/fixtures/toc/database-access/source.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

Here is an intro.

(!toc database-access!)
(!toc!)
5 changes: 3 additions & 2 deletions server/remark-toc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,12 @@ export const getTOC = (filePath: string, fs = nodeFS) => {
const files = fs.readdirSync(dirPath, "utf8");
let mdxFiles = new Set();
const dirs = files.reduce((accum, current) => {
// Don't add a TOC entry for the current file.
if (name == path.parse(current).name) {
return accum;
}
const stats = fs.statSync(path.join(dirPath, current));
if (!stats.isDirectory()) {
if (!stats.isDirectory() && current.endsWith(".mdx")) {
mdxFiles.add(path.join(dirPath, current));
return accum;
}
Expand Down Expand Up @@ -83,7 +84,7 @@ export const getTOC = (filePath: string, fs = nodeFS) => {
return { result: entries.join("\n") };
};

const tocRegexpPattern = "^\\(!toc ([^!]+)!\\)$";
const tocRegexpPattern = "^\\(!toc!\\)$";

export default function remarkTOC(): Transformer {
return (root: Content, vfile: VFile) => {
Expand Down

0 comments on commit 3d40d7f

Please sign in to comment.