Skip to content

Commit

Permalink
Merge pull request etcd-io#182 from chalin/chalin-docs-pg-vers-links-…
Browse files Browse the repository at this point in the history
…2021-04-01

Template cleanup: avoid generating excessive whitespace
  • Loading branch information
nate-double-u authored Apr 1, 2021
2 parents 9f8cd0f + 1e3e3fe commit 153a19a
Show file tree
Hide file tree
Showing 10 changed files with 238 additions and 268 deletions.
20 changes: 10 additions & 10 deletions layouts/_default/baseof.en.html
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
{{ $langCode := .Site.LanguageCode }}
{{ $isBlog := eq .Section "blog" }}
{{ $langCode := .Site.LanguageCode -}}
{{ $isBlog := eq .Section "blog" -}}
<!DOCTYPE html>
<html lang="{{ $langCode }}">
<head>
{{ partial "google-analytics.html" . }}
{{ partial "meta.html" . }}
{{ partial "google-analytics.html" . -}}
{{ partial "meta.html" . -}}
<title>
{{ block "title" . }}{{ .Site.Title }}{{ end }}
{{- block "title" . }}{{ .Site.Title }}{{ end -}}
</title>
{{ partial "favicon.html" . }}
{{ partial "css.html" . }}
{{ partial "favicon.html" . -}}
{{ partial "css.html" . -}}
</head>
<body class="page{{ if $isBlog }} has-navbar-fixed-top{{ end }}">
{{ block "main" . }}
{{ end }}
{{ block "main" . -}}
{{ end -}}

{{ partial "javascript.html" . }}
{{ partial "javascript.html" . -}}
</body>
</html>
86 changes: 39 additions & 47 deletions layouts/docs/section.en.html
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{{ define "title" }}
etcd | {{ .Title }}
{{ define "title" -}}
etcd | {{ .Title -}}
{{ end }}

{{ define "main" }}
{{ partial "docs/navbar.html" . }}
{{ $version := index (split .RelPermalink "/") 2 }}
{{ $isVersionMainPage := eq .RelPermalink (printf "/docs/%s/" $version) }}
{{ define "main" -}}
{{ partial "docs/navbar.html" . -}}
{{ $version := index (split .RelPermalink "/") 2 -}}
{{ $isVersionMainPage := eq .RelPermalink (printf "/docs/%s/" $version) -}}
<div class="dashboard">
{{ partial "docs/nav-panel.html" . }}

Expand All @@ -18,51 +18,43 @@

<section class="section">
<div class="content docs-content">
{{ with .Content }}
{{ . }}

<hr />
{{ end }}
{{ with .Content -}}
{{ . -}}
<hr />
{{ end -}}


{{ if and $isVersionMainPage .Sections }}
<h4>
Documentation sections
</h4>

<ul>
{{ range .Sections }}
<li>
<a href="{{ .RelPermalink }}">
{{ .Title }}
</a><br />
{{ .Description }}
</li>
{{ end }}
</ul>
{{ else if $version }}
<h4>
Docs in this section
</h4>

<ul>
{{ range .Pages }}
{{ if .Title }}
<li>
<a href="{{ .RelPermalink }}">
{{ .Title }}
</a><br />
{{ .Description }}
</li>
{{ end }}
{{ end }}
</ul>
{{ end }}
<h4>Documentation sections</h4>

<ul>
{{ range .Sections }}
<li>
<a href="{{ .RelPermalink }}">
{{- .Title -}}
</a><br />
{{- .Description -}}
</li>
{{ end -}}
</ul>
{{ else if $version -}}
<h4>Docs in this section</h4>
<ul>
{{ range .Pages }}
{{ if .Title -}}
<li>
<a href="{{ .RelPermalink }}">
{{- .Title -}}
</a><br />
{{- .Description -}}
</li>
{{ end -}}
{{ end -}}
</ul>
{{ end -}}
</div>
</section>


{{ partial "footer.html" . }}
{{ partial "footer.html" . -}}
</div>
</div>
{{ end }}
{{ end -}}
23 changes: 9 additions & 14 deletions layouts/docs/single.en.html
Original file line number Diff line number Diff line change
@@ -1,22 +1,17 @@
{{ define "title" }}
etcd docs | {{ .Title }}
{{ define "title" -}}
etcd docs | {{ .Title -}}
{{ end }}

{{ define "main" }}
{{ define "main" -}}
{{ partial "docs/navbar.html" . }}
<div class="dashboard">
{{ partial "docs/nav-panel.html" . }}

<div class="dashboard-main is-scrollable">
{{ partial "docs/hero.html" . }}

{{ partial "deprecation-warning.html" . }}

{{ partial "docs/article.html" . }}

{{ partial "footer.html" . }}
{{ partial "docs/hero.html" . -}}
{{ partial "deprecation-warning.html" . -}}
{{ partial "docs/article.html" . -}}
{{ partial "footer.html" . -}}
</div>

{{ partial "docs/toc.html" . }}
{{ partial "docs/toc.html" . -}}
</div>
{{ end }}
{{ end -}}
8 changes: 4 additions & 4 deletions layouts/partials/docs/dashboard.html
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@

<div class="dashboard">
{{ partial "docs/nav-panel.html" . }}
{{ partial "docs/nav-panel.html" . -}}

<div class="dashboard-main">
{{ partial "docs/hero.html" . }}
{{ partial "docs/article.html" . }}
{{ partial "docs/hero.html" . -}}
{{ partial "docs/article.html" . -}}
</div>

