From 41d7cfaaa1e58d4d5002d3c8c34e0cd133b7faeb Mon Sep 17 00:00:00 2001 From: Chad Sheets Date: Mon, 5 Mar 2018 19:53:29 -0800 Subject: [PATCH 1/4] organize nav and toc --- README.md | 29 +++++++++++++----- mkdocs.yml | 3 +- requirements.txt | 2 +- rtd_dropdown/base.html | 9 ++---- rtd_dropdown/nav.html | 60 +++++++++----------------------------- rtd_dropdown/toc-item.html | 15 ++++++++++ rtd_dropdown/toc.html | 37 ++++++++++++++--------- 7 files changed, 79 insertions(+), 76 deletions(-) create mode 100644 rtd_dropdown/toc-item.html diff --git a/README.md b/README.md index 9152495..682dae8 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ A ReadTheDocs theme for [MkDocs](http://www.mkdocs.org/) with collapsing menu su ![Dropdown Demo](docs/img/example.png) -How to use +How to install ---------- Install the ReadTheDocs Dropdown theme with pip: @@ -27,19 +27,34 @@ theme: ``` -Features --------- +How to use +---------- + +You have a couple folder/document-structure options when using this theme. + +## Default Settings + +Both ReadTheDocs and MkDocs use a "long-page" document structure. There is no nesting of pages. See [user-guide/instructions/](http://readthedocs.sheets.ch/user-guide/instructions/) as an example. + +Collapsing is based on top-level headings in each page. + +``` +# Page Title <-- Top level heading + +content, content, content +``` + -* Based on the ReadTheDocs theme build-into MkDocs -* Adds dropdown functionality to the sidebar (similar to ReadTheDocs) -For further discussion, see [this issue](https://github.com/mkdocs/mkdocs/issues/588#issuecomment-341931422). Considerations -------------- -ToDo +* Based on the ReadTheDocs theme build-into MkDocs +* Adds dropdown functionality to the sidebar (similar to ReadTheDocs) + +For further discussion, see [this issue](https://github.com/mkdocs/mkdocs/issues/588#issuecomment-341931422). diff --git a/mkdocs.yml b/mkdocs.yml index 0cae06d..78744e2 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -2,7 +2,8 @@ site_name: ReadTheDocs Dropdown site_description: 'Updated version of MkDocs ReadTheDocs theme' site_author: 'Chad Sheets' -theme_dir: rtd_dropdown +theme: + name: rtd-dropdown repo_url: https://github.com/cjsheets/readthedocs-dropdown diff --git a/requirements.txt b/requirements.txt index 30fa6e3..50f05f7 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,2 @@ #git+http://github.com/cjsheets/mkdocs.git@dev#egg=mkdocs -mkdocs +#mkdocs diff --git a/rtd_dropdown/base.html b/rtd_dropdown/base.html index 02a3b75..4eee68c 100644 --- a/rtd_dropdown/base.html +++ b/rtd_dropdown/base.html @@ -75,12 +75,9 @@   diff --git a/rtd_dropdown/nav.html b/rtd_dropdown/nav.html index 23060f7..b0698e5 100644 --- a/rtd_dropdown/nav.html +++ b/rtd_dropdown/nav.html @@ -1,5 +1,6 @@ {%- set child_url = '' %} {#| Target of the current link |#} +{% for nav_item in nav %} {%- if nav_item.children %} {%- if nav_item.children[0].input_path %} @@ -14,52 +15,17 @@ {%- endif %} -{%- if navlevel == 1 and child_url == '' %} - -{%- endif %} \ No newline at end of file +{% endfor %} \ No newline at end of file diff --git a/rtd_dropdown/toc-item.html b/rtd_dropdown/toc-item.html new file mode 100644 index 0000000..b55a2ad --- /dev/null +++ b/rtd_dropdown/toc-item.html @@ -0,0 +1,15 @@ + +{%- set toclevel = toclevel + 1 %} + diff --git a/rtd_dropdown/toc.html b/rtd_dropdown/toc.html index 9d1743d..b9ef762 100644 --- a/rtd_dropdown/toc.html +++ b/rtd_dropdown/toc.html @@ -1,16 +1,25 @@ -{% for toc_item in page.toc %} -
  • - {% if nav_item.title != toc_item.title %} - {{ toc_item.title }} - {% endif %} - {% if toc_item.children %} - + +
    + +
    + {% endfor %} \ No newline at end of file diff --git a/rtd_dropdown/toc-item.html b/rtd_dropdown/toc-item.html index 9250e49..bd51ec0 100644 --- a/rtd_dropdown/toc-item.html +++ b/rtd_dropdown/toc-item.html @@ -1,19 +1,20 @@ - - - - -{{(nav_item.title + toc_ns.top_level_headings | string) | debug}} {%- set toclevel = toclevel + 1 %} + {#| Support collapse-by-default setting |#} + {% if toc_item.active and (toc_ns.top_level_headings == 1 or not + (config.theme is defined and config.theme.collapse_by_default)) %} + {%- set class_is_active = 'current' %} + {% endif %} + {% if toc_item.children is defined and toc_item.children | length > 0 and toclevel < 2 %} -
  • {% if toc_ns.top_level_headings is defined and toc_ns.top_level_headings > 1 %} - + {{ toc_item.title }} {% endif %} -