Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

style: formats codebase #785

Merged
merged 1 commit into from
Sep 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
968 changes: 543 additions & 425 deletions packages/docs/astro.config.mjs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion packages/docs/biome.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,4 @@
"attributePosition": "auto"
}
}
}
}
34 changes: 20 additions & 14 deletions packages/docs/scripts/postbuild.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,12 @@ function unslugify(slug: string) {
return slug
.toLowerCase()
.split(/[-_.\s]/)
.map((w) => `${w.charAt(0).toUpperCase()}${w.substring(1)}`).join(' ');
.map((w) => `${w.charAt(0).toUpperCase()}${w.substring(1)}`)
.join(' ')
}

async function getAllRenderedDocs() {
const [cloud, oss] = await Promise.all([
globby(docsCloud),
globby(docsOSS)
])
const [cloud, oss] = await Promise.all([globby(docsCloud), globby(docsOSS)])

return {
cloud,
Expand All @@ -36,23 +34,31 @@ async function getAllRenderedDocs() {
}

function parseDoc(path: string) {
const content = readFileSync(path, 'utf-8')
const content = readFileSync(path, 'utf-8')
const isCloud = path.replace(baseURL, '').startsWith('/cloud')
const fullPath = `http://localhost:3000${path.replace(baseURL, '').replace(/^\/(open-source|cloud)/, '').replace('.html', '').replace(/\/index$/, '')}`
const fullPath = `http://localhost:3000${path
.replace(baseURL, '')
.replace(/^\/(open-source|cloud)/, '')
.replace('.html', '')
.replace(/\/index$/, '')}`

return generalPurposeCrawler(fullPath, content, {
parseCodeBlocks: true,
parseCodeBlocks: true
}).map((doc) => ({
...doc,
path: `/${isCloud ? 'cloud' : 'open-source'}${doc.path}`,
path: `/${isCloud ? 'cloud' : 'open-source'}${doc.path}`
}))
}

async function getAllParsedDocuments() {
const { cloud, oss } = await getAllRenderedDocs()
const cloudDocs = (await Promise.all(cloud.map(parseDoc))).flat().map((doc) => ({ ...doc, category: 'Cloud', section: unslugify(doc.section) }))
const ossDocs = (await Promise.all(oss.map(parseDoc))).flat().map((doc) => ({ ...doc, category: 'Open Source', section: unslugify(doc.section) }))

const cloudDocs = (await Promise.all(cloud.map(parseDoc)))
.flat()
.map((doc) => ({ ...doc, category: 'Cloud', section: unslugify(doc.section) }))
const ossDocs = (await Promise.all(oss.map(parseDoc)))
.flat()
.map((doc) => ({ ...doc, category: 'Open Source', section: unslugify(doc.section) }))

return [...cloudDocs, ...ossDocs]
}

Expand All @@ -62,7 +68,7 @@ async function updateOramaCloud(docs: GeneralPurposeCrawlerResult[]) {
return
}
const oramaCloudManager = new CloudManager({
api_key: process.env.ORAMA_CLOUD_PRIVATE_API_KEY,
api_key: process.env.ORAMA_CLOUD_PRIVATE_API_KEY
})

const docsIndex = oramaCloudManager.index(process.env.ORAMA_CLOUD_INDEX_ID)
Expand All @@ -76,4 +82,4 @@ async function updateOramaCloud(docs: GeneralPurposeCrawlerResult[]) {

const docs = await getAllParsedDocuments()

await updateOramaCloud(docs)
await updateOramaCloud(docs)
5 changes: 1 addition & 4 deletions packages/docs/src/components/Head.astro
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@
import type { Props } from '@astrojs/starlight/props'
import Default from '@astrojs/starlight/components/Head.astro'

const ogImageUrl = new URL(
`/og/${Astro.props.id.replace(/\.\w+$/, '.png')}`,
Astro.site,
)
const ogImageUrl = new URL(`/og/${Astro.props.id.replace(/\.\w+$/, '.png')}`, Astro.site)
---

<Default {...Astro.props}><slot /></Default>
Expand Down
23 changes: 11 additions & 12 deletions packages/docs/src/components/Search/Search.jsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { useEffect, useState } from 'react'
import { OramaClient } from '@oramacloud/client';
import { OramaClient } from '@oramacloud/client'
import { OramaSearchBox, OramaSearchButton } from '@orama/react-components'
import { ossSuggestions, cloudSuggestions } from './suggestions';
import { getCurrentCategory, getOramaUserId, searchSessionTracking, userSessionRefresh } from './utils';
import { ossSuggestions, cloudSuggestions } from './suggestions'
import { getCurrentCategory, getOramaUserId, searchSessionTracking, userSessionRefresh } from './utils'

const client = new OramaClient({
api_key: 'NKiqTJnwnKsQCdxN7RyOBJgeoW5hJ594',
endpoint: 'https://cloud.orama.run/v1/indexes/orama-docs-bzo330'
})
})

function useCmdK(callback) {
const [isCmdKPressed, setIsCmdKPressed] = useState(false)
Expand All @@ -21,13 +21,13 @@ function useCmdK(callback) {
callback()
}
}
};
}

