Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Version/Language dropdown menu & custom CSS/JS support #150

Open
wants to merge 4 commits into
base: release
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion assets/docs/scss/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,8 @@ $code-block-padding-top: {{ if eq .Site.Params.docs.prism true -}}0{{ else }}1.2
{{ if .Site.Params.feedback.enabled | default false -}}@import "custom/plugins/feedback/feedback";{{ end}}

// Mermaid
@import "custom/plugins/mermaid/mermaid";
@import "custom/plugins/mermaid/mermaid";

.dropdown-item {
text-align: left !important;
}
1 change: 1 addition & 0 deletions layouts/docs/baseof.html
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
</div>
{{ end -}}
<div class="docs-content col-12 {{ if .IsNode }}{{ else }}{{ if site.Params.docs.toc | default true }}{{ if and (ne .Params.toc false) (ne .TableOfContents "<nav id=\"TableOfContents\"></nav>") }}col-xl-9{{else}}{{end}}{{ else }}{{ end }}{{ end }} mt-0">
{{- partial (printf "%s/%s" ($.Scratch.Get "pathName") "version-banner.html") . }}
<div class="mb-0 d-flex">
{{ if site.Params.docs.titleIcon | default false }}
<i class="material-icons title-icon me-2">{{- .Params.icon | default "article" }}</i>
Expand Down
9 changes: 9 additions & 0 deletions layouts/partials/docs/head.html
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,15 @@
{{- $style = $style | minify | fingerprint "sha384" }}
{{- end -}}
<link rel="stylesheet" href="{{ $style.RelPermalink }}" {{ if hugo.IsProduction }}integrity="{{ $style.Data.Integrity }}"{{ end -}} crossorigin="anonymous">
{{ range .Site.Params.docCustomCss -}}
<link rel="stylesheet" href="{{ . | absURL }}"/>
{{- end }}

<!-- Custom JS -->
{{ range .Site.Params.docCustomJs -}}
<script src="{{ . | absURL }}"></script>
{{- end }}

<!-- Katex CSS -->
{{- if .Params.katex -}}
{{- $options := dict "enableSourceMap" true }}
Expand Down
13 changes: 0 additions & 13 deletions layouts/partials/docs/i18nlist.html
Original file line number Diff line number Diff line change
@@ -1,21 +1,8 @@
{{ $pageLang := .Page.Lang }}
{{ $translations := slice }}
{{ $docspath := $.Scratch.Get "pathName" }}

<!-- List available translations (excluding current page)-->
{{ range .Translations }}
<!-- Create 'available translations' slice -->
{{ $translations = $translations | append .Lang }}
<li><a class="dropdown-item" href="{{ .RelPermalink }}" role="button" rel="alternate" hreflang="{{ .Lang }}" lang="{{ .Lang }}">{{ .Language.LanguageName }}</a></li>
{{ end }}

<!-- List of configured languages without a translation for the current page (link to doc root) -->
{{ range .Site.Languages }}
{{ if ne $pageLang .Lang }}
<!-- If .Lang is in the 'available translations' slice, ignore it -->
{{ if in $translations .Lang }}
{{ else }}
<li><a class="dropdown-item" href="{{ .Lang | relURL }}/{{ $docspath }}" role="button" rel="alternate" hreflang="{{ .Lang }}" lang="{{ .Lang }}">{{ .LanguageName }}</a></li>
{{ end }}
{{ end }}
{{ end }}
11 changes: 11 additions & 0 deletions layouts/partials/docs/navbar-version.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{{ $path := .Page.RelPermalink -}}

{{ range .Site.Params.versions }}
{{ $url := $path -}}
{{ if ne .url "" -}}
{{ $url = (printf "%s/%s" (strings.TrimSuffix "/" .url) (strings.TrimPrefix "/" $path) ) -}}
{{ end -}}
{{ if not .current -}}
<li><a class="dropdown-item" href="{{ $url }}">{{ .version }}</a></li>
{{ end }}
{{ end }}
35 changes: 25 additions & 10 deletions layouts/partials/docs/top-header.html
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,31 @@
</div>