{{ partial "docs/toc.html" . }}
{{ partial "docs/toc.html" . -}}
</div>
135 changes: 63 additions & 72 deletions layouts/partials/docs/hero.html
Original file line number Diff line number Diff line change
@@ -1,95 +1,86 @@
{{ $version := index (split .File.Path "/") 1 }}
{{ $latest := printf "%s" site.Params.versions.latest }}
{{ $allVersions := site.Params.versions.all }}
{{ $versions := (slice) }}
{{ $here := .RelPermalink }}
{{ $path := .File.Path }}
{{ range $allVersions }}
{{ $v := printf "v%s" . }}
{{ $fileToCheck := replace $path $version $v }}
{{ if fileExists $fileToCheck }}
{{ $versions = $versions | append . }}
{{ end }}
{{ end }}
{{ $version := index (split .File.Path "/") 1 -}}
{{ $latest := printf "%s" site.Params.versions.latest -}}
{{ $allVersions := site.Params.versions.all -}}
{{ $versions := (slice) -}}
{{ $here := .RelPermalink -}}
{{ $path := .File.Path -}}

{{ range $allVersions -}}
{{ $v := printf "v%s" . -}}
{{ $fileToCheck := replace $path $version $v -}}
{{ if fileExists $fileToCheck -}}
{{ $versions = $versions | append . -}}
{{ end -}}
{{ end -}}

<section class="hero">
<div class="hero-body">
<p class="title is-size-1 is-size-2-mobile has-text-weight-light{{ if .Params.description }} is-spaced{{ end }}">
{{ .Title }}
</p>
{{ with .Params.description }}
<p class="subtitle is-size-4 is-size-5-mobile">
{{ . | markdownify }}
{{- .Title -}}
</p>
{{ with .Params.description -}}
<p class="subtitle is-size-4 is-size-5-mobile">
{{- . | markdownify -}}
</p>
{{ end }}

<nav class="level">
<div class="level-left">
<div class="level-item">
<p class="is-size-4 is-size-5-mobile">
Versions of this doc:
</p>
<p class="is-size-4 is-size-5-mobile">Versions of this doc:</p>
</div>

{{ $current_file := .File }}
{{ $current_file := .File -}}

{{ $original_version := printf "/%s/" .CurrentSection.Params.version }}
{{ $latest_url := replace .Params.url .CurrentSection.Params.version .Site.Params.latest | relURL }}
{{ $original_version := printf "/%s/" .CurrentSection.Params.version -}}
{{ $latest_url := replace .Params.url .CurrentSection.Params.version .Site.Params.latest | relURL -}}

<div class="level-item">
<div class="buttons">
{{ range .Site.Params.versions.all }}

{{ $new_version := printf "/%s/" . }}
{{ $target_file := replace $current_file $original_version $new_version }}
{{ $isLatest := eq $latest . }}
{{ $new_version := printf "/%s/" . -}}
{{ $target_file := replace $current_file $original_version $new_version -}}
{{ $isLatest := eq $latest . -}}

{{/* check if the file we are linking to in the other version exists */}}
{{ if (fileExists $target_file) -}}
<a class="button is-primary is-outlined has-text-weight-bold"
href="{{ replace $here $original_version $new_version | relURL }}">
<span>
{{ . }}
</span>
{{ if $isLatest }}
&nbsp;&nbsp;
<span class="tag is-small is-success">
latest
</span>
{{ end }}
</a>
{{ else }}
{{/* if not, then link to the top level of that version instead */}}
{{ if eq "/next/" $new_version }}
<a class="button is-primary is-outlined has-text-weight-bold"
href="{{ index (findRE `^(.*?)\/next\/` (replace $here $original_version $new_version | relURL)) 0 }}">
<span>
{{ . }}
</span>
{{ if $isLatest }}
&nbsp;&nbsp;
<span class="tag is-small is-success">
latest
</span>
{{ end }}
</a>
{{ else }}
<a class="button is-primary is-outlined has-text-weight-bold"
href="{{ index (findRE `^(.*?)\/v\d+.\d+\/` (replace $here $original_version $new_version | relURL)) 0 }}">
<span>
{{ . }}
</span>
{{ if $isLatest }}
&nbsp;&nbsp;
<span class="tag is-small is-success">
latest
</span>
{{ end }}
</a>
{{ end }}
{{- end }}
{{/* check if the file we are linking to in the other version exists */ -}}
{{ if (fileExists $target_file) -}}
<a class="button is-primary is-outlined has-text-weight-bold"
href="{{ replace $here $original_version $new_version | relURL }}">
<span>{{ . }}</span>
{{ if $isLatest -}}
&nbsp;&nbsp;
<span class="tag is-small is-success">latest</span>
{{ end -}}
</a>
{{- else -}}
{{/* if not, then link to the top level of that version instead */ -}}
{{ if eq "/next/" $new_version -}}
<a class="button is-primary is-outlined has-text-weight-bold"
href="{{ index (findRE `^(.*?)\/next\/` (replace $here $original_version $new_version | relURL)) 0 }}">
<span>{{ . }}</span>
{{ if $isLatest -}}
&nbsp;&nbsp;
<span class="tag is-small is-success">
latest
</span>
{{ end -}}
</a>
{{- else -}}
<a class="button is-primary is-outlined has-text-weight-bold"
href="{{ index (findRE `^(.*?)\/v\d+.\d+\/` (replace $here $original_version $new_version | relURL)) 0 }}">
<span>{{ . }}</span>
{{ if $isLatest -}}
&nbsp;&nbsp;
<span class="tag is-small is-success">
latest
</span>
{{ end -}}
</a>
{{- end -}}
{{ end -}}

{{ end }}
{{ end -}}
</div>
</div>
</div>
Expand Down
Loading

0 comments on commit 153a19a

Please sign in to comment.