jekyll-table-of-contents
jekyll-table-of-contents copied to clipboard
Restrict to headers in one post or div
This script looks great, but my blog home page renders multiple posts in an "infinite scroll" kind of interface, and the TOC on the first post includes all headers on all rendered posts.
It would be nice if the scanning could be restricted to descendants of a given DOM node (e.g. a given post's container).
rather then taking in another selector string for the container
(and adding special code in the toc function to look for closest(container)
) it seems like it would be more flexible to just change the existing $(settings.headers).filter(...)
into $(settings.headers, settings.context).filter(...)
-- where settings.context
defualts to $(this).context
That way, by default, the code would still look for all headers in the same context as the selected TOC elements -- which in the common case of $("#toc").toc()
will be the whole document -- but people with special needs could do things like...
// for each div.post, create a unique .toc of the headers in that div.post
$("div.post").each(function() { $(".toc", this).toc() });
..and the context
would be a lot more powerful then a simple selector string.
NB: I ended up using this built-in kramdown ToC instead of this