diff --git a/_includes/directory-tree.html b/_includes/directory-tree.html
index 11fd9aeec..a3b151a3f 100644
--- a/_includes/directory-tree.html
+++ b/_includes/directory-tree.html
@@ -1,13 +1,82 @@
-
- {%- assign sorted_pages = include.pages | sort: "dir" -%}
- {%- for page in sorted_pages -%}
- {%- if page.layout == nil or page.layout == 'none' or page.dir contains '/blog/page' -%}
+{%- comment -%}
+Build a directory tree (e.g. sitemap)
+
+Page Front Matter directory-tree hash parameters:
+
+ emphasize Emphasize the page in the tree.
+ Default: false.
+
+ de-emphasize De-emphasize the page in the tree.
+ Default: false.
+
+Tree include parameters:
+
+ dir The top-level directory of the tree.
+ If the path ends with a slash, the directory itself will be excluded from the tree.
+ Default: The root directory.
+
+Tree parameters that can be passed as include hash, Front Matter directory-tree hash or Liquid variables with directory-tree- prefix:
+
+ li The generated tree is a list item. Do not wrap an tag around it.
+
+ dir_class Add a class attribute with the specified classes to - tags of all directories.
+ If not set, wrap a tag around titles of all directories.
+
+ strong Wrap a tag around titles of the pages that have set `emphasize: true` in the Front Matter.
+ Default: false.
+
+ del Wrap a
tag around titles of the pages that have set `de-emphasize: true` in the Front Matter.
+ Default: false.
+{%- endcomment -%}
+{%- unless include.li or page.directory-tree.li or directory-tree-li %}{%- endunless %}
+ {%- assign dir_class = include.dir_class | default: directory-tree-dir_class | default: page.directory-tree.dir_class -%}
+ {%- if dir_class -%}
+ {%- assign dir_li = '- ' -%}
+ {%- else -%}
+ {%- assign dir_li = "
- " -%}
+ {%- assign dir_strong = "" -%}
+ {%- assign dir_strong_closing = "" -%}
+ {%- endif -%}
+ {%- assign filtered_pages = "" | split: "," -%}
+ {%- for pg in site.pages -%}
+ {%- comment -%}
+ # Skip page unless its directory starts with include.dir.
+ {%- endcomment -%}
+ {%- if include.dir -%}
+ {%- assign check_str = pg.dir | split: include.dir | first -%}
+ {%- if check_str.size > 0 -%}
+ {%- continue -%}
+ {%- endif -%}
+ {%- endif -%}
+ {%- if pg.layout == nil or pg.layout == 'none' or pg.dir contains '/blog/page' -%}
{%- continue -%}
{%- endif -%}
- {% unless page.dir == prev_page_dir -%}
- {%- assign path = page.dir | split: "/" -%}
+ {%- assign filtered_pages = filtered_pages | push: pg -%}
+ {%- endfor -%}
+ {%- assign sorted_by_dir = filtered_pages | sort_natural: "dir" -%}
+ {%- assign subdir_pages = "" | split: "," -%}
+ {%- assign sorted_pages = "" | split: "," -%}
+ {%- for pg in sorted_by_dir -%}
+ {%- unless pg.dir == prev_page_dir -%}
+ {%- if subdir_pages.size > 0 -%}
+ {%- assign sorted_subdir_pages = subdir_pages | sort_natural: "title" -%}
+ {%- assign sorted_pages = sorted_pages | concat: sorted_subdir_pages -%}
+ {%- endif -%}
+ {%- assign subdir_pages = "" | split: "," -%}
+ {%- assign prev_page_dir = pg.dir -%}
+ {%- endunless -%}
+ {%- assign subdir_pages = subdir_pages | push: pg -%}
+ {%- endfor -%}
+ {%- if subdir_pages.size > 0 -%}
+ {%- assign sorted_subdir_pages = subdir_pages | sort_natural: "title" -%}
+ {%- assign sorted_pages = sorted_pages | concat: sorted_subdir_pages -%}
+ {%- endif -%}
+ {%- assign prev_page_dir = include.dir -%}
+ {%- for pg in sorted_pages -%}
+ {% unless pg.dir == prev_page_dir -%}
+ {%- assign path = pg.dir | split: "/" -%}
{%- comment -%}
- # Split returns [] for "/" but ["", "doc"] "/doc/" as removes empty strings.
+ # Split returns [] for "/" but ["", "doc"] "/doc/" as removes trailing empty strings.
{%- endcomment -%}
{%- unless path.size > 0 -%}
{%- assign path = path | push: "" -%}
@@ -30,28 +99,55 @@
{%- assign levels_match = index0 -%}
{%- break -%}
{%- endunless -%}
+ {%- if forloop.last -%}
+ {%- assign levels_match = forloop.index0 -%}
+ {%- endif -%}
{%- endfor -%}
{%- for num in (1..levels_back) %}
{%- endfor -%}
- {% for dir in path offset:levels_match -%}
- {%- assign dir_index_page = include.pages | where: "dir", page.dir | where: "name", "index.md" | first -%}
- {%- unless dir_index_page -%}
- {%- assign dir_index_page = include.pages | where: "dir", page.dir | where: "name", "index.html" | first -%}
- {%- endunless %}
- -
- {{ dir_index_page.title }}
+ {% for dir in path offset:levels_match %}
+ {{ dir_li }}
+ {%- if forloop.last -%}
+ {%- assign dir_pages = site.pages | where: "dir", pg.dir -%}
+ {%- assign dir_index_page = dir_pages | where: "name", "index.md" | first -%}
+ {%- unless dir_index_page -%}
+ {%- assign dir_index_page = dir_pages | where: "name", "index.html" | first -%}
+ {%- endunless %}
+ {{ dir_strong }}{{ dir_index_page.title }}{{ dir_strong_closing }}
+ {%- else %}
+ {{ dir_strong }}{{ dir }}{{ dir_strong_closing }}
+ {%- endif %}
{%- endfor %}
- {%- assign prev_page_dir = page.dir -%}
+ {%- assign prev_page_dir = pg.dir -%}
{%- endunless %}
- {%- unless page.name == "index.md" or page.name == "index.html" %}
- - {{ page.title }}
+ {%- unless pg.name == "index.md" or pg.name == "index.html" -%}
+ {%- if pg.directory-tree.emphasize and include.strong or page.directory-tree.strong or directory-tree-strong -%}
+ {%- assign strong = "" -%}
+ {%- assign strong_closing = "" -%}
+ {%- else -%}
+ {%- assign strong = "" -%}
+ {%- assign strong_closing = "" -%}
+ {%- endif -%}
+ {%- if pg.directory-tree.de-emphasize and include.del or page.directory-tree.del or directory-tree-del -%}
+ {%- assign del = "" -%}
+ {%- assign del_closing = "" -%}
+ {%- else -%}
+ {%- assign del = "" -%}
+ {%- assign del_closing = "" -%}
+ {%- endif %}
+ - {{ strong }}{{ del }}{{ pg.title }}{{ del_closing }}{{ strong_closing }}
{%- endunless -%}
{% endfor -%}
- {%- for dir in path %}
+ {%- assign offset = include.dir | split: "/" | size -%}
+ {%- assign last_char = include.dir | slice: -1 -%}
+ {%- unless last_char == "/" -%}
+ {%- assign offset = offset | minus: 1 -%}
+ {%- endunless -%}
+ {%- for dir in path offset: offset %}
{%- endfor %}
-
+{% unless include.li or page.directory-tree.li or directory-tree-li -%}
{%- endunless -%}
diff --git a/_layouts/doc.html b/_layouts/doc.html
index 8153750d2..97c3cad3d 100644
--- a/_layouts/doc.html
+++ b/_layouts/doc.html
@@ -1,6 +1,11 @@
{% include top.html %}
+{%- assign directory-tree-li = true -%}
+{%- assign directory-tree-strong = true -%}
+{%- assign directory-tree-del = true -%}
+{%- assign directory-tree-dir_class = "r-docs-subnav list-group-item" %}
+