<div class="d-flex align-items-center">
{{ if .Site.IsMultiLingual }}
<div class="dropdown">
<button class="btn btn-link btn-default dropdown-toggle ps-2" type="button" data-bs-toggle="dropdown" aria-expanded="false">
{{ site.Language.LanguageName }}
</button>
<ul class="dropdown-menu text-end">
{{ partial (printf "%s/%s" ($.Scratch.Get "pathName") "i18nlist") . }}
</ul>
</div>
{{ end }}
{{ if .Site.Params.versions }}
<div class="dropdown">
<button class="btn btn-link btn-default dropdown-toggle ps-2" type="button" data-bs-toggle="dropdown" aria-expanded="false">
{{ range .Site.Params.versions }}
{{ if .current -}}
{{ .version -}}
{{ break }}
{{ end -}}
{{ end }}
</button>
<ul class="dropdown-menu text-end">
{{ partial (printf "%s/%s" ($.Scratch.Get "pathName") "navbar-version") . }}
</ul>
</div>
{{ end }}
<ul class="list-unstyled mb-0">
{{ with $.Scratch.Get "social_list" }}
{{ range . }}
Expand Down Expand Up @@ -78,16 +103,6 @@
</span>
</button>
{{ end -}}
{{ if .Site.IsMultiLingual }}
<div class="dropdown">
<button class="btn btn-link btn-default dropdown-toggle ps-2" type="button" data-bs-toggle="dropdown" aria-expanded="false">
{{ site.Language.Lang | upper }}
</button>
<ul class="dropdown-menu text-end">
{{ partial (printf "%s/%s" ($.Scratch.Get "pathName") "i18nlist") . }}
</ul>
</div>
{{ end }}
</div>
</div>
<!-- FlexSearch Input Start -->
Expand Down
37 changes: 37 additions & 0 deletions layouts/partials/docs/version-banner.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{{ $latestVersionUrl := urls.Parse $.Site.Params.Baseurl }}
{{ $currentVersion := "" }}

{{ range .Site.Params.versions }}
{{ if .current -}}
{{ $currentVersion = .version }}
{{ break }}
{{ end -}}
{{ end }}

{{ if .Site.Params.versionInfo.archived }}
<br/>
<div class="alert alert-danger d-flex" role="alert">
<div class="flex-shrink-1 alert-icon">

<span class="material-icons size-20 me-2">
report
</span></div>

<div class="w-100">
<p>Version <strong>{{ $currentVersion | markdownify }}</strong> documentation is <strong>no longer actively maintained</strong>. The version you are currently viewing is an archived snapshot. For up-to-date information, see the <a href="{{ $latestVersionUrl | safeURL }}" target="_blank"><strong>latest version</strong></a>.</p>

Check warning

Code scanning / CodeQL

Potentially unsafe external link Medium documentation

External links without noopener/noreferrer are a potential security risk.
</div>
</div>
{{ else if .Site.Params.versionInfo.unreleased }}
<br/>
<div class="alert alert-warning d-flex" role="alert">
<div class="flex-shrink-1 alert-icon">

<span class="material-icons size-20 me-2">
warning
</span></div>

<div class="w-100">
<p>Version <strong>{{ $currentVersion | markdownify }}</strong> documentation is <strong>unreleased and frequently changed</strong>. For up-to-date information, see the <a href="{{ $latestVersionUrl | safeURL }}" target="_blank"><strong>latest version</strong></a>.</p>

Check warning

Code scanning / CodeQL

Potentially unsafe external link Medium documentation

External links without noopener/noreferrer are a potential security risk.
</div>
</div>
{{ end }}
11 changes: 10 additions & 1 deletion layouts/partials/head.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
{{- $style = $style | minify | fingerprint "sha384" }}
{{- end -}}
<link rel="stylesheet" href="{{ $style.RelPermalink }}" {{ if hugo.IsProduction }}integrity="{{ $style.Data.Integrity }}"{{ end -}}/>
{{ range .Site.Params.customCss -}}
<link rel="stylesheet" href="{{ . | absURL }}"/>
{{- end }}
<!-- Bootstrap JS -->
{{ $js := resources.Get "js/bootstrap.js" }}
{{ $params := dict }}
Expand All @@ -35,7 +38,13 @@
{{ if hugo.IsProduction }}
{{ $js = $js | fingerprint "sha384" }}
{{ end }}
<script src="{{ $js.RelPermalink }}" {{ if hugo.IsProduction }}integrity="{{ $js.Data.Integrity }}"{{ end -}} defer></script>
<script src="{{ $js.RelPermalink }}" {{ if hugo.IsProduction }}integrity="{{ $js.Data.Integrity }}"{{ end -}} defer></script>

<!-- Custom JS -->
{{ range .Site.Params.customJs -}}
<script src="{{ . | absURL }}"></script>
{{- end }}

<!-- Image Compare Viewer -->
{{ if ($.Scratch.Get "image_compare_enabled") }}
{{ $imagecompare := resources.Get "js/image-compare-viewer.min.js" }}
Expand Down