diff --git a/source/_static/js/custom.js b/source/_static/js/custom.js new file mode 100644 --- /dev/null +++ b/source/_static/js/custom.js @@ -0,0 +1,25 @@ +/** + * Resets the "View page source" link to point to the current pages source file in the git repo (via Phabricator). + */ +function resetViewPageSourceLink() { + let path = window.location.pathname; + + // Grab the current "View page source" anchor tag + let viewPageSourceLink = document.getElementsByClassName("wy-breadcrumbs-aside")[0].firstElementChild; + + if (path !== "/") { + // Get the page name and the directory it's in (eg. dir/pagename.html) + path.split("/").splice(-2, 2).join("/"); + + // Replace html with rst, so we can reference the source file in the Git repo + let newPath = path.substr(0, path.lastIndexOf(".")) + "rst"; + + viewPageSourceLink.href = "https://phabricator.kde.org/source/websites-hig-kde-org/browse/master/source/" + newPath; + } + + let newPath = path.substr(1, path.lastIndexOf(".")) + "rst"; + + viewPageSourceLink.href = "https://phabricator.kde.org/source/websites-hig-kde-org/browse/master/source/" + newPath; +} + +resetViewPageSourceLink(); diff --git a/source/conf.py b/source/conf.py --- a/source/conf.py +++ b/source/conf.py @@ -190,3 +190,4 @@ # add css file def setup(app): app.add_stylesheet('css/breeze.css') + app.add_javascript('js/custom.js')