From add73aa2c57e264767da7b871a1702a100a5c86b Mon Sep 17 00:00:00 2001
From: Carson Yang <yangchuansheng33@gmail.com>
Date: Thu, 12 Oct 2023 00:04:45 +0800
Subject: [PATCH] Docs: use docsearch (#391)

Signed-off-by: Carson Yang <yangchuansheng33@gmail.com>
---
 docSite/hugo.toml                             | 10 ++---
 docSite/i18n/zh-cn.toml                       |  9 +++++
 .../partials/docs/footer/docsearch.html       | 39 +++++++++++++++++++
 3 files changed, 53 insertions(+), 5 deletions(-)
 create mode 100644 docSite/layouts/partials/docs/footer/docsearch.html

diff --git a/docSite/hugo.toml b/docSite/hugo.toml
index fe8a3c67d..a6241df73 100644
--- a/docSite/hugo.toml
+++ b/docSite/hugo.toml
@@ -110,8 +110,8 @@ defaultContentLanguage = 'zh-cn'
         listDescTrunc   = 100                                 # Number of characters by which to truncate the list card description
 
     [params.flexsearch] # Parameters for FlexSearch
-        enabled             = true
-        tokenize            = "full"
+        # enabled             = true
+        # tokenize            = "full"
         # optimize            = true
         # cache               = 100
         # minQueryChar        = 3 # default is 0 (disabled)
@@ -119,9 +119,9 @@ defaultContentLanguage = 'zh-cn'
         # searchSectionsIndex = []
 
     [params.docsearch] # Parameters for DocSearch
-        # appID     = "O2QIOCBDAK" # Algolia Application ID
-        # apiKey    = "fdc60eee76a72a35d739b54521498b77" # Algolia Search-Only API (Public) Key
-        # indexName = "prod_lotusdocs.dev" # Index Name to perform search on (or set env variable HUGO_PARAM_DOCSEARCH_indexName)
+        appID     = "5BEWEMH0YA" # Algolia Application ID
+        apiKey    = "14834e919a87217d919d6d881fcacac3" # Algolia Search-Only API (Public) Key
+        indexName = "fastgpt" # Index Name to perform search on (or set env variable HUGO_PARAM_DOCSEARCH_indexName)
 
     [params.analytics] # Parameters for Analytics (Google, Plausible)
         # plausibleURL    = "/docs/s" # (or set via env variable HUGO_PARAM_ANALYTICS_plausibleURL)
diff --git a/docSite/i18n/zh-cn.toml b/docSite/i18n/zh-cn.toml
index 553987f98..972fa79a1 100644
--- a/docSite/i18n/zh-cn.toml
+++ b/docSite/i18n/zh-cn.toml
@@ -19,6 +19,15 @@
 [search_no_results]
     other = "没有结果:"
 
+[search_no_recent_searches]
+    other = "没有最近搜索"
+
+[search_try_search]
+    other = "试试搜索"
+
+[search_search_by]
+    other = "搜索提供"
+
 [feedback_yes]
     other = "Yes"
 
diff --git a/docSite/layouts/partials/docs/footer/docsearch.html b/docSite/layouts/partials/docs/footer/docsearch.html
new file mode 100644
index 000000000..bd077a283
--- /dev/null
+++ b/docSite/layouts/partials/docs/footer/docsearch.html
@@ -0,0 +1,39 @@
+<script>
+    window.addEventListener('DOMContentLoaded', function() {
+        // DocSearch Config
+        docsearch({
+            container: '#docsearch',
+            appId: '{{ .Site.Params.docsearch.appID }}',
+            apiKey: '{{ .Site.Params.docsearch.apiKey }}',
+            indexName: '{{ .Site.Params.docsearch.indexName }}',
+            placeholder: '{{ i18n "search_title" }}',
+            translations: {
+                button: {
+                    buttonText: '{{ i18n "search_title" }}',
+                    buttonAriaLabel: '{{ i18n "search_title" }}',
+                },
+                modal: {
+                    startScreen: {
+                        noRecentSearchesText: '{{ i18n "search_no_recent_searches" }}',
+                    },
+                    footer: {
+                        selectText: '{{ i18n "search_select" }}',
+                        selectKeyAriaLabel: 'Enter key',
+                        navigateText: '{{ i18n "search_navigate" }}',
+                        navigateUpKeyAriaLabel: 'Arrow up',
+                        navigateDownKeyAriaLabel: 'Arrow down',
+                        closeText: '{{ i18n "search_close" }}',
+                        closeKeyAriaLabel: 'Escape key',
+                        searchByText: '{{ i18n "search_search_by" }}',
+                    },
+                    noResultsScreen: {
+                        noResultsText: '{{ i18n "search_no_results" }}',
+                        suggestedQueryText: '{{ i18n "search_try_search" }}',
+                        reportMissingResultsText: 'Believe this query should return results?',
+                        reportMissingResultsLinkText: 'Let us know.',
+                    },
+                },
+            }
+        });
+    });
+</script>
\ No newline at end of file
-- 
GitLab