mirror of
https://github.com/squidfunk/mkdocs-material.git
synced 2024-11-23 23:21:00 +01:00
Fixed navigation/toc issues when h1 is present
This commit is contained in:
parent
7d1a71e9a5
commit
e03c58f487
@ -53,7 +53,7 @@
|
||||
|
||||
<!-- Webfonts -->
|
||||
<link rel="stylesheet" type="text/css"
|
||||
href="https://fonts.googleapis.com/css?family=Ubuntu:300,400,700" />
|
||||
href="https://fonts.googleapis.com/css?family=Ubuntu:400,700" />
|
||||
<link rel="stylesheet" type="text/css"
|
||||
href="https://fonts.googleapis.com/css?family=Ubuntu+Mono" />
|
||||
|
||||
@ -95,6 +95,14 @@
|
||||
<!-- Main content -->
|
||||
<main class="main">
|
||||
|
||||
<!--
|
||||
This is a nasty hack that checks whether the content contains a
|
||||
h1 headline. If it does, the variable h1 is set to true. This is
|
||||
necessary for correctly rendering the table of contents which is
|
||||
embedded into the navigation and the actual headline.
|
||||
-->
|
||||
{% set h1 = "\x3c/h1\x3e" in content %}
|
||||
|
||||
<!-- Drawer with navigation -->
|
||||
<div class="drawer">
|
||||
{% include "drawer.html" %}
|
||||
@ -105,12 +113,13 @@
|
||||
<div class="wrapper">
|
||||
|
||||
<!-- Headline -->
|
||||
{% if page_title %}
|
||||
<h1>{{ page_title }}</h1>
|
||||
{% else %}
|
||||
<h1>{{ site_name }}</h1>
|
||||
{% if not h1 %}
|
||||
{% if page_title %}
|
||||
<h1>{{ page_title }}</h1>
|
||||
{% else %}
|
||||
<h1>{{ site_name }}</h1>
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
<hr />
|
||||
|
||||
<!-- Article content -->
|
||||
{{ content }}
|
||||
|
@ -58,7 +58,7 @@
|
||||
<!-- Table of contents -->
|
||||
<ul class="toc">
|
||||
{% for nav_item in nav %}
|
||||
{% include "toc.html" %}
|
||||
{% include "nav.html" %}
|
||||
{% endfor %}
|
||||
|
||||
<!-- Author-related links -->
|
||||
|
59
src/nav.html
Normal file
59
src/nav.html
Normal file
@ -0,0 +1,59 @@
|
||||
<!-- Render sections -->
|
||||
{% if nav_item.children %}
|
||||
<li>
|
||||
<hr />
|
||||
<span class="section">{{ nav_item.title }}</span>
|
||||
<ul>
|
||||
|
||||
<!-- Render pages of section -->
|
||||
{% for nav_item in nav_item.children %}
|
||||
{% include 'nav.html' %}
|
||||
{% endfor %}
|
||||
</ul>
|
||||
</li>
|
||||
|
||||
<!-- Render page link -->
|
||||
{% else %}
|
||||
<li>
|
||||
<a class="{% if nav_item.active %}current{% endif %}"
|
||||
title="{{ nav_item.title }}" href="{{ nav_item.url }}" >
|
||||
{{ nav_item.title }}
|
||||
</a>
|
||||
|
||||
<!-- 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 %}
|
||||
{% for toc_item in toc_item.children %}
|
||||
|
||||
<!-- 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>
|
||||
{% endif %}
|
||||
</li>
|
||||
{% endif %}
|
37
src/toc.html
37
src/toc.html
@ -1,37 +0,0 @@
|
||||
<!-- Render sections -->
|
||||
{% if nav_item.children %}
|
||||
<li>
|
||||
<hr />
|
||||
<span class="section">{{ nav_item.title }}</span>
|
||||
<ul>
|
||||
|
||||
<!-- Render links of section -->
|
||||
{% for nav_item in nav_item.children %}
|
||||
{% include 'toc.html' %}
|
||||
{% endfor %}
|
||||
</ul>
|
||||
</li>
|
||||
|
||||
<!-- Render link -->
|
||||
{% else %}
|
||||
<li>
|
||||
<a class="{% if nav_item.active %}current{% endif %}"
|
||||
title="{{ nav_item.title }}" href="{{ nav_item.url }}" >
|
||||
{{ nav_item.title }}
|
||||
</a>
|
||||
|
||||
<!-- Expand active pages -->
|
||||
{% if nav_item == current_page %}
|
||||
<ul>
|
||||
{% for toc_item in toc %}
|
||||
<li class="anchor">
|
||||
<a class="{% if loop.first %}current{% endif %}"
|
||||
title="{{ toc_item.title }}" href="{{ toc_item.url }}">
|
||||
{{ toc_item.title }}
|
||||
</a>
|
||||
</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
{% endif %}
|
||||
</li>
|
||||
{% endif %}
|
Loading…
Reference in New Issue
Block a user