3

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.

rdmptn
  • 5,413
  • 1
  • 16
  • 29

2 Answers2

4

Well, depends what you exactly want. If you just want to have a unpaginated list of all your posts (TOC), then you a are fine and that can be done easily. But if you want a paginated list, you might be comfortable with a workaround.

Without paginator
In your index.html modify {% for post in site.posts %} to

{% assign posts = site.posts | where:"hide", "false" %}
{% for post in posts %}
  ...    

and add a entry hide:[true,false] in the yaml-header of your posts. You can work with front matter defaults so you just have to set hide:false in the posts you want to exclude.

With paginator

First of all, up to now (Jekyll 2.5.3) and to my knowledge there is no possibility to filter the output of the paginator without using a plugin. But as far, as i remember things might change in the upcoming versions of jekyll.

I would recommend, to work with a collection of documents for the posts that should not show up. Collections are rendered like posts (if you pass the same layout to the collection), but since the paginator only works on posts your documents (posts) in a separate collection won't show up in the paginated list of posts as rendered by the paginator.

I hope, i could help...

astark
  • 609
  • 4
  • 7
  • 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 – rdmptn Apr 09 '15 at 13:57
0

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.

rdmptn
  • 5,413
  • 1
  • 16
  • 29