This is an automated email from the ASF dual-hosted git repository.
jeffreyh pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/doris-website.git
The following commit(s) were added to refs/heads/master by this push:
new 6db337bceb4 Feat:automatically update the hash value of searchIndex
(#1723)
6db337bceb4 is described below
commit 6db337bceb4bdd547318e3520bee843d5578000e
Author: yangon <[email protected]>
AuthorDate: Tue Jan 7 15:52:25 2025 +0800
Feat:automatically update the hash value of searchIndex (#1723)
Co-authored-by: liyang <[email protected]>
---
.github/workflows/cron-deploy-website.yml | 2 ++
scripts/update_search_hash.js | 42 +++++++++++++++++++++++++++++++
2 files changed, 44 insertions(+)
diff --git a/.github/workflows/cron-deploy-website.yml
b/.github/workflows/cron-deploy-website.yml
index 90394beaa4d..fa7b4b7b5db 100644
--- a/.github/workflows/cron-deploy-website.yml
+++ b/.github/workflows/cron-deploy-website.yml
@@ -38,6 +38,8 @@ jobs:
yarn cache clean
export NODE_OPTIONS=--max-old-space-size=8192
yarn && yarn build
+ node ./scripts/update_search_hash.js
+ cp worker.js ./build/
touch build/.dummy
cp .asf-site.yaml ./build/.asf.yaml
cp versions.json ./build/
diff --git a/scripts/update_search_hash.js b/scripts/update_search_hash.js
new file mode 100644
index 00000000000..3e500661858
--- /dev/null
+++ b/scripts/update_search_hash.js
@@ -0,0 +1,42 @@
+const fs = require('fs');
+const path = require('path');
+
+const { getIndexHash } =
require('@easyops-cn/docusaurus-search-local/dist/server/server/utils/getIndexHash.js');
+
+function ensureArray(object, key) {
+ if (!Array.isArray(object[key])) {
+ object[key] = [object[key]];
+ }
+}
+
+const searchConfig = {
+ hashed: true,
+ language: ['en', 'zh'],
+ highlightSearchTermsOnTargetPage: true,
+ docsDir: ['docs', 'versioned_docs', 'i18n'],
+ blogDir: 'blog',
+ // indexPages: true,
+ indexDocs: true,
+ // docsRouteBasePath: '/docs',
+ indexBlog: false,
+ explicitSearchResultPath: true,
+ searchBarShortcut: true,
+ searchBarShortcutHint: true,
+ searchResultLimits: 100,
+};
+ensureArray(searchConfig, 'docsDir');
+ensureArray(searchConfig, 'blogDir');
+searchConfig.docsDir = searchConfig.docsDir.map(dir => path.join(__dirname,
`../${dir}`));
+searchConfig.blogDir = searchConfig.blogDir.map(dir => path.join(__dirname,
`../${dir}`));
+const searchHash = getIndexHash(searchConfig);
+if (searchHash) {
+ const workerJSPath = path.join(__dirname, '../worker.js');
+ const workerJs = fs.readFileSync(workerJSPath, 'utf-8');
+ const targetRegex = /const searchIndexUrl =
"search-index\{dir\}\.json\?_=[^"]+"/;
+ const replacement = `const searchIndexUrl =
"search-index{dir}.json?_=${searchHash}"`;
+ const newWorkjs = workerJs.replace(targetRegex, replacement);
+ fs.writeFileSync(workerJSPath, newWorkjs, 'utf-8');
+ console.log('successful,searchHash:',searchHash)
+}else{
+ console.log('searchHash is null');
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]