This is a simple TOC generator for blog posts, its process logic is: Select all headings expect those inside blockquote
tags and generate the table of contents.
- Include the
toc-generator.js
file to the page - Add all files in
toc-assets/
to make the TOC styled - Write the placeholder
[TOC]
as the first paragraph in your post
Both non-jquery version and jquery version are deployed on a test server, generally the effects are the same. And...any bug report is welcomed = =.
Actually they were initially used as test page for this generator.
Here is a preview picture of demo page:
More details or ideas can be found in my blog if you are interested.
There is a tocConf
constant inside Javascript code:
const tocConf = {
"title": "Table Of Contents",
"placeholder": "[TOC]",
"contentWrapper": ".post-content"
};
Each stands for TOC title, placeholder and post content selector, respectively. You can change them to whatever the value you like, just make sure the contentWrapper
selector is valid.
Other codes in the file are NOT recommended to customize.