From 949d9e75f4d6f90bceab28ed9d31be2e15052904 Mon Sep 17 00:00:00 2001 From: Simran Spiller Date: Mon, 8 Apr 2024 09:35:51 +0200 Subject: [PATCH 1/3] Mark 3.10 as deprecated --- site/data/versions.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/site/data/versions.yaml b/site/data/versions.yaml index dba897a9d3..f101a4538f 100644 --- a/site/data/versions.yaml +++ b/site/data/versions.yaml @@ -16,4 +16,4 @@ - name: "3.10" version: "3.10.14" alias: "3.10" - deprecated: false + deprecated: true From 765932c56ad0f174d94d06a83ee3e166f862d189 Mon Sep 17 00:00:00 2001 From: Simran Spiller Date: Mon, 8 Apr 2024 15:54:20 +0200 Subject: [PATCH 2/3] DOC-609 | Fix aliasing and deprecation admonition Only substitute version number with alias in internal links if currently using an alias in the URL (or if the version doesn't have a proper alias, i.e. name == alias). Perform the replacement for all versions accordingly so that rare uses of cross-version links (like in the deprecation admonition) are substituted correctly. Previously, all links were changed to the current URL version. --- .../layouts/partials/deprecated.html | 2 +- .../arangodb-docs-theme/static/js/theme.js | 46 +++++++++++++------ 2 files changed, 33 insertions(+), 15 deletions(-) diff --git a/site/themes/arangodb-docs-theme/layouts/partials/deprecated.html b/site/themes/arangodb-docs-theme/layouts/partials/deprecated.html index 22cb66e7a8..8cbe614152 100644 --- a/site/themes/arangodb-docs-theme/layouts/partials/deprecated.html +++ b/site/themes/arangodb-docs-theme/layouts/partials/deprecated.html @@ -15,7 +15,7 @@

ArangoDB v{{ $shortVersion }} reached End of Life (EOL) and is no longer supported.

-

This documentation is outdated. Please see the most recent {{ $stableVersion }} version.

+

This documentation is outdated. Please see the most recent stable version.

diff --git a/site/themes/arangodb-docs-theme/static/js/theme.js b/site/themes/arangodb-docs-theme/static/js/theme.js index ed51018675..b961986cb9 100644 --- a/site/themes/arangodb-docs-theme/static/js/theme.js +++ b/site/themes/arangodb-docs-theme/static/js/theme.js @@ -53,7 +53,7 @@ function closeAllEntries() { function loadMenu(url) { closeAllEntries(); - var version = getVersionByURL() + var version = getVersionFromURL() $('.version-menu.'+version).find('a').each(function() { $(this).attr("href", function(index, old) { @@ -146,7 +146,7 @@ function loadNotFoundPage() { function loadPage(target) { var href = target; - if (getVersionInfo(getVersionByURL()) == undefined) { + if (getVersionInfo(getVersionFromURL()) == undefined) { loadNotFoundPage(); return; } @@ -154,21 +154,21 @@ function loadPage(target) { getCurrentVersion(href); renderVersion(); loadMenu(new URL(href).pathname); - var version = getVersionInfo(getVersionByURL()).name; - href = href.replace(getVersionByURL(), version); + var version = getVersionInfo(getVersionFromURL()).name; + href = href.replace(getVersionFromURL(), version); var xhr = new XMLHttpRequest(); $.get({ xhr: function() { return xhr; }, url: href, success: function(newDoc) { if (xhr.responseURL && href.replace(/#.*/, "") !== xhr.responseURL) { - updateHistory(xhr.responseURL.replace(version, getVersionByURL())); + updateHistory(xhr.responseURL.replace(version, getVersionFromURL())); return; } if (!newDoc.includes("")) { // https://github.com/gohugoio/hugo/blob/master/tpl/tplimpl/embedded/templates/alias.html var match = /(.*?)<\/title>/.exec(newDoc)[1]; - updateHistory(match.replace(version, getVersionByURL())) + updateHistory(match.replace(version, getVersionFromURL())) return; } replaceArticle(href, newDoc) @@ -370,15 +370,33 @@ function getVersionInfo(version) { return undefined; } -function getVersionByURL() { +function getVersionFromURL() { return window.location.pathname.split("/")[1] } +function isUsingAlias() { + let urlVersion = getVersionFromURL(); + for (let v of versions) { + if (urlVersion == v.alias) return true; + } + return false; +} + function aliazeLinks(parentSelector, linkSelector) { + if (!isUsingAlias()) return; + let nameAliasMapping = {}; + for (let v of versions) { + nameAliasMapping[v.name] = v.alias; + } + $(parentSelector).find(linkSelector).each(function() { $(this).attr("href", function(index, old) { - if (old == undefined) return old - return old.replace(old.split("/")[1], getVersionByURL()); + if (old == undefined) return old; + let splitLink = old.split("/"); + let linkVersion = splitLink[1]; + let alias = nameAliasMapping[linkVersion] || linkVersion; + splitLink.splice(1, 1, alias); + return splitLink.join("/"); }); }); } @@ -402,7 +420,7 @@ function getCurrentVersion() { var urlVersion = stableVersion.name if (window.location.pathname.split("/").length > 0) { - newVersion = getVersionByURL() + newVersion = getVersionFromURL() if (newVersion === "3.8" || newVersion === "3.9") { handleOldDocsVersion(newVersion) @@ -444,7 +462,7 @@ function changeVersion() { } - var newUrl = window.location.pathname.replace(getVersionByURL(), getVersionInfo(newVersion).alias) + window.location.hash; + var newUrl = window.location.pathname.replace(getVersionFromURL(), getVersionInfo(newVersion).alias) + window.location.hash; updateHistory(newUrl); } @@ -533,7 +551,7 @@ const goToTop = (event) => { function goToHomepage(event){ event.preventDefault(); - var homepage = "/" + getVersionByURL() + "/"; + var homepage = "/" + getVersionFromURL() + "/"; updateHistory(homepage); } @@ -574,8 +592,8 @@ window.onload = () => { renderVersion(); loadPage(window.location.href) - if (getVersionInfo(getVersionByURL()) != undefined) { - window.setupDocSearch(getVersionInfo(getVersionByURL()).name); + if (getVersionInfo(getVersionFromURL()) != undefined) { + window.setupDocSearch(getVersionInfo(getVersionFromURL()).name); } else { window.setupDocSearch(stableVersion); From 98f1c3e5b096fd1cf0f2ace398ee47b974e26191 Mon Sep 17 00:00:00 2001 From: Simran Spiller <simran@arangodb.com> Date: Mon, 8 Apr 2024 16:18:01 +0200 Subject: [PATCH 3/3] DOC-670 | Soft-navigation and version aliases for cards Use AJAX load for .card-link elements, avoiding a slow full page load. Substitute version number in internal links with alias like for other links. --- .../layouts/partials/shortcodes/card.html | 7 +++++-- site/themes/arangodb-docs-theme/static/js/theme.js | 10 +++++++--- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/site/themes/arangodb-docs-theme/layouts/partials/shortcodes/card.html b/site/themes/arangodb-docs-theme/layouts/partials/shortcodes/card.html index a997cba87b..2a753ad822 100644 --- a/site/themes/arangodb-docs-theme/layouts/partials/shortcodes/card.html +++ b/site/themes/arangodb-docs-theme/layouts/partials/shortcodes/card.html @@ -1,5 +1,8 @@ -{{- $context := .context }} {{- $title := .title }} {{- $image := .icon }} {{- $link := .link }} {{- -$content := .Inner }} +{{- $context := .context }} +{{- $title := .title }} +{{- $image := .icon }} +{{- $link := .link }} +{{- $content := .Inner }} {{ $destinationPage := "" }} {{ if hasPrefix $link "/" }} diff --git a/site/themes/arangodb-docs-theme/static/js/theme.js b/site/themes/arangodb-docs-theme/static/js/theme.js index b961986cb9..f90c3f8ef4 100644 --- a/site/themes/arangodb-docs-theme/static/js/theme.js +++ b/site/themes/arangodb-docs-theme/static/js/theme.js @@ -190,7 +190,12 @@ function internalLinkListener() { } event.preventDefault(); updateHistory(event.target.getAttribute('href')) - }) + }); + + $('.card-link').click(function(event) { + event.preventDefault(); + updateHistory(this.getAttribute('href')) + }); } function codeShowMoreListener() { @@ -222,8 +227,7 @@ function initArticle(url) { styleImages(); internalLinkListener(); codeShowMoreListener(); - aliazeLinks('article', 'a.link:not([target])'); - aliazeLinks('article', 'a.header-link'); + aliazeLinks('article', 'a.link:not([target]), a.card-link, a.header-link'); aliazeLinks('#breadcrumbs', 'a') }