diff --git a/docs/build.sh b/docs/build.sh new file mode 100755 index 00000000000..15234cdc213 --- /dev/null +++ b/docs/build.sh @@ -0,0 +1,56 @@ +#!/bin/bash +# +# This was adapted from https://github.com/dgraph-io/dgraph/blob/master/wiki/scripts/build.sh +# + +set -e + +GREEN='\033[32;1m' +RESET='\033[0m' +HOST=https://gqlgen.com + +VERSIONS_ARRAY=( + 'v0.10.2' + 'master' + 'v0.9.3' + 'v0.8.3' + 'v0.7.2' + 'v0.6.0' + 'v0.5.1' + 'v0.4.4' +) + +joinVersions() { + versions=$(printf ",%s" "${VERSIONS_ARRAY[@]}") + echo "${versions:1}" +} + +function version { echo "$@" | gawk -F. '{ printf("%03d%03d%03d\n", $1,$2,$3); }'; } + +rebuild() { + echo -e "$(date) $GREEN Updating docs for branch: $1.$RESET" + + + VERSION_STRING=$(joinVersions) + export CURRENT_VERSION=${1} + export VERSIONS=${VERSION_STRING} + + hugo --quiet --destination="public/$CURRENT_VERSION" --baseURL="$HOST/$CURRENT_VERSION" + + if [[ $1 == "${VERSIONS_ARRAY[0]}" ]]; then + hugo --quiet --destination=public/ --baseURL="$HOST/" + fi +} + + +currentBranch=$(git rev-parse --abbrev-ref HEAD) + +git fetch origin + +for version in "${VERSIONS_ARRAY[@]}" ; do + git checkout $branch + rebuild "$version" +done + +git checkout -q "$currentBranch" + diff --git a/docs/layouts/_default/baseof.html b/docs/layouts/_default/baseof.html index 70eea20aba6..9a504891013 100644 --- a/docs/layouts/_default/baseof.html +++ b/docs/layouts/_default/baseof.html @@ -27,6 +27,7 @@ + {{ partial "version-switcher" . }} {{ partial "sidebar" . }} {{ block "main" . }}{{ end }} - \ No newline at end of file + diff --git a/docs/layouts/_default/single.html b/docs/layouts/_default/single.html index ccaa378b030..5c1439560e2 100644 --- a/docs/layouts/_default/single.html +++ b/docs/layouts/_default/single.html @@ -13,6 +13,7 @@

{{ .LinkTitle }}

+ {{partial "version-banner"}} {{ .Content }}
diff --git a/docs/layouts/index.html b/docs/layouts/index.html index f3e8fa58eb2..c8f0b7bbcb4 100644 --- a/docs/layouts/index.html +++ b/docs/layouts/index.html @@ -10,6 +10,7 @@

{{ .LinkTitle }}

+ {{partial "version-banner"}} {{ .Content }} {{.Scratch.Set "intro" (readFile "content/_introduction.md")}} {{.Scratch.Set "intro" (split (.Scratch.Get "intro") "\n")}} diff --git a/docs/layouts/partials/version-banner.html b/docs/layouts/partials/version-banner.html new file mode 100644 index 00000000000..3c4f2416012 --- /dev/null +++ b/docs/layouts/partials/version-banner.html @@ -0,0 +1,14 @@ +{{ $currentVersion := getenv "CURRENT_VERSION" }} +{{ $versionString := getenv "VERSIONS" }} +{{ $versions := split $versionString "," }} +{{ $latestVersion := index $versions 0 }} + +{{ if (eq $currentVersion "master") }} +
+ You are looking at the docs for the unreleased master branch. The latest version is {{ $latestVersion }}. +
+{{ else if not (eq $latestVersion $currentVersion) }} +
+ You are looking at the docs for an older version ({{ $currentVersion }}). The latest version is {{ $latestVersion }}. +
+{{ end }} diff --git a/docs/layouts/partials/version-switcher.html b/docs/layouts/partials/version-switcher.html new file mode 100644 index 00000000000..5e4ddf5982b --- /dev/null +++ b/docs/layouts/partials/version-switcher.html @@ -0,0 +1,15 @@ +{{ $VersionString := getenv "VERSIONS" }} +{{ $Versions := split $VersionString "," }} +{{ $currentVersion := getenv "CURRENT_VERSION" }} + +
+ {{ $currentVersion }} +
+ {{$currentVersion}} + {{ range $i, $version := $Versions }} + {{ if not (eq $currentVersion $version) }} + {{$version}} + {{ end }} + {{ end }} +
+
diff --git a/docs/static/main.css b/docs/static/main.css index 4a13c4e8954..7bf7f5c4943 100644 --- a/docs/static/main.css +++ b/docs/static/main.css @@ -451,3 +451,69 @@ tr { tr td:first-child, th { font-weight: bold; } + +.version-switcher { + position: absolute; + top: 18px; + right: 16px; + display: inline-block; + width: 80px; + z-index: 3; + color: white; +} + + +.version-switcher-options { + display: none; + /*opacity: 40%;*/ + color: var(--color-text); + position: absolute; + top: 0; + right: 0; + background-color: #f9f9f9; + width: 80px; + box-shadow: 0px 3px 7px 0px rgba(0,0,0,0.2); + z-index: 2; +} + +@media (min-width: 768px) { + .version-switcher { + color: var(--color-text); + } +} + +.version-switcher-options a, .version-switcher span { + list-style-type: none; + padding: 3px 10px; + display: block; + cursor: pointer; + font-family: var(--font-code); +} + +.version-switcher-options a { + color: var(--color-text); +} + +.version-switcher-options a:hover { + background: #bbb; + text-decoration: none; +} + +.version-switcher-options a:first-child { + background: #ccc; +} + +.version-switcher:hover .version-switcher-options { + display: block; +} + +.alert-warning { + background-color: rgba(255, 85, 35, 0.84); + padding: 10px; + color: white; + font-weight: bolder; +} + +.alert-warning a { + color: #ff6; +}