Skip to content

Commit

Permalink
Generate docs for all tags
Browse files Browse the repository at this point in the history
  • Loading branch information
vektah committed Jan 7, 2020
1 parent 8218c73 commit cfa2907
Show file tree
Hide file tree
Showing 7 changed files with 155 additions and 1 deletion.
56 changes: 56 additions & 0 deletions docs/build.sh
Original file line number Diff line number Diff line change
@@ -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"

3 changes: 2 additions & 1 deletion docs/layouts/_default/baseof.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,12 @@
</head>

<body>
{{ partial "version-switcher" . }}
{{ partial "sidebar" . }} {{ block "main" . }}{{ end }}
<footer>
&copy; {{ now.Format "2006" }}
<a href="https://github.com/vektah">Adam Scarr</a>
</footer>
</body>

</html>
</html>
1 change: 1 addition & 0 deletions docs/layouts/_default/single.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ <h1>{{ .LinkTitle }}</h1>

<main>
<div class="content">
{{partial "version-banner"}}
{{ .Content }}
</div>
</main>
Expand Down
1 change: 1 addition & 0 deletions docs/layouts/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ <h1>{{ .LinkTitle }}</h1>

<main>
<div class="content">
{{partial "version-banner"}}
{{ .Content }}
{{.Scratch.Set "intro" (readFile "content/_introduction.md")}}
{{.Scratch.Set "intro" (split (.Scratch.Get "intro") "\n")}}
Expand Down
14 changes: 14 additions & 0 deletions docs/layouts/partials/version-banner.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{{ $currentVersion := getenv "CURRENT_VERSION" }}
{{ $versionString := getenv "VERSIONS" }}
{{ $versions := split $versionString "," }}
{{ $latestVersion := index $versions 0 }}

{{ if (eq $currentVersion "master") }}
<div class="alert-warning">
You are looking at the docs for the unreleased <code>master</code> branch. The latest version is <a href="/$latestVersion">{{ $latestVersion }}</a>.
</div>
{{ else if not (eq $latestVersion $currentVersion) }}
<div class="alert-warning">
You are looking at the docs for an older version ({{ $currentVersion }}). The latest version is <a href="/$latestVersion">{{ $latestVersion }}</a>.
</div>
{{ end }}
15 changes: 15 additions & 0 deletions docs/layouts/partials/version-switcher.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{{ $VersionString := getenv "VERSIONS" }}
{{ $Versions := split $VersionString "," }}
{{ $currentVersion := getenv "CURRENT_VERSION" }}

<div class="version-switcher">
<span>{{ $currentVersion }}</span>
<div class="version-switcher-options">
<a class="version-switcher-option">{{$currentVersion}}</a>
{{ range $i, $version := $Versions }}
{{ if not (eq $currentVersion $version) }}
<a href="/{{$version}}/" class="version-switcher-option">{{$version}}</a>
{{ end }}
{{ end }}
</div>
</div>
66 changes: 66 additions & 0 deletions docs/static/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

0 comments on commit cfa2907

Please sign in to comment.