Skip to content

Commit

Permalink
Merge branch 'main' into docusaurus-v3-docs
Browse files Browse the repository at this point in the history
  • Loading branch information
SaraVieira authored Apr 9, 2024
2 parents cf6d19d + e0c62b0 commit 1e25d51
Show file tree
Hide file tree
Showing 24 changed files with 83 additions and 86 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "orama-monorepo",
"version": "2.0.13",
"version": "2.0.14",
"description": "Next generation full-text and vector search engine, written in TypeScript",
"workspaces": [
"packages/*",
Expand Down
2 changes: 1 addition & 1 deletion packages/benchmarks/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "benchmarks",
"version": "2.0.13",
"version": "2.0.14",
"private": true,
"scripts": {
"bench:group": "node src/group.bench.js",
Expand Down
2 changes: 1 addition & 1 deletion packages/docs/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@orama/docs",
"version": "2.0.13",
"version": "2.0.14",
"description": "Documentation for Orama",
"private": true,
"type": "module",
Expand Down
2 changes: 1 addition & 1 deletion packages/orama/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@orama/orama",
"version": "2.0.13",
"version": "2.0.14",
"type": "module",
"description": "Next generation full-text and vector search engine, written in TypeScript",
"sideEffects": false,
Expand Down
2 changes: 1 addition & 1 deletion packages/orama/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ export async function getNanosecondsTime(): Promise<bigint> {
return process.hrtime.bigint()
}

if (process?.hrtime) {
if (typeof process !== 'undefined' && typeof process?.hrtime?.bigint === 'function') {
return process.hrtime.bigint()
}

Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-analytics/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@orama/plugin-analytics",
"version": "2.0.13",
"version": "2.0.14",
"description": "Orama plugin for providing analytics data on your searches",
"keywords": ["orama", "analytics", "telemetry"],
"license": "Apache-2.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-astro/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@orama/plugin-astro",
"description": "An Astro integration for Orama",
"version": "2.0.13",
"version": "2.0.14",
"keywords": ["astro", "astro-component", "cms", "orama", "search"],
"repository": "https://github.com/oramasearch/orama",
"author": {
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-data-persistence/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@orama/plugin-data-persistence",
"version": "2.0.13",
"version": "2.0.14",
"description": "Data persistence plugin for Orama",
"type": "module",
"sideEffects": false,
Expand Down
29 changes: 3 additions & 26 deletions packages/plugin-docusaurus-v3/README.md
Original file line number Diff line number Diff line change
@@ -1,28 +1,5 @@
# Orama plugin for Docusaurus v3
# Orama Plugin for Docusaurus v3

[![Tests](https://github.com/oramasearch/orama/actions/workflows/turbo.yml/badge.svg)](https://github.com/oramasearch/orama/actions/workflows/turbo.yml)
[Plugin documentation](https://docs.askorama.ai/open-source/plugins/plugin-docusaurus)

| :warning: This plugin do not support Docusaurus v2. Use [`@orama/plugin-docusaurus-v3`](https://www.npmjs.com/package/@orama/plugin-docusaurus) instead. |
|-------------------------------------------------------------------------------------------------------------------------------------------------------------|

## Usage

Install the plugin:

```bash
npm install --save @orama/plugin-docusaurus-v3
```

```bash
yarn add @orama/plugin-docusaurus-v3
```

Add the plugin to your `docusaurus.config.js`:

```js
plugins: ['@orama/plugin-docusaurus-v3']
```

# License

Licensed under the [Apache 2.0](/LICENSE.md) license.
For Docusaurus v2, please refer to the [v2 branch.](https://www.npmjs.com/package/@orama/plugin-docusaurus)
14 changes: 8 additions & 6 deletions packages/plugin-docusaurus-v3/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@orama/plugin-docusaurus-v3",
"version": "2.0.13",
"version": "2.0.14",
"description": "Docusaurus plugin for local search powered by orama",
"keywords": ["orama", "docusaurus"],
"license": "Apache-2.0",
Expand All @@ -21,26 +21,28 @@
"watch": "tsc --watch"
},
"dependencies": {
"@docusaurus/plugin-content-docs": "^3.2.0",
"@docusaurus/theme-common": "^3.2.0",
"@orama/highlight": "^0.1.5",
"@orama/orama": "workspace:*",
"@orama/plugin-analytics": "workspace:*",
"@orama/plugin-parsedoc": "workspace:*",
"@orama/searchbox": "^1.0.0-rc13",
"@orama/searchbox": "^1.0.0-rc14",
"@oramacloud/client": "^1.0.14",
"github-slugger": "^2.0.0",
"gray-matter": "^4.0.3",
"jsdom": "^23.2.0",
"markdown-it": "^13.0.2",
"pako": "^2.1.0",
"tslib": "^2.6.2",
"vfile-message": "^3.1.4"
"vfile-message": "^3.1.4",
"react": "^18.2.0",
"react-dom": "^18.2.0"
},
"devDependencies": {
"@types/jsdom": "^21.1.6",
"@types/markdown-it": "^13.0.7",
"@types/pako": "^2.0.3",
"react": "^18.2.0",
"react-dom": "^18.2.0"
"@types/pako": "^2.0.3"
},
"peerDependencies": {
"@docusaurus/plugin-content-docs": ">= 3.2.0",
Expand Down
22 changes: 14 additions & 8 deletions packages/plugin-docusaurus-v3/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { create, insertMultiple, save } from "@orama/orama"
import { JSDOM } from "jsdom"
import MarkdownIt from "markdown-it"
import matter from "gray-matter"
import { checkIndexAccess, createSnapshot, deployIndex } from "./utils"
import { createSnapshot, deployIndex, fetchEndpointConfig } from "./utils"

type CloudConfig = {
deploy: boolean,
Expand Down Expand Up @@ -131,7 +131,7 @@ export default function OramaPluginDocusaurus(ctx: {
category: data.category
}))

await deployData({
const endpointConfig = await deployData({
oramaDocs,
generatedFilesDir: ctx.generatedFilesDir,
version: "current",
Expand All @@ -147,8 +147,8 @@ export default function OramaPluginDocusaurus(ctx: {
analytics: options.analytics,
...(options.cloud && {
endpoint: {
url: options.cloud.endpoint,
key: options.cloud.public_api_key
url: endpointConfig?.endpoint,
key: endpointConfig?.public_api_key
}
}),
})
Expand Down Expand Up @@ -248,11 +248,15 @@ async function deployData({
const { ORAMA_CLOUD_BASE_URL } = process.env
const baseUrl = ORAMA_CLOUD_BASE_URL || "https://cloud.oramasearch.com"

if (deployConfig?.enabled) {
await checkIndexAccess(baseUrl, deployConfig.oramaCloudAPIKey!, deployConfig.indexId!)
await createSnapshot(baseUrl, deployConfig.oramaCloudAPIKey!, deployConfig.indexId!, oramaDocs)
await deployIndex(baseUrl, deployConfig.oramaCloudAPIKey!, deployConfig.indexId!)
if (deployConfig) {
const endpointConfig = await fetchEndpointConfig(baseUrl, deployConfig.oramaCloudAPIKey!, deployConfig.indexId!)

if (deployConfig.enabled) {
await createSnapshot(baseUrl, deployConfig.oramaCloudAPIKey!, deployConfig.indexId!, oramaDocs)
await deployIndex(baseUrl, deployConfig.oramaCloudAPIKey!, deployConfig.indexId!)
}

return endpointConfig
} else {
const db = await create({
schema: { ...presets.docs.schema, version: "enum" }
Expand All @@ -263,5 +267,7 @@ async function deployData({
const serializedOrama = JSON.stringify(await save(db))
const gzipedOrama = gzip(serializedOrama)
writeFileSync(indexPath(generatedFilesDir, version), gzipedOrama)

return undefined
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
.DocSearch-Button {
height: 36px;
height: 36px !important;
-webkit-user-select: none;
user-select: none
}
Expand Down
21 changes: 16 additions & 5 deletions packages/plugin-docusaurus-v3/src/theme/SearchBar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import React, { useEffect, useState } from "react"
import useBaseUrl from "@docusaurus/useBaseUrl"
import { useLocation } from "@docusaurus/router"
import useIsBrowser from "@docusaurus/useIsBrowser"
import { useActiveVersion } from "@docusaurus/plugin-content-docs/client"
import { useActiveVersion, useVersions } from "@docusaurus/plugin-content-docs/client"
import { useColorMode, useDocsPreferredVersion } from "@docusaurus/theme-common"
import { usePluginData } from "@docusaurus/useGlobalData"
import { ungzip } from "pako"
Expand All @@ -13,6 +13,15 @@ import { create, insertMultiple } from "@orama/orama"
import { pluginAnalytics } from "@orama/plugin-analytics"
import "@orama/searchbox/dist/index.css"

interface PluginData {
searchData: {
current: { data: ArrayBuffer } | null
},
endpoint: { url: string, key: string } | null,
analytics: { apiKey: string, indexId: string, enabled: boolean } | null,
docsInstances: string[]
}

export function OramaSearch() {
const [searchBoxConfig, setSearchBoxConfig] = useState(null)
const { pathname } = useLocation()
Expand All @@ -22,14 +31,15 @@ export function OramaSearch() {
endpoint,
analytics,
docsInstances
} = usePluginData("@orama/plugin-docusaurus-v3")
}: PluginData = usePluginData("@orama/plugin-docusaurus-v3") as PluginData
const pluginId = docsInstances.filter((id: string) => pathname.includes(id))[0] || docsInstances[0]
const baseURL = useBaseUrl("orama-search-index-current.json.gz")
const isBrowser = useIsBrowser()
const { colorMode } = useColorMode()
const versions = useVersions(pluginId)
const activeVersion = useActiveVersion(pluginId)
const { preferredVersion } = useDocsPreferredVersion(pluginId)
const currentVersion = activeVersion || preferredVersion
const currentVersion = activeVersion || preferredVersion || versions[0]

useEffect(() => {
async function loadOrama() {
Expand Down Expand Up @@ -63,12 +73,13 @@ export function OramaSearch() {
const db = await create({
schema: { ...presets.docs.schema, version: "enum" },
plugins: [
...(analytics && [
...(analytics ? [
pluginAnalytics({
apiKey: analytics.apiKey,
indexId: analytics.indexId,
enabled: analytics.enabled,
})
] ?? [])
] : [])
]
})

Expand Down
8 changes: 4 additions & 4 deletions packages/plugin-docusaurus-v3/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ export async function loggedOperation(preMessage: string, fn: () => Promise<any>
}
}

export async function checkIndexAccess(baseUrl: string, APIKey: string, indexId: string) {
export async function fetchEndpointConfig(baseUrl: string, APIKey: string, indexId: string) {
const result = await loggedOperation(
'Start: Check index access',
'Start: Fetch index endpoint config',
async () => await restFetcher(
`${baseUrl}/api/v1/indexes/get-index?id=${indexId}`,
{
Expand All @@ -54,10 +54,10 @@ export async function checkIndexAccess(baseUrl: string, APIKey: string, indexId:
}
}
),
'End: Check index access (success)'
'End: Fetch index endpoint config (success)'
)

return { endpoint: result?.api_endpoint, api_key: result?.api_key }
return { endpoint: result?.api_endpoint, public_api_key: result?.api_key }
}

export async function createSnapshot(baseUrl: string, APIKey: string, indexId: string, documents: any[]) {
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-docusaurus/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@orama/plugin-docusaurus",
"version": "2.0.13",
"version": "2.0.14",
"description": "Docusaurus plugin for local search powered by orama",
"keywords": ["orama", "docusaurus"],
"license": "Apache-2.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-match-highlight/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@orama/plugin-match-highlight",
"version": "2.0.13",
"version": "2.0.14",
"description": "Orama plugin for search match highlighting",
"keywords": ["full-text search", "search", "fuzzy search", "typo-tolerant search", "full-text"],
"license": "Apache-2.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-nextra/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@orama/plugin-nextra",
"version": "2.0.13",
"version": "2.0.14",
"description": "Nextra plugin for local search powered by orama",
"keywords": ["orama", "nextra"],
"license": "Apache-2.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-parsedoc/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@orama/plugin-parsedoc",
"version": "2.0.13",
"version": "2.0.14",
"description": "Orama plugin to populate an index with HTML/Markdown documents",
"keywords": [],
"author": "",
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-secure-proxy/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@orama/plugin-secure-proxy",
"version": "2.0.13",
"version": "2.0.14",
"description": "Orama plugin for generating embeddings securely on the front-end",
"keywords": ["orama", "embeddings", "secure proxy", "vector search"],
"license": "Apache-2.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-vitepress/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@orama/plugin-vitepress",
"version": "2.0.13",
"version": "2.0.14",
"description": "Vitepress plugin for local search powered by orama",
"keywords": ["orama", "vite", "vitepress", "vue"],
"license": "Apache-2.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/stemmers/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@orama/stemmers",
"version": "2.0.13",
"version": "2.0.14",
"type": "module",
"description": "Stemmers for Orama",
"sideEffects": false,
Expand Down
2 changes: 1 addition & 1 deletion packages/stopwords/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@orama/stopwords",
"version": "2.0.13",
"version": "2.0.14",
"type": "module",
"description": "Stop-words for Orama",
"sideEffects": false,
Expand Down
2 changes: 1 addition & 1 deletion packages/tokenizers/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@orama/tokenizers",
"version": "2.0.13",
"version": "2.0.14",
"type": "module",
"description": "Additional tokenizers for Orama",
"sideEffects": false,
Expand Down
Loading

0 comments on commit 1e25d51

Please sign in to comment.