From 46829bf9ceb11ec1aae81c0acc62f59c5a27b1e5 Mon Sep 17 00:00:00 2001 From: Andrew Gerrand Date: Wed, 5 Aug 2015 13:36:28 +1000 Subject: [PATCH] godoc/static: dynamically adjust install instructions for a given download This change allows the download page to redirect the user to /doc/install?download=filename so the user can see installation instructions specific to the file they are downloading. This is related to this change to the core repo: https://golang.org/cl/13151 Change-Id: Ia81344ed913aea1d1a4deed021c0e07f7360ff68 Reviewed-on: https://go-review.googlesource.com/13180 Reviewed-by: Chris Broadfoot --- godoc/static/godocs.js | 39 +++++++++++++++++++++++++++++++++++++++ godoc/static/static.go | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 78 insertions(+) diff --git a/godoc/static/godocs.js b/godoc/static/godocs.js index 27d2699a..eee508d5 100644 --- a/godoc/static/godocs.js +++ b/godoc/static/godocs.js @@ -245,6 +245,44 @@ function toggleHash() { } } +function personalizeInstallInstructions() { + var prefix = '?download='; + var s = window.location.search; + if (!s.startsWith(prefix)) { + // No 'download' query string; bail. + return; + } + + var filename = s.substr(prefix.length); + var filenameRE = /^go1\.\d+(\.\d+)?([a-z0-9]+)?\.([a-z0-9]+)-([a-z0-9]+)\.(.+)$/ + $('.downloadFilename').text(filename); + $('.hideFromDownload').hide(); + var m = filenameRE.exec(filename); + if (!m) { + // Can't interpret file name; bail. + return; + } + + var os = m[3]; + var ext = m[5]; + if (ext != 'tar.gz') { + $('#tarballInstructions').hide(); + } + if (os != 'darwin' || ext != 'pkg') { + $('#darwinPackageInstructions').hide(); + } + if (os != 'windows') { + $('#windowsInstructions').hide(); + } else { + if (ext != 'msi') { + $('#windowsInstallerInstructions').hide(); + } + if (ext != 'zip') { + $('#windowsZipInstructions').hide(); + } + } +} + $(document).ready(function() { bindSearchEvents(); generateTOC(); @@ -260,6 +298,7 @@ $(document).ready(function() { setupTypeInfo(); setupCallgraphs(); toggleHash(); + personalizeInstallInstructions(); // godoc.html defines window.initFuncs in the tag, and root.html and // codewalk.js push their on-page-ready functions to the list. diff --git a/godoc/static/static.go b/godoc/static/static.go index 5c42fd0d..49d54204 100644 --- a/godoc/static/static.go +++ b/godoc/static/static.go @@ -810,6 +810,44 @@ function toggleHash() { } } +function personalizeInstallInstructions() { + var prefix = '?download='; + var s = window.location.search; + if (!s.startsWith(prefix)) { + // No 'download' query string; bail. + return; + } + + var filename = s.substr(prefix.length); + var filenameRE = /^go1\.\d+(\.\d+)?([a-z0-9]+)?\.([a-z0-9]+)-([a-z0-9]+)\.(.+)$/ + $('.downloadFilename').text(filename); + $('.hideFromDownload').hide(); + var m = filenameRE.exec(filename); + if (!m) { + // Can't interpret file name; bail. + return; + } + + var os = m[3]; + var ext = m[5]; + if (ext != 'tar.gz') { + $('#tarballInstructions').hide(); + } + if (os != 'darwin' || ext != 'pkg') { + $('#darwinPackageInstructions').hide(); + } + if (os != 'windows') { + $('#windowsInstructions').hide(); + } else { + if (ext != 'msi') { + $('#windowsInstallerInstructions').hide(); + } + if (ext != 'zip') { + $('#windowsZipInstructions').hide(); + } + } +} + $(document).ready(function() { bindSearchEvents(); generateTOC(); @@ -825,6 +863,7 @@ $(document).ready(function() { setupTypeInfo(); setupCallgraphs(); toggleHash(); + personalizeInstallInstructions(); // godoc.html defines window.initFuncs in the tag, and root.html and // codewalk.js push their on-page-ready functions to the list.