Search code examples
jekylltableofcontents

Hide an entry from the TOC (table of contents) in Jekyll


I have a site that has a lot of markdown files sorted into appropriate folders. Jekyll creates their HTML versions and the TOC (table of contents) automatically. In the _config.yml file I can rename some folders, rearrange them (e.g., if I don't want them sorted alphabetically).

I went through their documentation (http://jekyllrb.com/docs/home/) and I did not see a way to hide a file/folder from the TOC. I hope I have missed something.

What I want is to hide some folders and files from the TOC, but keep them live so people with the correct URL can still read the articles. As to why - legacy stuff I don't want people to find by themselves, but old links must still work and I must keep the information online.

Thus, I cannot use the published: false approach in the heading of the markdown file itself, as this will bring it offline.

Here is an example of my config file:

    "someFolderWithChildren":
        title: "Name of my folder"
        position: 10
    "someFolderWithChildren/child-folder-I-want-hidden":
        title: "hidden folder 1"

        published: false
        visible: false
        noToc: true
        hidden: true    # these did not work (I admit to guessing in frustration a lot)
    "someFolderWithChildren/another-folder-I-want-hidden":
        title: "hidden folder 2"
        position: 8
    "someFolderWithChildren/folder-i-want-in-the-toc":
        title: "some live folder"
        position: 1
    "someFolderWithChildren/folder-i-want-in-the-toc/child-folder-i-want live":
        title: "yet another live foder"
        position: 0

I really hope someone can point me in the right direction.

EDIT: to answer the comment and answer - I do not use posts, I am afraid, I am tied with other types of content. Further digging showed that the TOC tree is actually a custom JS widget and it seems I need to look into the way its data source is generated by the existing plugins. Thank you for your assistance and your time.


Solution

  • It turned out that the site i had had a custom plugin that goes through all md files, creates a list for the TOC and serializes it to a json file that is then used by a client-side treeview widget (kendo ui, btw) for its data source. So, i ended up with a few lines of ruby code that skipped adding the folders i want hidden to that json.

    While that worked for me, i see the idea in the posted answer and it is perhaps the way to go in a more oob scenario.