Skip to content

Commit feb9782

Browse files
authored
[docs] Refactored the sidebar and breadcrumbs partials (#1)
- Refactored the sidebar and breadcrumbs partials. - Added search input the base layout - Minor style adjustments. Signed-off-by: Denis.Rebenok <denis.rebenok@flant.ru>
1 parent 7050ae7 commit feb9782

File tree

4 files changed

+74
-168
lines changed

4 files changed

+74
-168
lines changed

layouts/_partials/breadcrumbs.html

Lines changed: 21 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,21 @@
1-
{{- $channelsInfo := .Site.Data.channels.info }}
2-
{{- $moduleTitle := "" }}
3-
4-
{{- $_pathElements := index ( findRESubmatch `^modules/([a-zA-Z0-9-]+)/([a-zA-Z0-9-]+)/*$` .File.Dir 1 ) 0 }}
5-
{{- $currentModuleName := index $_pathElements 1 }}
6-
{{- $currentModuleChannel := index $_pathElements 2 }}
7-
8-
9-
{{- range sort $channelsInfo "stability" "desc" }}
10-
{{- $code := .code }}
11-
{{- if eq $code "rock-solid" }}{{ continue }}{{ end }}
12-
{{- with $.GetPage ( printf "modules/%s/%s/README.md" $currentModuleName $code ) }}
13-
{{- if and .Params.menuTitle (not $moduleTitle ) }}{{ $moduleTitle = .Params.menuTitle }}{{ end }}
14-
{{- end}}
15-
{{- end}}
16-
{{- if not $moduleTitle }}{{ $moduleTitle = $currentModuleName }}{{ end }}
17-
18-
{{- if $moduleTitle }}
19-
<li class="breadcrumbs__item">{{ $moduleTitle }}</li>
20-
{{- end }}
21-
<li class="breadcrumbs__item">
22-
{{- if in .Site.Data.helpers.knownPageNames .File.TranslationBaseName }}
23-
{{- T (printf "moduleLinkTitle%s" .File.TranslationBaseName) }}
24-
{{- else if .LinkTitle }}
25-
{{- .LinkTitle }}
26-
{{- else if .Title }}
27-
{{- .Title }}
28-
{{- end -}}
29-
</li>
1+
{{- if .Ancestors -}}
2+
{{- $ancestors := .Ancestors.Reverse -}}
3+
{{- /* Check that this is not a second-level page. */ -}}
4+
{{- if gt (len (after 1 $ancestors)) 0 -}}
5+
{{- /* Skip the first element (top level) in the breadcrumbs */ -}}
6+
{{- range $index, $element := after 1 $ancestors -}}
7+
<li class="breadcrumbs__item">
8+
<a href="{{ .RelPermalink }}" class="breadcrumbs__link">
9+
{{- if and (eq $index 0) -}}
10+
{{- if eq .Language.Lang "ru" -}}Документация{{- else -}}Documentation{{- end -}}
11+
{{- else -}}
12+
{{- .LinkTitle -}}
13+
{{- end -}}
14+
</a>
15+
</li>
16+
{{- end }}
17+
<li class="breadcrumbs__item breadcrumbs__item--current">
18+
<span class="breadcrumbs__current">{{ .LinkTitle }}</span>
19+
</li>
20+
{{- end -}}
21+
{{- end -}}

layouts/_partials/sidebar.html

Lines changed: 44 additions & 137 deletions
Original file line numberDiff line numberDiff line change
@@ -1,145 +1,52 @@
1-
{{- $modulesList := .Site.Data.modules.channels }}
2-
{{- $channelsInfo := .Site.Data.channels.info }}
3-
{{- $lang := .Site.Language.Lang }}
4-
{{- $sidebarRootMenu := slice }}
5-
{{- $pages := (where $.Site.RegularPages ".Section" "modules").ByWeight }}
6-
{{- $ctx := $ }}
1+
{{- $currentPage := . -}}
72

8-
{{- $_pathElements := index ( findRESubmatch `^modules/([a-zA-Z0-9-]+)/([a-zA-Z0-9-]+)/*$` .File.Dir 1 ) 0 }}
9-
{{- $currentModuleName := index $_pathElements 1 }}
10-
{{- $currentModuleChannel := index $_pathElements 2 }}
11-
12-
{{- range $module, $data := $modulesList }}
13-
{{- $moduleTitle := "" }}
14-
{{- $moduleChannel := "" }}
15-
{{- $isActiveItem := false }}
16-
{{- $moduleStatus := "" }}
17-
18-
{{- if eq $currentModuleName $module }}
19-
{{- $moduleChannel = $currentModuleChannel }}
20-
{{- $isActiveItem = true }}
21-
{{- end }}
22-
23-
{{- range sort $channelsInfo "stability" "desc" }}
24-
{{- $code := .code }}
25-
{{- if eq $code "rock-solid" }}{{ continue }}{{ end }}
26-
{{- with $.GetPage ( printf "modules/%s/%s/README.md" $module $code ) }}
27-
{{- if and .Params.menuTitle (not $moduleTitle ) }}{{ $moduleTitle = .Params.menuTitle }}{{ end }}
28-
{{- if and .Params.moduleStatus ( not $moduleStatus ) }}{{ $moduleStatus = .Params.moduleStatus }}{{ end }}
29-
{{- if not $moduleChannel }}{{ $moduleChannel = $code }}{{ end }}
30-
{{- end }}
31-
{{- end }}
32-
{{- if not $moduleTitle }}{{ $moduleTitle = $module }}{{ end }}
33-
{{- if $moduleChannel }}
34-
{{- $sidebarRootMenu = $sidebarRootMenu | append (dict "module" $module "title" $moduleTitle "channel" $moduleChannel "isActive" $isActiveItem "moduleStatus" $moduleStatus) }}
35-
{{- end }}
36-
{{- end}}
37-
38-
{{- $sidebarRootMenu = sort $sidebarRootMenu "title" "asc" }}
39-
40-
<div style="display: flex; justify-content: start; padding-top: 12px; padding-bottom: 35px; gap: 25px;">
41-
<div class="channel-menu submenu-parent">
42-
{{- partial "documentation-section-badge" }}
43-
</div>
44-
45-
<div id="doc-versions-menu" class="channel-menu submenu-parent">
46-
{{- if $.IsPage }}
47-
{{- if and $currentModuleName $currentModuleChannel }}
48-
{{- partial "module-version-badge" (dict "ctx" $ "module" $currentModuleName "channel" $currentModuleChannel ) }}
49-
{{- end }}
50-
{{- end }}
51-
</div>
52-
53-
</div>
54-
55-
<div class="sidebar__wrapper-inner">
3+
<div class="sidebar__wrapper-inner">
564
<nav class="sidebar__container">
57-
58-
<ul class="sidebar" id="mysidebar">
59-
60-
{{- $overviewItem := $.GetPage "modules/" }}
61-
62-
<li class="sidebar__item {{ if eq $overviewItem $.Page }}active{{ end }}">
63-
<a href='{{ relURL "" }}modules/'>{{ $overviewItem.LinkTitle }}</a>
64-
</li>
65-
66-
{{- range $sidebarItem := $sidebarRootMenu }}
67-
<li class="sidebar__item sidebar__item_parent{{ if $sidebarItem.isActive }} active{{ end }}">
68-
<a href='#'>
69-
<span class='sidebar__submenu-title'>
70-
{{- $sidebarItem.title -}}
71-
</span>
72-
73-
<span class="sidebar__badge--container">
74-
{{- if and (gt (len $sidebarItem.module) 0) (index $.Site.Data.modules_all $sidebarItem.module) }}
75-
{{- $moduleEditions := index (index $.Site.Data.modules_all $sidebarItem.module) "editions" }}
76-
{{- $moduleCommercialBadgeMessage := index (index $.Site.Data.modules_all $sidebarItem.module) "commercialBadgeMessage" $lang}}
77-
{{- if $moduleCommercialBadgeMessage }}
78-
<span class="sidebar__badge_v2 sidebar__badge_commercial" title='{{ $moduleCommercialBadgeMessage }}'>{{ T "currency_sign" }}</span>
79-
{{- else if not (in $moduleEditions "ce") }}
80-
<span class="sidebar__badge_v2 sidebar__badge_commercial" title='{{ T "commercial" }}'>{{ T "currency_sign" }}</span>
81-
{{- end }}
82-
{{- end }}
83-
{{- if and (replace (lower $sidebarItem.moduleStatus) " " "_") (index $.Site.Data.helpers.moduleStageBageMap (replace (lower $sidebarItem.moduleStatus) " " "_")) -}}
84-
<span class='sidebar__badge_v2'
85-
{{- if (T (printf "module_alert_%s_long" (replace (lower $sidebarItem.moduleStatus ) " " "_") )) }}
86-
title='{{ (T (printf "module_alert_%s_long" (replace (lower $sidebarItem.moduleStatus) " " "_") )) }}'
87-
{{ end -}}
88-
>{{ index $.Site.Data.helpers.moduleStageBageMap (replace (lower $sidebarItem.moduleStatus) " " "_") -}}
89-
</span>
5+
<ul class="sidebar" id="mysidebar">
6+
{{/* Get all sections on the first level */}}
7+
{{ range .Site.Sections }}
8+
<li class="sidebar__item {{ if or (eq . $currentPage) (.IsAncestor $currentPage) }}active{{ end }}{{ if .Pages }} has-children{{ end }}">
9+
<a href="{{ .RelPermalink }}" {{ if and (.IsAncestor $currentPage) (not (eq . $currentPage)) }}style="color: #00122c;"{{ end }}>{{ .Title }}</a>
10+
{{- if .Pages }}
11+
{{- template "subpages" (dict "parent" . "currentPage" $currentPage "level" 1) }}
9012
{{- end }}
91-
</span>
92-
</a>
93-
{{- template "subpages" (dict "parent" $sidebarItem "pages" $pages "ctx" $ctx) }}
94-
</li>
95-
{{- end }}
96-
</ul>
13+
</li>
14+
{{ end }}
15+
</ul>
9716
</nav>
98-
</div>
17+
</div>
9918

10019
{{/* --- subpages --- */}}
10120
{{- define "subpages" }}
102-
103-
{{- $sidebarItem := .parent }}
104-
{{- $pages := .pages }}
105-
{{- $ctx := .ctx }}
106-
107-
<ul class="sidebar__submenu">
108-
109-
{{- with $ctx.GetPage ( printf "modules/%s/%s/README.md" $sidebarItem.module $sidebarItem.channel ) }}
110-
<li class="sidebar__submenu-item {{ if or ($ctx.Page.IsAncestor .) (eq $ctx.Page .) }}active{{ end }}">
111-
<a href="{{ replaceRE "/readme.html$" "/" .RelPermalink }}">
112-
{{- if in .Site.Data.helpers.knownPageNames .File.TranslationBaseName }}
113-
{{- T (printf "moduleLinkTitle%s" .File.TranslationBaseName) }}
114-
{{- else if .LinkTitle }}
115-
{{- .LinkTitle }}
116-
{{- else if .Title }}
117-
{{- .Title }}
118-
{{- end }}
119-
</a>
120-
</li>
121-
{{- end }}
122-
123-
{{- range $pages }}
124-
{{- $_pathElements := index ( findRESubmatch `^modules/([a-zA-Z0-9-]+)/([a-zA-Z0-9-]+)/*$` .File.Dir 1 ) 0 }}
125-
{{- $moduleName := index $_pathElements 1 }}
126-
{{- $moduleChannel := index $_pathElements 2 }}
127-
{{- if or ( ne $moduleName $sidebarItem.module ) ( ne $moduleChannel $sidebarItem.channel ) ( eq .File.TranslationBaseName "README" ) }}{{ continue }}{{ end }}
128-
{{- $pageTitle := "" }}
129-
{{- if in .Site.Data.helpers.knownPageNames .File.TranslationBaseName }}
130-
{{- $pageTitle = T (printf "moduleLinkTitle%s" .File.TranslationBaseName) }}
131-
{{- else if .LinkTitle }}
132-
{{- $pageTitle = strings.TrimSpace .LinkTitle }}
133-
{{- else if .Title }}
134-
{{- $pageTitle = strings.TrimSpace .Title }}
135-
{{- end }}
136-
{{- if not $pageTitle }}{{ continue }}{{ end }}
137-
<li class="sidebar__submenu-item {{ if or (.IsAncestor page) (eq . page) }}active{{ end }}">
138-
<a href="{{ if .IsPage }}{{ replaceRE "/readme.html$" "/" .RelPermalink }}{{ else }}#{{ end }}">
139-
{{- $pageTitle -}}
140-
</a>
141-
</li>
142-
{{- end }}
143-
</ul>
21+
{{- $parent := .parent }}
22+
{{- $currentPage := .currentPage }}
23+
{{- $level := .level }}
24+
{{- $maxLevel := 6 }}
25+
26+
{{- if and $parent.Pages (lt $level $maxLevel) }}
27+
<ul class="sidebar__submenu level-{{ $level }}" {{ if eq $level 1 }}style="padding: 0 0 0 0;"{{ end }}>
28+
{{- range $parent.Pages.ByWeight }}
29+
{{- if not .Params.hidden }}
30+
<li class="sidebar__submenu-item {{ if or (eq . $currentPage) (.IsAncestor $currentPage) }}active{{ end }}{{ if .Pages }} sidebar__submenu-item_parent has-children{{ end }}">
31+
<a href="{{ .RelPermalink }}">
32+
<span class="sidebar__submenu-title" {{ if eq $level 1 }}style="font-size: 16px;"{{ end }}>
33+
{{- if .Title }}
34+
{{- .Title }}
35+
{{- else if .LinkTitle }}
36+
{{- .LinkTitle }}
37+
{{- else }}
38+
{{- .File.BaseFileName | humanize }}
39+
{{- end }}
40+
</span>
41+
</a>
42+
43+
{{/* Recursive function call for subpages */}}
44+
{{- if .Pages }}
45+
{{- template "subpages" (dict "parent" . "currentPage" $currentPage "level" (add $level 1)) }}
46+
{{- end }}
47+
</li>
48+
{{- end }}
49+
{{- end }}
50+
</ul>
14451
{{- end }}
145-
{{/* END --- subpages --- */}}
52+
{{- end }}

layouts/baseof.html

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,14 @@
2222
{{- partial "breadcrumbs" . }}
2323
</ol>
2424
</div>
25+
<div class="searchV3">
26+
<div class="container">
27+
<div class="input-wrapper">
28+
<input type="text" id="search-input" placeholder="Search..." class="input" data-search-index-path="" data-search-context="">
29+
<div id="search-results" class="results" style="display: none"></div>
30+
</div>
31+
</div>
32+
</div>
2533
</div>
2634

2735
<div class="layout-sidebar">

layouts/list.html

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,10 @@
99
<h1>Kind - {{.Kind}}</h1>
1010
{{.Content}}
1111
{{- range .Pages }}
12-
<div style="border: 1px solid black; margin:10px; padding:10px; ">
12+
<div style="border: 1px solid rgb(0, 0, 0); margin:10px; padding:10px; ">
1313
<div style="font-size:20px;">
1414
<a href="{{ .RelPermalink }}">{{.Title}}</a>
1515
</div>
16-
<div style="color:grey; font-size:16px;">{{ dateFormat "Monday, Jan 2, 2006" .Date }}</div>
1716
<div style="color:grey; font-size:16px;">{{ if .Params.tags }}<strong>Tags:</strong> {{range .Params.tags}}<a href="{{ "/tags/" | relLangURL }}{{ . | urlize }}">{{ . }}</a> {{end}}{{end}}</div>
1817
<div style="color:grey; font-size:16px;">{{ if .Params.categories }}<strong>Categories:</strong> {{range .Params.categories}}<a href="{{ "/categories/" | relLangURL }}{{ . | urlize }}">{{ . }}</a> {{end}}{{end}}</div>
1918
<div style="color:grey; font-size:16px;">{{ if .Params.moods }}<strong>Moods:</strong> {{range .Params.moods}}<a href="{{ "/moods/" | relLangURL }}{{ . | urlize }}">{{ . }}</a> {{end}}{{end}}</div>

0 commit comments

Comments
 (0)