From 029bd9c1d2b5b62bb4a7444416731700e291bd68 Mon Sep 17 00:00:00 2001 From: albttx Date: Wed, 20 Mar 2024 12:20:13 +0000 Subject: [PATCH] chore: use custom env for meilisearch --- docusaurus/docusaurus.config.js | 6 ++++++ docusaurus/src/theme/SearchBar.js | 17 ++++++++++++++--- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/docusaurus/docusaurus.config.js b/docusaurus/docusaurus.config.js index 4c83087..eb80093 100644 --- a/docusaurus/docusaurus.config.js +++ b/docusaurus/docusaurus.config.js @@ -22,6 +22,12 @@ const config = { locales: ["en"], }, + customFields: { + meilisearchURL: process.env.MEILISEARCH_URL || 'localhost:7700', + meilisearchApiKey: process.env.MEILISEARCH_API_KEY || 'masterKey', + meilisearchIndexUid: process.env.MEILISEARCH_INDEX_UID || 'dev' + }, + scripts: [ { // 100% privacy-first analytics diff --git a/docusaurus/src/theme/SearchBar.js b/docusaurus/src/theme/SearchBar.js index 70d2e43..c99271d 100644 --- a/docusaurus/src/theme/SearchBar.js +++ b/docusaurus/src/theme/SearchBar.js @@ -2,15 +2,26 @@ import React, { useEffect } from "react"; // import "./style.css"; import "meilisearch-docsearch/css"; +import useDocusaurusContext from '@docusaurus/useDocusaurusContext'; + + export default function Component() { + const { siteConfig } = useDocusaurusContext(); + + const { + meilisearchURL, + meilisearchApiKey, + meilisearchIndexUid, + } = siteConfig.customFields + useEffect(() => { const lang = document.querySelector("html").lang || "en"; const docsearch = require("meilisearch-docsearch").default; const destroy = docsearch({ - host: "http://localhost:7700", - apiKey: "xxx", - indexUid: "dev", + host: meilisearchURL, + apiKey: meilisearchApiKey, + indexUid: meilisearchIndexUid, container: "#docsearch", // searchParams: {filter: [`lang = ${lang}`]}, });