From 01f59053a0af918fa93fdd2b0ce401f8203ebdde Mon Sep 17 00:00:00 2001 From: ismailuddin Date: Wed, 14 Nov 2018 18:04:15 +0000 Subject: [PATCH 1/3] Add JS function to reformat 'Whats New' links for new format --- doc/source/_static/js/whatsnew_links.js | 22 ++++++++++++++++++++++ doc/source/conf.py | 1 + 2 files changed, 23 insertions(+) create mode 100644 doc/source/_static/js/whatsnew_links.js diff --git a/doc/source/_static/js/whatsnew_links.js b/doc/source/_static/js/whatsnew_links.js new file mode 100644 index 0000000000000..7c2a4b9938f42 --- /dev/null +++ b/doc/source/_static/js/whatsnew_links.js @@ -0,0 +1,22 @@ +(function() { + /* Reformats last part of 'whatsnew' URLs */ + const generateWhatsNew = (whatsNew) => { + let url = whatsNew[0], anchor = whatsNew[1]; + url = ((url) => url.split(".")[0] + "/")(url); + let anchorEls = anchor.slice(9).split("-"); + anchorEls[0] = ((version) => "v" + version.slice(0,1) + "." + version.slice(1,-1) + "." + version.slice(-1) + ".html#")(anchorEls[0]); + return url + anchorEls[0] + anchorEls.slice(1).join("-"); + } + + const links = Array.from(document.getElementsByTagName("a")); + links.forEach((link) => { + const re = /(whatsnew.html)#(whatsnew)-[\d]+(-\w+)+/g; + let linkElements = link.href.split("/"); + if (re.test(linkElements.slice(-1)[0])) { + let whatsNew = linkElements.slice(-1)[0].split("#"); + whatsNew = generateWhatsNew(whatsNew); + linkElements[linkElements.length - 1] = whatsNew; + link.href = linkElements.join("/") + } + }); +})(); diff --git a/doc/source/conf.py b/doc/source/conf.py index 47adc80204fcc..4f27d9536318d 100644 --- a/doc/source/conf.py +++ b/doc/source/conf.py @@ -698,3 +698,4 @@ def setup(app): app.add_autodocumenter(AccessorMethodDocumenter) app.add_autodocumenter(AccessorCallableDocumenter) app.add_directive('autosummary', PandasAutosummary) + app.add_js('js/whatsnew_links.js') From 8cc0f5f4de9e39de0b46d62dfa14ae21aeac8b70 Mon Sep 17 00:00:00 2001 From: Tom Augspurger Date: Fri, 16 Nov 2018 15:27:25 +0000 Subject: [PATCH 2/3] Update doc/source/conf.py Fix function name typo Co-Authored-By: ismailuddin --- doc/source/conf.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/source/conf.py b/doc/source/conf.py index 4f27d9536318d..869e80dda752a 100644 --- a/doc/source/conf.py +++ b/doc/source/conf.py @@ -698,4 +698,4 @@ def setup(app): app.add_autodocumenter(AccessorMethodDocumenter) app.add_autodocumenter(AccessorCallableDocumenter) app.add_directive('autosummary', PandasAutosummary) - app.add_js('js/whatsnew_links.js') + app.add_js_file('js/whatsnew_links.js') From 7b7315d0f4cc0ffab34659cda1002ee473205fa8 Mon Sep 17 00:00:00 2001 From: ismailuddin Date: Fri, 16 Nov 2018 15:30:19 +0000 Subject: [PATCH 3/3] Remove trailing whitespace --- doc/source/_static/js/whatsnew_links.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/source/_static/js/whatsnew_links.js b/doc/source/_static/js/whatsnew_links.js index 7c2a4b9938f42..bbe7d531a687d 100644 --- a/doc/source/_static/js/whatsnew_links.js +++ b/doc/source/_static/js/whatsnew_links.js @@ -11,12 +11,12 @@ const links = Array.from(document.getElementsByTagName("a")); links.forEach((link) => { const re = /(whatsnew.html)#(whatsnew)-[\d]+(-\w+)+/g; - let linkElements = link.href.split("/"); + let linkElements = link.href.split("/"); if (re.test(linkElements.slice(-1)[0])) { let whatsNew = linkElements.slice(-1)[0].split("#"); whatsNew = generateWhatsNew(whatsNew); linkElements[linkElements.length - 1] = whatsNew; - link.href = linkElements.join("/") + link.href = linkElements.join("/"); } }); })();