diff --git a/CHANGELOG b/CHANGELOG index d79a3f4cfc9fa8d8819be373ad422cd772692251..55f0a9e0537aad7d68c0e254ef758ade4cb5206a 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -2,6 +2,7 @@ mkdocs-material-0.x.x (2016-xx-xx) * Fixed #3: Ordered lists within an unordered list have ::before content * Fixed #4: Click on Logo/Title without Github-Repository: "None" + * Fixed #5: Page without headlines renders empty list in table of contents * Moved Modernizr to top to ensure basic usability in IE8 mkdocs-material-0.1.2 (2016-02-16) diff --git a/material/nav.html b/material/nav.html index 9a7c43fae5257fc520772e570ae19e00a75ed028..4a8efd504136ccacf8fe29f46277b57b7de4884b 100644 --- a/material/nav.html +++ b/material/nav.html @@ -13,25 +13,21 @@ {{ nav_item.title }} </a> {% if nav_item == current_page %} - <ul> - {% for toc_item in toc %} - {% if h1 %} - {% for toc_item in toc_item.children %} - <li class="anchor"> - <a title="{{ toc_item.title }}" href="{{ toc_item.url }}"> - {{ toc_item.title }} - </a> - </li> - {% endfor %} - {% else %} - <li class="anchor"> - <a title="{{ toc_item.title }}" href="{{ toc_item.url }}"> - {{ toc_item.title }} - </a> - </li> - {% endif %} - {% endfor %} - </ul> + {% if h1 %} + {% set toc_item = toc | first %} + {% set toc = toc_item.children %} + {% endif %} + {% if toc %} + <ul> + {% for toc_item in toc %} + <li class="anchor"> + <a title="{{ toc_item.title }}" href="{{ toc_item.url }}"> + {{ toc_item.title }} + </a> + </li> + {% endfor %} + </ul> + {% endif %} {% endif %} </li> {% endif %} \ No newline at end of file diff --git a/src/nav.html b/src/nav.html index 8d30f126eb585267d3fe05f32a6f857fc2112a03..69bf9d8d7d1acaea48959d932dad0db0dea99271 100644 --- a/src/nav.html +++ b/src/nav.html @@ -21,38 +21,32 @@ <!-- Expand active pages --> {% if nav_item == current_page %} - <ul> - <!-- Render anchors of active page --> - {% for toc_item in toc %} + <!-- + The top-level anchor must be skipped if the article contains a h1 + headline, since it would be redundant to the link to the current page + that is located just above the anchor. Therefore we directly continue + with the children of the anchor. + --> + {% if h1 %} + {% set toc_item = toc | first %} + {% set toc = toc_item.children %} + {% endif %} - <!-- - The top-level anchor must be skipped if the article contains a h1 - headline, since it would be redundant to the link to the current - page that is located just above the anchor. Therefore we directly - continue with the children of the anchor. - --> - {% if h1 %} - {% for toc_item in toc_item.children %} + <!-- Render anchors of active page --> + {% if toc %} + <ul> + {% for toc_item in toc %} - <!-- Render anchor --> - <li class="anchor"> - <a title="{{ toc_item.title }}" href="{{ toc_item.url }}"> - {{ toc_item.title }} - </a> - </li> - {% endfor %} - {% else %} - - <!-- Render anchor --> - <li class="anchor"> - <a title="{{ toc_item.title }}" href="{{ toc_item.url }}"> - {{ toc_item.title }} - </a> - </li> - {% endif %} - {% endfor %} - </ul> + <!-- Render anchor --> + <li class="anchor"> + <a title="{{ toc_item.title }}" href="{{ toc_item.url }}"> + {{ toc_item.title }} + </a> + </li> + {% endfor %} + </ul> + {% endif %} {% endif %} </li> {% endif %} \ No newline at end of file