From 4824e55ebfe20ecf6eeab9d454a08b044a88834a Mon Sep 17 00:00:00 2001
From: kazk <kazk.dev@gmail.com>
Date: Mon, 19 Apr 2021 18:53:58 -0700
Subject: [PATCH 1/2] Add search with DocSearch

---
 .github/workflows/docsearch.yml | 22 ++++++++++++++++++++
 docsearch.json                  | 36 +++++++++++++++++++++++++++++++++
 docusaurus.config.js            |  6 ++++++
 src/css/custom.css              | 27 ++++++++++++++++++++++++-
 4 files changed, 90 insertions(+), 1 deletion(-)
 create mode 100644 .github/workflows/docsearch.yml
 create mode 100644 docsearch.json

diff --git a/.github/workflows/docsearch.yml b/.github/workflows/docsearch.yml
new file mode 100644
index 00000000..f6d8fa57
--- /dev/null
+++ b/.github/workflows/docsearch.yml
@@ -0,0 +1,22 @@
+name: DocSearch Scraper
+
+on:
+  schedule:
+    # Run daily at 00:00 UTC
+    - cron: "0 0 * * *"
+
+jobs:
+  scrape:
+    runs-on: ubuntu-latest
+    steps:
+      - uses: actions/checkout@v2
+      - name: Get DocSearch Config
+        id: docsearch-config
+        run: echo "::set-output name=json::$(cat docsearch.json | jq -r tostring)"
+      - name: Run DocSearch Scraper
+        run: docker run -e TZ -e API_KEY -e APPLICATION_ID -e CONFIG algolia/docsearch-scraper:latest
+        env:
+          TZ: UTC
+          API_KEY: ${{ secrets.ALGOLIA_API_KEY }}
+          APPLICATION_ID: "2O5VWTLFC8"
+          CONFIG: ${{ steps.docsearch-config.outputs.json }}
diff --git a/docsearch.json b/docsearch.json
new file mode 100644
index 00000000..985ff609
--- /dev/null
+++ b/docsearch.json
@@ -0,0 +1,36 @@
+{
+  "index_name": "codewars-docs",
+  "start_urls": ["https://docs.codewars.com/"],
+  "sitemap_urls": ["https://docs.codewars.com/sitemap.xml"],
+  "sitemap_alternate_links": true,
+  "stop_urls": [],
+  "selectors": {
+    "lvl0": {
+      "selector": "(//ul[contains(@class,'menu__list')]//a[contains(@class, 'menu__link menu__link--sublist menu__link--active')]/text() | //nav[contains(@class, 'navbar')]//a[contains(@class, 'navbar__link--active')]/text())[last()]",
+      "type": "xpath",
+      "global": true,
+      "default_value": "Documentation"
+    },
+    "lvl1": "header h1",
+    "lvl2": "article h2",
+    "lvl3": "article h3",
+    "lvl4": "article h4",
+    "lvl5": "article h5",
+    "lvl6": "article h6",
+    "text": "article p, article li"
+  },
+  "strip_chars": " .,;:#",
+  "custom_settings": {
+    "separatorsToIndex": "_",
+    "attributesForFaceting": ["language", "version", "type", "docusaurus_tag"],
+    "attributesToRetrieve": [
+      "hierarchy",
+      "content",
+      "anchor",
+      "url",
+      "url_without_anchor",
+      "type"
+    ]
+  },
+  "nb_hits": 3038
+}
diff --git a/docusaurus.config.js b/docusaurus.config.js
index 7b6d3905..63d2c357 100644
--- a/docusaurus.config.js
+++ b/docusaurus.config.js
@@ -14,6 +14,12 @@ module.exports = {
     colorMode: {
       defaultMode: "dark",
     },
+    algolia: {
+      // Search only API key
+      apiKey: "651420d53bdf2d24b6719c6777dc69a4",
+      indexName: "codewars-docs",
+      appId: "2O5VWTLFC8",
+    },
     navbar: {
       title: "Codewars",
       hideOnScroll: true,
diff --git a/src/css/custom.css b/src/css/custom.css
index e9a4c6bd..372304f7 100644
--- a/src/css/custom.css
+++ b/src/css/custom.css
@@ -9,7 +9,7 @@
 @tailwind utilities;
 
 :root {
-  --ifm-color-primary: #b1361e;
+  --ifm-color-primary: theme("colors.brand");
   --ifm-color-primary-dark: #9f311b;
   --ifm-color-primary-darker: #962e19;
   --ifm-color-primary-darkest: #7c2615;
@@ -156,3 +156,28 @@ html[data-theme="dark"] .anchored:target {
     @apply text-caution-content;
   }
 }
+
+html[data-theme="light"] .DocSearch {
+  --docsearch-primary-color: theme("colors.red.500");
+  --docsearch-highlight-color: var(--docsearch-primary-color);
+  --docsearch-searchbox-shadow: inset 0 0 0 2px var(--docsearch-primary-color);
+  --docsearch-logo-color: theme("colors.red.400");
+}
+
+html[data-theme="dark"] .DocSearch {
+  --docsearch-primary-color: theme("colors.red.800");
+  --docsearch-text-color: var(--ifm-font-color-base);
+  --docsearch-highlight-color: var(--docsearch-primary-color);
+  --docsearch-muted-color: var(--ifm-color-secondary-darkest);
+  --docsearch-container-background: rgba(47, 55, 69, 0.7);
+  --docsearch-logo-color: theme("colors.red.900");
+  --docsearch-modal-background: var(--ifm-background-color);
+  --docsearch-modal-shadow: inset 1px 1px 0 0 #2c2e40, 0 3px 8px 0 #000309;
+  --docsearch-searchbox-shadow: inset 0 0 0 2px var(--docsearch-primary-color);
+  --docsearch-footer-background: var(--ifm-background-surface-color);
+  --docsearch-key-gradient: linear-gradient(
+    -26.5deg,
+    var(--ifm-color-emphasis-200) 0%,
+    var(--ifm-color-emphasis-100) 100%
+  );
+}

From bc09b12785de71d12902b7dfe181d57683c2254b Mon Sep 17 00:00:00 2001
From: kazk <kazk.dev@gmail.com>
Date: Mon, 19 Apr 2021 20:09:14 -0700
Subject: [PATCH 2/2] Update docsearch/react to 3.0.0-alpha.36

---
 yarn.lock | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/yarn.lock b/yarn.lock
index 253c2ccc..206422a1 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -1120,19 +1120,19 @@
   resolved "https://registry.yarnpkg.com/@csstools/convert-colors/-/convert-colors-1.4.0.tgz#ad495dc41b12e75d588c6db8b9834f08fa131eb7"
   integrity sha512-5a6wqoJV/xEdbRNKVo6I4hO3VjyDq//8q2f9I6PBAvMesJHFauXDorcNCsr9RzvsZnaWi5NYCcfyqP1QeFHFbw==
 
-"@docsearch/css@3.0.0-alpha.35":
-  version "3.0.0-alpha.35"
-  resolved "https://registry.yarnpkg.com/@docsearch/css/-/css-3.0.0-alpha.35.tgz#17579a6649cae7303ecac400795e84b1a906a5ed"
-  integrity sha512-Qaft+2qy7VYzy3j02OqurXtm1tCNXAfTO1u8R7ww4qB9+1Ns80kn9tJejbtQclgBbFCGf7kn7JShxwlpEMLUzw==
+"@docsearch/css@3.0.0-alpha.36":
+  version "3.0.0-alpha.36"
+  resolved "https://registry.yarnpkg.com/@docsearch/css/-/css-3.0.0-alpha.36.tgz#0af69a86b845974d0f8cab62db0218f66b6ad2d6"
+  integrity sha512-zSN2SXuZPDqQaSFzYa1kOwToukqzhLHG7c66iO+/PlmWb6/RZ5cjTkG6VCJynlohRWea7AqZKWS/ptm8kM2Dmg==
 
 "@docsearch/react@^3.0.0-alpha.33":
-  version "3.0.0-alpha.35"
-  resolved "https://registry.yarnpkg.com/@docsearch/react/-/react-3.0.0-alpha.35.tgz#ce7c2480384c4721976dc49f0962701e98b309d2"
-  integrity sha512-gL3CsZDvRhrrte2zjUFfnKC/jG2o2S6W9+v+m46Ro0juzfdSoKnVLyCr6MUi94asE6yF1zjCX1Z9xcpw0wq8YA==
+  version "3.0.0-alpha.36"
+  resolved "https://registry.yarnpkg.com/@docsearch/react/-/react-3.0.0-alpha.36.tgz#f2dbd53ba9c389bc19aea89a3ad21782fa6b4bb5"
+  integrity sha512-synYZDHalvMzesFiy7kK+uoz4oTdWSTbe2cU+iiUjwFMyQ+WWjWwGVnvcvk+cjj9pRCVaZo5y5WpqNXq1j8k9Q==
   dependencies:
     "@algolia/autocomplete-core" "1.0.0-alpha.44"
     "@algolia/autocomplete-preset-algolia" "1.0.0-alpha.44"
-    "@docsearch/css" "3.0.0-alpha.35"
+    "@docsearch/css" "3.0.0-alpha.36"
     algoliasearch "^4.0.0"
 
 "@docusaurus/core@2.0.0-alpha.73":