Skip to content

chenfan0/filetoc

Repository files navigation

FileToc

中文

Generates table of contents for markdown files inside local git repository. Link to file address.

Table of Contents generated with FileToc

Installation

npm install filetoc -g

Usage

Create a config File(filetoc.config.js)

Examples

// filetoc.config.js
module.exports = {
  remoteUrl: 'https://github.com/chenfan0/dirtoc', // your repo address
  mainBranch: 'main', // your default branch. default 'main'
  dirPath: '.', //  the dir where you want to gengerate the toc. default '.'
  mdPath: ['./README.md', './README.zh.md'], // the markdown files path, when there is only one path, it also can be a string.  default ['README.md']
  excludes: ['.git'] // the excludes file name or dir name
}

Specifying location of toc

You should specify where to insert the TOC in your markdown file.

Example

<!--filetoc-start-->
toc will insert here
<!--filetoc-end-->

Run filetoc

Go into the directory that contains you local git project and type:

filetoc

Use with git hooks

If you want to automatically modify the markdown for you before each commit.You can use husky to achieve this effect.

Go into the directory that contains you local git project and type:

npx husky-init && npm install

Find the pre-commit file under the generated husky folder and write in the file:

filetoc
git add .

About

a generates toc based on the directory

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published