const handleKeyUp = (event) => {
if ((event.metaKey || event.ctrlKey) && event.key === 'k') {
setIsCmdKPressed(false);
setIsCmdKPressed(false)
}
};
}

window.addEventListener('keydown', handleKeyDown)
window.addEventListener('keyup', handleKeyUp)
Expand All @@ -44,7 +44,7 @@ function useCmdK(callback) {
export function Search() {
const [theme, setTheme] = useState()
const [currentCategory, setCurrentCategory] = useState(null)
const [userId, setUserId] = useState(getOramaUserId());
const [userId, setUserId] = useState(getOramaUserId())

// TODO: Remove when fully integrated
const [isOpen, setIsOpen] = useState(false)
Expand All @@ -65,7 +65,6 @@ export function Search() {
const intervalId = setInterval(() => userSessionRefresh(client, userId, setUserId), 5000)
return () => clearInterval(intervalId)
}, [userId])


useEffect(() => {
function callback(mutationList) {
Expand Down Expand Up @@ -103,7 +102,7 @@ export function Search() {

const facetProperty = ['Cloud', 'Open Source'].includes(currentCategory) ? 'section' : 'category'
const suggestions = currentCategory === 'Open Source' ? ossSuggestions : cloudSuggestions

if (!theme) return null

return (
Expand All @@ -115,10 +114,10 @@ export function Search() {
setIsOpen(false)
}}
sourcesMap={{
description: 'content',
description: 'content'
}}
resultsMap={{
description: 'content',
description: 'content'
}}
searchParams={{
where: oramaWhere
Expand Down
4 changes: 2 additions & 2 deletions packages/docs/src/components/Search/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import { Search } from "./Search";
import { Search } from './Search'

export { Search };
export { Search }
6 changes: 3 additions & 3 deletions packages/docs/src/components/Search/suggestions.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
export const ossSuggestions = [
'What languages are supported?',
'How do I write an Orama plugin?',
'How do I perform vector search with OSS Orama?',
'How do I perform vector search with OSS Orama?'
]

export const cloudSuggestions = [
'What is an Orama index?',
'How do I perform vector search with Orama Cloud?',
'What is an answer session?',
]
'What is an answer session?'
]
24 changes: 12 additions & 12 deletions packages/docs/src/components/Search/utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { OramaClient } from "@oramacloud/client"
import type { OramaClient } from '@oramacloud/client'

export function getCurrentCategory() {
const url = new URL(window.location.href).pathname
Expand All @@ -11,23 +11,23 @@ export function getCurrentCategory() {

export function getOramaUserId() {
if (typeof document === 'undefined' || typeof window === 'undefined') return

const cookies = document.cookie.split(';')
const oid = cookies.find(cookie => cookie.startsWith('oid='))
const oid = cookies.find((cookie) => cookie.startsWith('oid='))

if (oid) {
return oid.split('=')[1]
}

return undefined
}

export function userSessionRefresh(client: OramaClient, userId: string, updateCallback: (userId: string) => void) {
const currentUserId = getOramaUserId();
const currentUserId = getOramaUserId()
if (currentUserId !== userId) {
console.log('User ID changed:', currentUserId);
client.reset();
updateCallback(currentUserId);
console.log('User ID changed:', currentUserId)
client.reset()
updateCallback(currentUserId)
}
}

Expand All @@ -37,13 +37,13 @@ export function searchSessionTracking(client: OramaClient, userId: string) {
if (userId) {
// TODO: remove this console.log
console.log('Identifying user with Cookie ID:', userId)
client.identify(userId);
client.identify(userId)
} else {
// TODO: remove this console.log
console.log('Identifying session with PostHog:', window.posthog.get_distinct_id())
client.alias(window.posthog.get_distinct_id());
client.alias(window.posthog.get_distinct_id())
}
} catch (error) {
console.log(`Error setting identity: ${error}`);
console.log(`Error setting identity: ${error}`)
}
}
12 changes: 5 additions & 7 deletions packages/docs/src/components/Sidebar.astro
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
---
import type { Props } from "@astrojs/starlight/props";
import type { Props } from '@astrojs/starlight/props'

import MobileMenuFooter from "@astrojs/starlight/components/MobileMenuFooter.astro";
import SidebarSublist from "@astrojs/starlight/components/SidebarSublist.astro";
import MobileMenuFooter from '@astrojs/starlight/components/MobileMenuFooter.astro'
import SidebarSublist from '@astrojs/starlight/components/SidebarSublist.astro'

const sidebar = (
Astro.props.sidebar.filter((k) =>
Astro.props.slug.startsWith("open-source")
? k.label === "open-source"
: k.label === "cloud"
Astro.props.slug.startsWith('open-source') ? k.label === 'open-source' : k.label === 'cloud'
)[0] as any
).entries;
).entries
---

<SidebarSublist sublist={sidebar} />
Expand Down
2 changes: 1 addition & 1 deletion packages/docs/src/global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ interface Window {
get_distinct_id: () => string
capture: (event: string, properties?: any) => void
}
}
}
4 changes: 2 additions & 2 deletions packages/docs/src/pages/index.astro
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
import StarlightPage from '@astrojs/starlight/components/StarlightPage.astro';
import { YouTube } from 'astro-embed';
import StarlightPage from '@astrojs/starlight/components/StarlightPage.astro'
import { YouTube } from 'astro-embed'
---

<StarlightPage
Expand Down
6 changes: 3 additions & 3 deletions packages/docs/src/pages/og/[...slug].ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ export const { getStaticPaths, GET } = OGImageRoute({
description: page.data.description,
logo: {
path: './src/assets/logo.png',
size: [120],
size: [120]
},
bgImage: {
path: './src/assets/og-bg.png'
},
format: 'PNG',
padding: 60,
quality: 100,
quality: 100
}
}
})
})
10 changes: 5 additions & 5 deletions packages/docs/tailwind.config.mjs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/** @type {import('tailwindcss').Config} */
export default {
content: ['./src/**/*.{astro,html,js,jsx,md,mdx,svelte,ts,tsx,vue}'],
theme: {
extend: {},
},
plugins: [],
content: ['./src/**/*.{astro,html,js,jsx,md,mdx,svelte,ts,tsx,vue}'],
theme: {
extend: {}
},
plugins: []
}
2 changes: 1 addition & 1 deletion packages/docs/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
"jsx": "react-jsx",
"jsxImportSource": "react"
}
}
}
2 changes: 1 addition & 1 deletion packages/orama/tests/boosting.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ t.test('boosting', (t) => {

const { hits: hits1 } = await search(db, {
term: 'computer for browsing and movies',
threshold: 1,
threshold: 1
})

const { hits: hits2 } = await search(db, {
Expand Down
2 changes: 1 addition & 1 deletion packages/orama/tests/search.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ t.test('search method', (t) => {

const result = await search(db, {
term: 'coffee',
threshold: 1,
threshold: 1
})

const matchedIds = result.hits.map((d) => d.id)
Expand Down
Loading
Loading