From bf8686eccced45a28466d5cff17ed85e3dd1257b Mon Sep 17 00:00:00 2001 From: "yongen.loong" Date: Thu, 20 Jun 2024 19:23:48 +0800 Subject: [PATCH] feat: typesense search --- .github/workflows/typesense.yml | 2 +- README.md | 10 ++ config/typesense-theme-config.json | 15 +++ docusaurus.config.ts | 4 +- package-lock.json | 204 +++++++++++++++++++++++++++++ package.json | 1 + 6 files changed, 234 insertions(+), 2 deletions(-) create mode 100644 config/typesense-theme-config.json diff --git a/.github/workflows/typesense.yml b/.github/workflows/typesense.yml index 39ed76d..785797b 100644 --- a/.github/workflows/typesense.yml +++ b/.github/workflows/typesense.yml @@ -17,7 +17,7 @@ jobs: - run: | docker run -e TYPESENSE_API_KEY="${{ secrets.TYPESENSE_API_KEY }}" \ - -e TYPESENSE_HOST="${{ secrets.TYPESENSE_HOST }}" \ + -e TYPESENSE_HOST="typesense.test.aelf.dev" \ -e TYPESENSE_PORT=443 \ -e TYPESENSE_PROTOCOL=https \ -e "CONFIG=$(cat config/typesense.json | jq -r tostring)" typesense/docsearch-scraper:0.9.1 \ No newline at end of file diff --git a/README.md b/README.md index 0c6c2c2..5127665 100644 --- a/README.md +++ b/README.md @@ -39,3 +39,13 @@ $ GIT_USER= yarn deploy ``` If you are using GitHub pages for hosting, this command is a convenient way to build the website and push to the `gh-pages` branch. + +### Generate search-only api key + +```bash +curl 'https://typesense.test.aelf.dev/keys' \ + -X POST \ + -H "X-TYPESENSE-API-KEY: ${TYPESENSE_API_KEY}" \ + -H 'Content-Type: application/json' \ + -d '{"description":"Search-only aelf-docs key.","actions": ["documents:search"], "collections": ["aelf-docs"]}' +``` diff --git a/config/typesense-theme-config.json b/config/typesense-theme-config.json new file mode 100644 index 0000000..f3dc428 --- /dev/null +++ b/config/typesense-theme-config.json @@ -0,0 +1,15 @@ +{ + "typesenseCollectionName": "aelf-docs", + "typesenseServerConfig": { + "nodes": [ + { + "host": "typesense.test.aelf.dev", + "port": 443, + "protocol": "https" + } + ], + "apiKey": "5zqd4xhbUfewLSGk7Veev11KXZcDRy9z" + }, + "typesenseSearchParameters": {}, + "contextualSearch": true +} diff --git a/docusaurus.config.ts b/docusaurus.config.ts index 2102b24..b74f323 100644 --- a/docusaurus.config.ts +++ b/docusaurus.config.ts @@ -3,6 +3,7 @@ import type {Config} from '@docusaurus/types'; import type * as Preset from '@docusaurus/preset-classic'; import footerLinks from "./config/footer-links.json"; import navbarLinks from "./config/navbar-links.json"; +import typesenseThemeConfig from "./config/typesense-theme-config.json"; const config: Config = { title: "AELF Docs", @@ -51,7 +52,7 @@ const config: Config = { } satisfies Preset.Options, ], ], - + themes: ["docusaurus-theme-search-typesense"], themeConfig: { // Replace with your project's social card image: "img/aelficon.png", @@ -86,6 +87,7 @@ const config: Config = { hideable: true, // https://docusaurus.io/docs/sidebar#hideable-sidebar }, }, + typesense: typesenseThemeConfig, } satisfies Preset.ThemeConfig, }; diff --git a/package-lock.json b/package-lock.json index 497a780..9bfeb70 100644 --- a/package-lock.json +++ b/package-lock.json @@ -12,6 +12,7 @@ "@docusaurus/preset-classic": "3.4.0", "@mdx-js/react": "^3.0.0", "clsx": "^2.0.0", + "docusaurus-theme-search-typesense": "^0.20.0-0", "prism-react-renderer": "^2.3.0", "react": "^18.0.0", "react-dom": "^18.0.0" @@ -4012,6 +4013,11 @@ "astring": "bin/astring" } }, + "node_modules/asynckit": { + "version": "0.4.0", + "resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz", + "integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==" + }, "node_modules/at-least-node": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/at-least-node/-/at-least-node-1.0.0.tgz", @@ -4056,6 +4062,16 @@ "postcss": "^8.1.0" } }, + "node_modules/axios": { + "version": "1.7.2", + "resolved": "https://registry.npmjs.org/axios/-/axios-1.7.2.tgz", + "integrity": "sha512-2A8QhOMrbomlDuiLeK9XibIBzuHeRcqqNOHp0Cyp5EoJ1IFDh+XZH3A6BkXtv0K4gFGCI0Y4BM7B1wOEi0Rmgw==", + "dependencies": { + "follow-redirects": "^1.15.6", + "form-data": "^4.0.0", + "proxy-from-env": "^1.1.0" + } + }, "node_modules/babel-loader": { "version": "9.1.3", "resolved": "https://registry.npmjs.org/babel-loader/-/babel-loader-9.1.3.tgz", @@ -4689,6 +4705,17 @@ "node": ">=10" } }, + "node_modules/combined-stream": { + "version": "1.0.8", + "resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz", + "integrity": "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==", + "dependencies": { + "delayed-stream": "~1.0.0" + }, + "engines": { + "node": ">= 0.8" + } + }, "node_modules/comma-separated-tokens": { "version": "2.0.3", "resolved": "https://registry.npmjs.org/comma-separated-tokens/-/comma-separated-tokens-2.0.3.tgz", @@ -5437,6 +5464,14 @@ "url": "https://github.com/sponsors/sindresorhus" } }, + "node_modules/delayed-stream": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz", + "integrity": "sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ==", + "engines": { + "node": ">=0.4.0" + } + }, "node_modules/depd": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/depd/-/depd-2.0.0.tgz", @@ -5546,6 +5581,57 @@ "node": ">=6" } }, + "node_modules/docusaurus-theme-search-typesense": { + "version": "0.20.0-0", + "resolved": "https://registry.npmjs.org/docusaurus-theme-search-typesense/-/docusaurus-theme-search-typesense-0.20.0-0.tgz", + "integrity": "sha512-MW6fLJsZYfKKDRXC6pTe77OMhyQBishJO/L1M14hZymavKW2IyYFy+Mczp8TXL9QqvkLsW7Ja7YtnWXjmt5sCw==", + "dependencies": { + "@docusaurus/logger": "3.4.0", + "@docusaurus/plugin-content-docs": "3.4.0", + "@docusaurus/theme-translations": "3.4.0", + "@docusaurus/utils": "3.4.0", + "@docusaurus/utils-validation": "3.4.0", + "algoliasearch-helper": "^3.10.0", + "clsx": "^1.2.1", + "eta": "^2.0.0", + "fs-extra": "^10.1.0", + "lodash": "^4.17.21", + "tslib": "^2.4.0", + "typesense-docsearch-react": "^3.4.1", + "typesense-instantsearch-adapter": "^2.7.1", + "utility-types": "^3.10.0" + }, + "engines": { + "node": ">=18" + }, + "peerDependencies": { + "@docusaurus/core": "3.4.0", + "@docusaurus/theme-common": "3.4.0", + "react": "^18.0.0", + "react-dom": "^18.0.0" + } + }, + "node_modules/docusaurus-theme-search-typesense/node_modules/clsx": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/clsx/-/clsx-1.2.1.tgz", + "integrity": "sha512-EcR6r5a8bj6pu3ycsa/E/cKVGuTgZJZdsyUYHOksG/UHIiKfjxzRxYJpyVBwYaQeOvghal9fcc4PidlgzugAQg==", + "engines": { + "node": ">=6" + } + }, + "node_modules/docusaurus-theme-search-typesense/node_modules/fs-extra": { + "version": "10.1.0", + "resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-10.1.0.tgz", + "integrity": "sha512-oRXApq54ETRj4eMiFzGnHWGy+zo5raudjuxN0b8H7s/RU2oW0Wvsx9O0ACRN/kRq9E8Vu/ReskGB5o3ji+FzHQ==", + "dependencies": { + "graceful-fs": "^4.2.0", + "jsonfile": "^6.0.1", + "universalify": "^2.0.0" + }, + "engines": { + "node": ">=12" + } + }, "node_modules/dom-converter": { "version": "0.2.0", "resolved": "https://registry.npmjs.org/dom-converter/-/dom-converter-0.2.0.tgz", @@ -6448,6 +6534,19 @@ "node": ">=6" } }, + "node_modules/form-data": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.0.tgz", + "integrity": "sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww==", + "dependencies": { + "asynckit": "^0.4.0", + "combined-stream": "^1.0.8", + "mime-types": "^2.1.12" + }, + "engines": { + "node": ">= 6" + } + }, "node_modules/form-data-encoder": { "version": "2.1.4", "resolved": "https://registry.npmjs.org/form-data-encoder/-/form-data-encoder-2.1.4.tgz", @@ -8038,6 +8137,18 @@ "resolved": "https://registry.npmjs.org/lodash.uniq/-/lodash.uniq-4.5.0.tgz", "integrity": "sha512-xfBaXQd9ryd9dlSDvnvI0lvxfLJlYAZzXomUYzLKtUeOQvOP5piqAWuGtrhWeqaXK9hhoM/iyJc5AV+XfsX3HQ==" }, + "node_modules/loglevel": { + "version": "1.9.1", + "resolved": "https://registry.npmjs.org/loglevel/-/loglevel-1.9.1.tgz", + "integrity": "sha512-hP3I3kCrDIMuRwAwHltphhDM1r8i55H33GgqjXbrisuJhF4kRhW1dNuxsRklp4bXl8DSdLaNLuiL4A/LWRfxvg==", + "engines": { + "node": ">= 0.6.0" + }, + "funding": { + "type": "tidelift", + "url": "https://tidelift.com/funding/github/npm/loglevel" + } + }, "node_modules/longest-streak": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/longest-streak/-/longest-streak-3.1.0.tgz", @@ -11580,6 +11691,11 @@ "node": ">= 0.10" } }, + "node_modules/proxy-from-env": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/proxy-from-env/-/proxy-from-env-1.1.0.tgz", + "integrity": "sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg==" + }, "node_modules/punycode": { "version": "1.4.1", "resolved": "https://registry.npmjs.org/punycode/-/punycode-1.4.1.tgz", @@ -13523,6 +13639,94 @@ "node": ">=14.17" } }, + "node_modules/typesense": { + "version": "1.8.2", + "resolved": "https://registry.npmjs.org/typesense/-/typesense-1.8.2.tgz", + "integrity": "sha512-aBpePjA99Qvo+OP2pJwMpvga4Jrm1Y2oV5NsrWXBxlqUDNEUCPZBIksPv2Hq0jxQxHhLLyJVbjXjByXsvpCDVA==", + "dependencies": { + "axios": "^1.6.0", + "loglevel": "^1.8.1" + }, + "engines": { + "node": ">=18" + }, + "peerDependencies": { + "@babel/runtime": "^7.23.2" + } + }, + "node_modules/typesense-docsearch-css": { + "version": "0.4.1", + "resolved": "https://registry.npmjs.org/typesense-docsearch-css/-/typesense-docsearch-css-0.4.1.tgz", + "integrity": "sha512-mN8K18pfIpCrhzsMAJBzoS7l/YDcC4P3f9vsScenUceXmC8n3FCPldmF10dKDJmK3Lr7aAScQt70jCA5126y2w==" + }, + "node_modules/typesense-docsearch-react": { + "version": "3.4.1", + "resolved": "https://registry.npmjs.org/typesense-docsearch-react/-/typesense-docsearch-react-3.4.1.tgz", + "integrity": "sha512-d0PQym/B/p5oP+hfdFEOH6goiKa1JLR63bikZSDGq1+jT2FtuwNrdMGVBZZMNFUsXVsJRA8ULHJpsREmfSJmVw==", + "dependencies": { + "@algolia/autocomplete-core": "1.8.2", + "@algolia/autocomplete-preset-algolia": "1.8.2", + "typesense": "^1.7.2", + "typesense-docsearch-css": "^0.4.1", + "typesense-instantsearch-adapter": "^2.7.1" + }, + "peerDependencies": { + "@types/react": ">= 16.8.0 < 19.0.0", + "react": ">= 16.8.0 < 19.0.0", + "react-dom": ">= 16.8.0 < 19.0.0" + }, + "peerDependenciesMeta": { + "@types/react": { + "optional": true + }, + "react": { + "optional": true + }, + "react-dom": { + "optional": true + } + } + }, + "node_modules/typesense-docsearch-react/node_modules/@algolia/autocomplete-core": { + "version": "1.8.2", + "resolved": "https://registry.npmjs.org/@algolia/autocomplete-core/-/autocomplete-core-1.8.2.tgz", + "integrity": "sha512-mTeshsyFhAqw/ebqNsQpMtbnjr+qVOSKXArEj4K0d7sqc8It1XD0gkASwecm9mF/jlOQ4Z9RNg1HbdA8JPdRwQ==", + "dependencies": { + "@algolia/autocomplete-shared": "1.8.2" + } + }, + "node_modules/typesense-docsearch-react/node_modules/@algolia/autocomplete-preset-algolia": { + "version": "1.8.2", + "resolved": "https://registry.npmjs.org/@algolia/autocomplete-preset-algolia/-/autocomplete-preset-algolia-1.8.2.tgz", + "integrity": "sha512-J0oTx4me6ZM9kIKPuL3lyU3aB8DEvpVvR6xWmHVROx5rOYJGQcZsdG4ozxwcOyiiu3qxMkIbzntnV1S1VWD8yA==", + "dependencies": { + "@algolia/autocomplete-shared": "1.8.2" + }, + "peerDependencies": { + "@algolia/client-search": ">= 4.9.1 < 6", + "algoliasearch": ">= 4.9.1 < 6" + } + }, + "node_modules/typesense-docsearch-react/node_modules/@algolia/autocomplete-shared": { + "version": "1.8.2", + "resolved": "https://registry.npmjs.org/@algolia/autocomplete-shared/-/autocomplete-shared-1.8.2.tgz", + "integrity": "sha512-b6Z/X4MczChMcfhk6kfRmBzPgjoPzuS9KGR4AFsiLulLNRAAqhP+xZTKtMnZGhLuc61I20d5WqlId02AZvcO6g==" + }, + "node_modules/typesense-instantsearch-adapter": { + "version": "2.8.0", + "resolved": "https://registry.npmjs.org/typesense-instantsearch-adapter/-/typesense-instantsearch-adapter-2.8.0.tgz", + "integrity": "sha512-2q4QVpHoUV0ncf1XOqIC0dufOTkFRxQ0mHzg//H3WK02ZYqdNNPCAacZODhQlltl1cNJdTI8Y4uuGVd6fJuGzw==", + "hasInstallScript": true, + "dependencies": { + "typesense": "^1.7.2" + }, + "engines": { + "node": ">=16" + }, + "peerDependencies": { + "@babel/runtime": "^7.17.2" + } + }, "node_modules/undici-types": { "version": "5.26.5", "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-5.26.5.tgz", diff --git a/package.json b/package.json index 586f630..0e513b5 100644 --- a/package.json +++ b/package.json @@ -19,6 +19,7 @@ "@docusaurus/preset-classic": "3.4.0", "@mdx-js/react": "^3.0.0", "clsx": "^2.0.0", + "docusaurus-theme-search-typesense": "^0.20.0-0", "prism-react-renderer": "^2.3.0", "react": "^18.0.0", "react-dom": "^18.0.0"