8000 [docs] Add config docs version selector. by manugarg · Pull Request #927 · cloudprober/cloudprober · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

[docs] Add config docs version selector. #927

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

Merged
merged 1 commit into from
Nov 15, 2024
Merged
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
4 changes: 2 additions & 2 deletions docs/config/_default/menus/menus.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
name = "Config"
weight = 40
identifier = "config"
url = "/docs/config/overview"
url = "/docs/config/latest/overview"

[[main]]
name = "How-To"
Expand Down Expand Up @@ -90,7 +90,7 @@
[[docs]]
name = "Configuration"
identifier = "config"
url = "/docs/config/overview"
url = "/docs/config/latest/overview"
weight = 20
[docs.params]
collapsible = true
Expand Down
14 changes: 13 additions & 1 deletion docs/layouts/shortcodes/config-docs-nav.html
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,16 @@
Configs:  {{ $s | safeHTML}}
</div>
<br>
<button id="set-lang-yaml" class="set-lang">YAML</button>|<button id="set-lang-textpb" class="set-lang">TextPB</button>
<div style="font-size:85%">
{{ if os.FileExists "public/docs/config/" -}}
<label for="config-version-selector">Version:</label>
<select id="config-version-selector">
<option selected value="latest">latest</option>
<option value="master">master</option>
{{ range os.ReadDir "public/docs/config/" -}}
{{ if and (findRE `v[0-9]+\.[0-9]+\.[0-9]+` .Name) .IsDir }}<option value="{{ .Name }}">{{ .Name }}</option> {{ end }}
{{- end }}
</select> |
{{- end }}
Language: <button id="set-lang-yaml" class="set-lang">YAML</button>|<button id="set-lang-textpb" class="set-lang">TextPB</button>
</div>
2 changes: 1 addition & 1 deletion docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"start": "exec-bin node_modules/.bin/hugo/hugo server --bind=0.0.0.0 --disableFastRender",
"build": "exec-bin node_modules/.bin/hugo/hugo --gc --minify",
"build:preview": "npm run build -D -F",
"clean": "shx rm -rf public resources",
"clean": "shx rm -rf resources",
"clean:install": "shx rm -rf package-lock.json node_modules ",
"lint": "npm run -s lint:scripts && npm run -s lint:styles && npm run -s lint:markdown",
"lint:scripts": "eslint assets/js config functions",
Expand Down
26 changes: 26 additions & 0 deletions docs/static/configdoc.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,34 @@ function addTOC() {
}
}

function configVersionSelector() {
var currentVersion = "latest";
var configName = "overview";
const configDocsPath = (version, configName) => `/docs/config/${version}/${configName}/`;
const url = new URL(window.location.href);
const urlParts = url.pathname.split("/");
// URL with version will have 6 parts.
if (urlParts.length == 6) {
configName = urlParts[4];
currentVersion = urlParts[3];
} else if (urlParts.length == 5) {
configName = urlParts[3];
}

const versionSelector = document.getElementById("config-version-selector");
if (versionSelector) {
versionSelector.value = currentVersion;
versionSelector.addEventListener("change", function () {
const selectedVersion = versionSelector.value;
url.pathname = configDocsPath(selectedVersion, configName);
window.location.href = url.toString();
});
}
}

document.addEventListener("DOMContentLoaded", function () {
setConfigLang();
configVersionSelector();
if (window.location.hash) {
const e = document.querySelector(window.location.hash);
if (e) {
Expand Down
27 changes: 16 additions & 11 deletions tools/gen_config_docs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -56,22 +56,29 @@ if [ "${DOCS_VERSION}" != "latest" ]; then
TITLE_VERSION=" (${DOCS_VERSION})"
fi

for dir in ${ORIGINAL_DIR}/docs/_config_docs/${DOCS_VERSION}/textpb/*; do
baseName=$(basename $dir)
if [ ! -d $dir ]; then
continue
fi
cat > ${BASE_PATH}/${baseName}.md <<EOF
generate_config_files() {
local base_path="$1"
local menu_hdr="$2"
for dir in ${ORIGINAL_DIR}/docs/_config_docs/${DOCS_VERSION}/textpb/*; do
baseName=$(basename $dir)
if [ ! -d $dir ]; then
continue
fi
cat > ${base_path}/${baseName}.md <<EOF
---
${MENU_HDR}title: "${baseName^} Config${TITLE_VERSION}"
${menu_hdr}title: "${baseName^} Config${TITLE_VERSION}"
---

{{% config-docs-nav version="${DOCS_VERSION}" %}}

{{% config-doc config="$(basename $dir)" version="${DOCS_VERSION}" %}}

EOF
done
done
}

# Call the function with BASE_PATH
generate_config_files "${BASE_PATH}" "${MENU_HDR}"

cp ${ORIGINAL_DIR}/docs/content/docs/config/_index.md ${BASE_PATH}/

Expand All @@ -81,7 +88,5 @@ if [ "${DOCS_VERSION}" == "latest" ]; then
echo "Copying latest configs to non-versioned path as well."
NON_VERSIONED_BASE_PATH=${ORIGINAL_DIR}/docs/content/docs/config
mkdir -p ${NON_VERSIONED_BASE_PATH}
for dir in ${BASE_PATH}/*; do
cp -r $dir ${NON_VERSIONED_BASE_PATH}/
done
generate_config_files "${NON_VERSIONED_BASE_PATH}" ""
fi
Loading
0