From 32dd4c4cfc6488ca57645297c547abbb3d774868 Mon Sep 17 00:00:00 2001 From: Luke Murphy Date: Wed, 23 Aug 2017 05:40:02 +0200 Subject: [PATCH] Add mkdocs search hack. Should close https://github.com/commercialhaskell/stack/issues/3376. Copy-Pasta from https://github.com/nodemcu/nodemcu-firmware/commit/7dd89dd15ef993c9740ba4d4361e6be8edd1284b. --- ChangeLog.md | 4 ++++ etc/mkdocsjs/searchhack.js | 29 +++++++++++++++++++++++++++++ mkdocs.yml | 3 +++ 3 files changed, 36 insertions(+) create mode 100644 etc/mkdocsjs/searchhack.js diff --git a/ChangeLog.md b/ChangeLog.md index 65b19a7c4d..1114a3b955 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -122,6 +122,10 @@ Bug fixes: trust the etag and not re-download. Fixed in this version. * Invoking `stack --docker` in parallel now correctly locks the sqlite database. See [#3400](https://github.com/commercialhaskell/stack/issues/3400). +* docs.haskellstack.org RTD documentation search is replaced by the mkdocs + search. Please see + [#3376](https://github.com/commercialhaskell/stack/issues/3376). + ## 1.5.1 diff --git a/etc/mkdocsjs/searchhack.js b/etc/mkdocsjs/searchhack.js new file mode 100644 index 0000000000..03608c2163 --- /dev/null +++ b/etc/mkdocsjs/searchhack.js @@ -0,0 +1,29 @@ +// Please see https://github.com/commercialhaskell/stack/issues/3376 + +(function () { + $(document).ready(function () { + fixSearch(); + }); + + function fixSearch() { + var target = document.getElementById('rtd-search-form'); + var config = {attributes: true, childList: true}; + + var observer = new MutationObserver(function(mutations) { + observer.disconnect(); + var form = $('#rtd-search-form'); + form.empty(); + form.attr('action', 'https://' + window.location.hostname + '/en/' + determineSelectedBranch() + '/search.html'); + $('').attr({ + type: "text", + name: "q", + placeholder: "Search docs" + }).appendTo(form); + }); + + if (window.location.origin.indexOf('readthedocs') > -1) { + observer.observe(target, config); + } + } + +})(); diff --git a/mkdocs.yml b/mkdocs.yml index 5294458227..d615e4450f 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -38,3 +38,6 @@ pages: markdown_extensions: - toc: permalink: true + +extra_javascript: +- etc/mkdocsjs/searchhack.js