github.com/darmach/terratest@v0.34.8-0.20210517103231-80931f95e3ff/docs/_includes/collection_browser/navigation/_collection_toc.html (about) 1 {% capture tocWorkspace %} 2 {% comment %} 3 To build navigation: 4 == A1: Group docs by categories 5 == A2: [Loop] Go by categories... 6 == A3: ADD CATEGORY LINK TO THE NAV (It's the uppermost level of links in navigation.) 7 == A4: [Loop] Go by documents in the category... 8 == B1: ADD DOC'S TITLE TO NAV 9 == B2: [Loop] Go by headings in a doc... 10 == B3: ADD HEADING TO THE NAV 11 == A6: Final steps 12 Add ID and classes to the navigation, and `markdonify` content. 13 {% endcomment %} 14 15 {% capture my_toc %}{% endcapture %} 16 17 {% assign collection_name = include.collection_name | default: 'posts' %} 18 {% comment %} 19 ======================= A1: GROUP BY CATEGORIES ======================= 20 {% endcomment %} 21 {% assign collection_grouped = site[collection_name] | group_by: 'category' %} 22 {% assign sort_by = include.sort_by | default: 'order' %} 23 {% assign orderedList = include.ordered | default: false %} 24 {% assign minHeader = include.h_min | default: 1 %} 25 {% assign maxHeader = include.h_max | default: 6 %} 26 {% assign firstHeader = true %} 27 {% assign level = 0 %} 28 29 {% assign docHeaderIndentAmount = 1 %} 30 31 {% comment %} 32 ======================= A2: CATEGORIES LOOP ======================= 33 {% endcomment %} 34 {% for category in collection_grouped %} 35 36 {% capture col_id %}{{ collection_name | downcase | replace: ' ', '-' | replace: ':', ''}}{% endcapture %} 37 {% capture cat_id %}{{ category.name | downcase | replace: ' ', '-' | replace: ':', ''}}{% endcapture %} 38 39 {% comment %} 40 ======================= A3: BUILD CATEGORY LINK ======================= 41 The category link is defined as link to the heading on index page. 42 {% endcomment %} 43 44 {% capture category_link %}{{ site.baseurl }}/{{ collection_name }}#{{ category.name }}{% endcapture %} 45 {% capture my_toc %}{{ my_toc }} 46 - <span 47 class='nav-collapse-handler category-head collapsed' 48 id='cat-nav-id-{{ col_id }}-{{ cat_id }}' 49 data-toggle='collapse' 50 role='button' 51 aria-expanded='false' 52 aria-controls='{{ col_id }}-{{ cat_id }}'> 53 <span class='arrow-icon glyphicon glyphicon-triangle-bottom'></span> 54 </span>[{{ category.name | replace: '-',' ' | replace: '%20', ' ' | capitalize }}]({{ category_link }}){% endcapture %} 55 56 57 {% comment %} 58 ======================= A4: DOCS LOOP ======================= 59 Loop over the docs within a category. 60 {% endcomment %} 61 {% assign items = category.items | sort: sort_by %} 62 {% for doc in items %} 63 64 {% capture n_cont %}{{ doc.content }}{% endcapture %} 65 {% assign n_cont_md = n_cont | markdownify %} 66 67 {% comment %} 68 ======================= B1: ADD DOC TITLE TO NAV ======================= 69 Add document's title to the navigation. 70 {% endcomment %} 71 {% capture doc_id %}{{ doc.title | downcase | downcase | replace: ' ', '-' | replace: ':', ''}}{% endcapture %} 72 {% assign doc_url = doc.url %} 73 {% if doc.redirect_to %} 74 {% assign doc_url = doc.redirect_to.first %} 75 {% endif %} 76 {% capture doc_url_prefix %}{{ doc_url | slice: 0, 4 }}{% endcapture %} 77 {% unless doc_url_prefix == "http" %} 78 {% capture doc_url %}{{ site.baseurl }}{{ doc_url }}{% endcapture %} 79 {% endunless %} 80 {% capture target_blank %}{% endcapture %} 81 {% if doc.target_blank %} 82 {% capture target_blank %}{:target="_blank"}{% endcapture %} 83 {% endif %} 84 {% capture my_toc %}{{ my_toc }} 85 - <span 86 class='nav-collapse-handler category-head collapsed' 87 id='cat-nav-id-{{ doc_id }}-{{ cat_id }}' 88 data-toggle='collapse' 89 role='button' 90 aria-expanded='false' 91 aria-controls='{{ doc_id }}-{{ cat_id }}'> 92 <span class='arrow-icon glyphicon glyphicon-triangle-bottom'></span> 93 </span>[{{ doc.title }}]({{ doc_url }}){{ target_blank }}{% endcapture %} 94 95 {% comment %} 96 =============== B2: Find headings in doc and add to nav ================ 97 Goes heading by heading (h2, h3, h4, etc.), and adds it to the navigation. 98 {% endcomment %} 99 {% assign nodes = n_cont_md | split: '<h' %} 100 {% for node in nodes %} 101 102 {% if node == "" %} 103 {% continue %} 104 {% endif %} 105 106 {% assign headerLevel = node | replace: '"', '' | slice: 0, 1 | times: 1 %} 107 108 {% if headerLevel < minHeader or headerLevel > maxHeader %} 109 {% continue %} 110 {% endif %} 111 112 {% if firstHeader %} 113 {% assign firstHeader = false %} 114 {% assign minHeader = headerLevel %} 115 {% endif %} 116 117 {% assign indentAmount = headerLevel | minus: minHeader | plus: docHeaderIndentAmount %} 118 {% assign _workspace = node | split: '</h' %} 119 120 {% assign _idWorkspace = _workspace[0] | split: 'id="' %} 121 {% assign _idWorkspace = _idWorkspace[1] | split: '"' %} 122 {% assign html_id = _idWorkspace[0] %} 123 124 {% assign _classWorkspace = _workspace[0] | split: 'class="' %} 125 {% assign _classWorkspace = _classWorkspace[1] | split: '"' %} 126 {% assign html_class = _classWorkspace[0] %} 127 128 {% if html_class contains "no_toc" %} 129 {% continue %} 130 {% endif %} 131 132 {% capture _hAttrToStrip %}{{ _workspace[0] | split: '>' | first }}>{% endcapture %} 133 {% assign header = _workspace[0] | replace: _hAttrToStrip, '' %} 134 135 {% assign space = '' %} 136 {% for i in (1..indentAmount) %} 137 {% assign space = space | prepend: ' ' %} 138 {% endfor %} 139 140 {% unless include.item_class == blank %} 141 {% capture listItemClass %}{{ include.item_class | replace: '%level%', headerLevel }}{% endcapture %} 142 {% endunless %} 143 144 {% capture heading_body %}{% if include.sanitize %}{{ header | strip_html }}{% else %}{{ header }}{% endif %}{% endcapture %} 145 146 {% comment %} 147 ======================= B3: ADD HEADING TO THE NAV ======================= 148 Go heading-by-heading (h2, h3, h4, etc.), and add it to the navigation. 149 {% endcomment %} 150 {% capture my_toc %}{{ my_toc }} 151 {{ space }}- <span 152 class='nav-collapse-handler category-head collapsed' 153 id='cat-nav-id-{{ doc_id }}-{{ cat_id }}-{{ increment level }}' 154 data-toggle='collapse' 155 role='button' 156 aria-expanded='false' 157 aria-controls='{{ doc_id }}-{{ cat_id }}-{{ increment level }}'> 158 <span class='arrow-icon glyphicon glyphicon-triangle-bottom'></span> 159 </span>[{{ heading_body | replace: "|", "\|" }}]({% if include.baseurl %}{{ include.baseurl }}{% endif %}{{ site.baseurl }}{{doc.url}}#{{ html_id }}){% if include.anchor_class %}{:.{{ include.anchor_class }}}{% endif %}{% endcapture %} 160 161 {% endfor %} 162 163 164 {% endfor %} 165 166 {% endfor %} 167 168 169 {% comment %} 170 ======================= A6: FINAL STEPS ======================= 171 {% endcomment %} 172 173 {% if include.class %} 174 {% capture my_toc %}{:.{{ include.class }}} 175 {{ my_toc | lstrip }}{% endcapture %} 176 {% endif %} 177 {% if include.id %} 178 {% capture my_toc %}{: #{{ include.id }}} 179 {{ my_toc | lstrip }}{% endcapture %} 180 {% endif %} 181 182 {% endcapture %} 183 {% assign tocWorkspace = '' %} 184 185 {{ my_toc | markdownify | strip }}