Skip to content

Commit acefe72

Browse files
feat: implement documentation versioning and update header for versio… (#487)
<!-- markdownlint-disable MD041 --> #### What this PR does / why we need it The PR introduces a version toggle on the website. It is using a versions.json in the data/ folder that contains all available versions. New versions of the website need to be cut off from the main branch and afterwards built using the baseURL + the new version and merge this into the public/ folder. This holds all versions in parallel, accessible by introducing a v2 in the URL, since Gh pages are not able to use multiple branches. ``` hugo build --baseURL https://ocm.software/v2/ \ --destination ./public/v2 \ --minify --gc ``` The PR will introduce the version toggle and the version "current" which will live on the root level in the public/ folder that will be published. Related to open-component-model/ocm-project#482 Signed-off-by: Gerald Morrison (SAP) <[email protected]> Co-authored-by: Gerald Morrison (SAP) <[email protected]>
1 parent a244d82 commit acefe72

File tree

6 files changed

+69
-37
lines changed

6 files changed

+69
-37
lines changed

config/_default/hugo.toml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,7 @@ lastMod = false
8787
tag = "tags"
8888

8989
[permalinks]
90-
blog = "/blog/:slug/"
91-
docs = "/docs/:sections[1:]/:slug/"
92-
# docs = "/docs/1.0/:sections[1:]/:slug/"
90+
docs = "/docs/:sections[1:]/:title/"
9391

9492
[minify.tdewolff.html]
9593
keepWhitespace = false

config/_default/module.toml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,3 +86,13 @@
8686
[[mounts]]
8787
source = "static"
8888
target = "static"
89+
90+
## Reference Docs mounted from other repositories
91+
## Use @main to always use the latest version of the repository.
92+
## Use version tags to pin to a specific version.
93+
94+
#[[imports]]
95+
# path = "github.com/open-component-model/open-component-model@main"
96+
# [[imports.mounts]]
97+
# source = "docs/reference/cli"
98+
# target = "content/docs/reference/ocm-cli"

config/_default/params.toml

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,16 @@ mainSections = ["docs"]
5151
showMissingLanguages = true # whether or not to show untranslated languages in the language menu; true (default) or false
5252

5353
# Versioning
54-
docsVersioning = false # false (default) or true
55-
docsVersion = "1.0"
54+
# Offers toggle to maintain multiple versions of the same documentation
55+
# Parameters are used in the layouts/partials/header/header.html template
56+
#
57+
# Central versions.json containinig all parallel versions lies in data/ folder
58+
# and NEEDS to be maintained in the main branch BEFORE a new version branch is cut off to
59+
# be available in the version switcher of all versions.
60+
61+
docsVersioning = true
62+
docsVersion = "current"
63+
defaultVersion = "current"
5664

5765
# UX
5866
headerBar = true # true (default) or false

data/docs-versions.yml

Lines changed: 0 additions & 12 deletions
This file was deleted.

data/versions.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"defaultVersion": "current",
3+
"versions": [ "current" ]
4+
}

layouts/partials/header/header.html

