Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
micheleriva committed Oct 18, 2024
1 parent f3fe838 commit b74c886
Show file tree
Hide file tree
Showing 8 changed files with 239 additions and 28 deletions.
31 changes: 3 additions & 28 deletions packages/plugin-vitepress/src/Search.vue
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
<script lang='ts' setup>
import { onMounted } from 'vue'
import { useData } from 'vitepress'
import { ComponentLibrary} from '@orama/vue-components'
const VPData = useData()
$.colorScheme.value = VPData.isDark.value ? 'dark' : 'light'
// $.colorScheme.value = VPData.isDark.value ? 'dark' : 'light'
onMounted(async () => {
// @ts-expect-error - virtual:search-data is not globally defined
Expand All @@ -19,36 +18,12 @@ onMounted(async () => {
<ClientOnly>
<!-- should implement the searchbox here -->
<orama-chat-box
:orama-instance="oramaInstance"
:client-instance="oramaInstance"
/>

<div class="VPNavBarSearch search">
<div id="docsearch">
<button type="button" class="DocSearch DocSearch-Button" aria-label="Search" v-on:click="$.show.value = true">
<span class="DocSearch-Button-Container">
<svg
class="DocSearch-Search-Icon"
width="20"
height="20"
viewBox="0 0 20 20"
aria-label="search icon"
>
<path
d="M14.386 14.386l4.0877 4.0877-4.0877-4.0877c-2.9418 2.9419-7.7115 2.9419-10.6533 0-2.9419-2.9418-2.9419-7.7115 0-10.6533 2.9418-2.9419 7.7115-2.9419 10.6533 0 2.9419 2.9418 2.9419 7.7115 0 10.6533z"
stroke="currentColor"
fill="none"
fill-rule="evenodd"
stroke-linecap="round"
stroke-linejoin="round"
/>
</svg>
<span class="DocSearch-Button-Placeholder">Search</span>
</span>
<span class="DocSearch-Button-Keys">
<kbd class="DocSearch-Button-Key"></kbd>
<kbd class="DocSearch-Button-Key">K</kbd>
</span>
</button>
<!-- should implement search button here -->
</div>
</div>
</ClientOnly>
Expand Down
21 changes: 21 additions & 0 deletions packages/plugin-vitepress/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { AnySchema, create, insertMultiple, OramaPlugin } from '@orama/orama'
import { persist } from '@orama/plugin-data-persistence'
import { pluginPT15 } from '@orama/plugin-pt15'
import { pluginQPS } from '@orama/plugin-qps'
import { ComponentLibrary } from '@orama/vue-components'
import slugify from 'slugify'
import { readFileSync } from 'fs'

Expand Down Expand Up @@ -144,13 +145,32 @@ export function OramaPlugin(pluginOptions: OramaPluginOptions = { scoringAlgorit
}

const selfBuildEnd = vitepressConfig.buildEnd
const originalTransformHead = vitepressConfig.transformHead

vitepressConfig.buildEnd = (siteConfig: any) => {
selfBuildEnd?.(siteConfig)
siteConfig = Object.assign(siteConfig || {})
pluginSiteConfig?.buildEnd?.(siteConfig)
}

vitepressConfig.transformHead = async (ctx) => {
const head = await originalTransformHead?.(ctx) || []

// Add your custom head elements here if needed
head.push(['script', {}, `
import { createApp } from 'vue'
import { ComponentLibrary } from '@orama/vue-components'
if (typeof window !== 'undefined') {
window.__VUE_PROD_DEVTOOLS__ = true
const app = createApp({})
app.use(ComponentLibrary)
}
`])

return head
}

const selfTransformHead = vitepressConfig.transformHead

vitepressConfig.transformHead = async (ctx) => {
Expand All @@ -159,6 +179,7 @@ export function OramaPlugin(pluginOptions: OramaPluginOptions = { scoringAlgorit
return selfHead.concat(pluginHead)
}
},

config: () => ({
resolve: {
alias: {
Expand Down
1 change: 1 addition & 0 deletions sandboxes/vitepress-1.4.1/.vitepress/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
cache
34 changes: 34 additions & 0 deletions sandboxes/vitepress-1.4.1/.vitepress/config.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { defineConfig } from 'vitepress'
import { OramaPlugin } from '@orama/plugin-vitepress'

// https://vitepress.dev/reference/site-config
export default defineConfig({
title: "Vitepress Sandbox",
description: "A VitePress Site",
extends: {
vite: {
plugins: [OramaPlugin()]
}
},
themeConfig: {
// https://vitepress.dev/reference/default-theme-config
nav: [
{ text: 'Home', link: '/' },
{ text: 'Examples', link: '/markdown-examples' }
],

sidebar: [
{
text: 'Examples',
items: [
{ text: 'Markdown Examples', link: '/markdown-examples' },
{ text: 'Runtime API Examples', link: '/api-examples' }
]
}
],

socialLinks: [
{ icon: 'github', link: 'https://github.com/vuejs/vitepress' }
]
}
})
49 changes: 49 additions & 0 deletions sandboxes/vitepress-1.4.1/api-examples.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
---
outline: deep
---

# Runtime API Examples

This page demonstrates usage of some of the runtime APIs provided by VitePress.

The main `useData()` API can be used to access site, theme, and page data for the current page. It works in both `.md` and `.vue` files:

```md
<script setup>
import { useData } from 'vitepress'

const { theme, page, frontmatter } = useData()
</script>

## Results

### Theme Data
<pre>{{ theme }}</pre>

### Page Data
<pre>{{ page }}</pre>

### Page Frontmatter
<pre>{{ frontmatter }}</pre>
```

<script setup>
import { useData } from 'vitepress'

const { site, theme, page, frontmatter } = useData()
</script>

## Results

### Theme Data
<pre>{{ theme }}</pre>

### Page Data
<pre>{{ page }}</pre>

### Page Frontmatter
<pre>{{ frontmatter }}</pre>

## More

Check out the documentation for the [full list of runtime APIs](https://vitepress.dev/reference/runtime-api#usedata).
25 changes: 25 additions & 0 deletions sandboxes/vitepress-1.4.1/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
---
# https://vitepress.dev/reference/default-theme-home-page
layout: home

hero:
name: "Vitepress Sandbox"
text: "A VitePress Site"
tagline: My great project tagline
actions:
- theme: brand
text: Markdown Examples
link: /markdown-examples
- theme: alt
text: API Examples
link: /api-examples

features:
- title: Feature A
details: Lorem ipsum dolor sit amet, consectetur adipiscing elit
- title: Feature B
details: Lorem ipsum dolor sit amet, consectetur adipiscing elit
- title: Feature C
details: Lorem ipsum dolor sit amet, consectetur adipiscing elit
---

85 changes: 85 additions & 0 deletions sandboxes/vitepress-1.4.1/markdown-examples.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
# Markdown Extension Examples

This page demonstrates some of the built-in markdown extensions provided by VitePress.

## Syntax Highlighting

VitePress provides Syntax Highlighting powered by [Shikiji](https://github.com/antfu/shikiji), with additional features like line-highlighting:

**Input**

````md
```js{4}
export default {
data () {
return {
msg: 'Highlighted!'
}
}
}
```
````

**Output**

```js{4}
export default {
data () {
return {
msg: 'Highlighted!'
}
}
}
```

## Custom Containers

**Input**

```md
::: info
This is an info box.
:::

::: tip
This is a tip.
:::

::: warning
This is a warning.
:::

::: danger
This is a dangerous warning.
:::

::: details
This is a details block.
:::
```

**Output**

::: info
This is an info box.
:::

::: tip
This is a tip.
:::

::: warning
This is a warning.
:::

::: danger
This is a dangerous warning.
:::

::: details
This is a details block.
:::

## More

Check out the documentation for the [full list of markdown extensions](https://vitepress.dev/guide/markdown).
21 changes: 21 additions & 0 deletions sandboxes/vitepress-1.4.1/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"name": "vitepress-1.4.1",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"docs:dev": "vitepress dev",
"docs:build": "vitepress build",
"docs:preview": "vitepress preview"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"@orama/plugin-vitepress": "workspace:*"
},
"devDependencies": {
"vitepress": "1.0.0-rc.31"
}
}

0 comments on commit b74c886

Please sign in to comment.