Lines changed: 44 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ <h5 class="offcanvas-title fw-bold" id="offcanvasNavMainLabel">{{ .Site.Params.T
147147
{{ partial "main/showFlexSearch" . }}
148148
{{ $showFlexSearch := .Scratch.Get "showFlexSearch" -}}
149149
{{ if $showFlexSearch -}}
150-
<button type="button" id="searchToggleDesktop" class="btn btn-link nav-link p-2 d-none d-lg-block" aria-label="Search website">
150+
<button type="button" id="searchToggleDesktop" class="btn btn-link nav-link p-2 d-none d-lg-block order-lg-3" aria-label="Search website">
151151
<svg xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-search" width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round">
152152
<path stroke="none" d="M0 0h24v24H0z" fill="none"></path>
153153
<circle cx="10" cy="10" r="7"></circle>
@@ -207,33 +207,57 @@ <h5 class="offcanvas-title fw-bold" id="offcanvasNavMainLabel">{{ .Site.Params.T
207207
</div>
208208
{{ end -}}
209209

210-
<!-- Versioning dropdown -->
211-
{{ if eq site.Params.doks.docsVersioning true -}}
210+
<!-- Versioning dropdown -->
211+
{{ if site.Params.doks.docsVersioning }}
212+
{{/* load versions.json from data/ */}}
213+
{{ $versionsData := site.Data.versions }}
212214

213-
<div class="dropdown mt-1 order-lg-3">
214-
<button class="btn btn-dropdown dropdown-toggle" id="doks-versions" data-bs-toggle="dropdown" aria-expanded="false" data-bs-display="static" aria-label="Toggle version menu">
215-
<span class="d-none">Doks</span> v{{ site.Params.doks.docsVersion }}
215+
{{ if $versionsData.versions }}
216+
{{ $currentVer := site.Params.doks.docsVersion }}
217+
218+
<div class="dropdown mt-1 order-lg-1">
219+
<button class="btn btn-dropdown dropdown-toggle"
220+
id="doks-versions"
221+
data-bs-toggle="dropdown"
222+
aria-expanded="false"
223+
data-bs-display="static"
224+
aria-label="Toggle version menu">
225+
Versions
216226
<span class="dropdown-caret">
217-
<svg xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-chevron-down" width="24" height="24" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round">
218-
<path stroke="none" d="M0 0h24v24H0z" fill="none"></path>
219-
<path d="M6 9l6 6l6 -6"></path>
227+
<svg xmlns="http://www.w3.org/2000/svg"
228+
class="icon icon-tabler icon-tabler-chevron-down"
229+
width="24" height="24" viewBox="0 0 24 24" stroke-width="1.5"
230+
stroke="currentColor" fill="none"
231+
stroke-linecap="round" stroke-linejoin="round">
232+
<path stroke="none" d="M0 0h24v24H0z" fill="none"/>
233+
<path d="M6 9l6 6l6 -6"/>
220234
</svg>
221235
</span>
222236
</button>
223-
<ul class="dropdown-menu dropdown-menu-lg-end me-lg-2 shadow rounded border-0" aria-labelledby="doks-versions">
224-
<li><a class="dropdown-item current" aria-current="true" href="/docs/{{ site.Params.doks.docsVersion }}/prologue/introduction/">Latest ({{ site.Params.doks.docsVersion }}.x)</a></li>
225-
<li><hr class="dropdown-divider"></li>
226-
<li><a class="dropdown-item" href="/docs/0.2/prologue/introduction/">v0.2.x</a></li>
227-
<li><a class="dropdown-item" href="/docs/0.1/prologue/introduction/">v0.1.x</a></li>
228-
<li><hr class="dropdown-divider"></li>
229-
<li><a class="dropdown-item" href="/docs/versions/">All versions</a></li>
237+
238+
<ul class="dropdown-menu dropdown-menu-lg-end me-lg-2 shadow rounded border-0"
239+
aria-labelledby="doks-versions">
240+
{{ range $versionsData.versions }}
241+
{{ $isDefault := eq . $versionsData.defaultVersion }}
242+
{{ $isCurrent := eq . $currentVer }}
243+
{{ $versionPath := cond $isDefault "/" (printf "/%s/" .) }}
244+
245+
<li>
246+
<a class="dropdown-item{{ if $isCurrent }} current{{ end }}"
247+
{{ if $isCurrent }}aria-current="true"{{ end }}
248+
href="{{ $versionPath }}docs/overview/about">
249+
{{ . }}{{ if $isDefault }} (latest){{ end }}
250+
</a>
251+
</li>
252+
{{ end }}
230253
</ul>
231254
</div>
232-
{{ end -}}
255+
{{ end }}
256+
{{ end }}
233257

234258
<!-- Color mode toggler -->
235259
{{ if .Site.Params.doks.colorModeToggler }}
236-
<button id="buttonColorMode" class="btn btn-link mx-auto nav-link p-0 ms-lg-2 me-lg-1" type="button" aria-label="Toggle theme">
260+
<button id="buttonColorMode" class="btn btn-link mx-auto nav-link p-0 ms-lg-2 me-lg-1 order-lg-4" type="button" aria-label="Toggle theme">
237261
<svg data-bs-theme-value="dark" xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-moon" width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round">
238262
<path stroke="none" d="M0 0h24v24H0z" fill="none"></path>
239263
<path d="M12 3c.132 0 .263 0 .393 0a7.5 7.5 0 0 0 7.92 12.446a9 9 0 1 1 -8.313 -12.454z"></path>
@@ -278,5 +302,5 @@ <h5 class="offcanvas-title fw-bold" id="offcanvasNavMainLabel">{{ .Site.Params.T
278302

279303
<!-- Search modal -->
280304
{{ if site.Params.doks.flexSearch -}}
281-
{{ partial "header/search-modal" . }}
282-
{{ end -}}
305+
{{ partial "header/search-modal" . }}
306+
{{ end -}}

0 commit comments

Comments
 (0)