Skip to content

Commit c187ef8

Browse files
committed
addition of demo site for test
1 parent 528daf9 commit c187ef8

8 files changed

Lines changed: 688 additions & 82 deletions

File tree

vitepress-plugin-moss/.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,6 @@ dist-ssr
5454

5555
# npm pack
5656
*.tgz
57+
58+
# Demo Site
59+
demo-site/

vitepress-plugin-moss/README.md

Lines changed: 18 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -163,86 +163,46 @@ If indexing fails (network error, bad credentials, etc.) the build **does not fa
163163

164164
---
165165

166-
## Testing the plugin locally
166+
## Testing Locally (Demo Site)
167+
168+
The repository includes a ready-to-use demo site in the `demo-site/` folder. This is the best way to test changes to the plugin.
167169

168170
### Step 1 — Build the plugin
169171

172+
First, build the plugin from the root directory to generate the `dist` folder.
173+
170174
```bash
171-
cd vitepress-plugin-moss
172175
pnpm install
173176
pnpm build
174-
# dist/ is now populated
175177
```
176178

177-
### Step 2 — Create a minimal test VitePress site
178-
179-
```bash
180-
mkdir /tmp/test-docs && cd /tmp/test-docs
181-
npm init -y
182-
npm install vitepress
183-
```
179+
### Step 2 — Set up the Demo Site
184180

185-
Add `"type": "module"` to the generated `package.json`:
186-
187-
```json
188-
{
189-
"name": "test-docs",
190-
"type": "module",
191-
...
192-
}
193-
```
194-
195-
Create some pages:
181+
Navigate to the demo site directory and install its dependencies.
196182

197183
```bash
198-
mkdir -p docs/.vitepress
199-
echo "# Home\n\nThis is the home page." > docs/index.md
200-
echo "# Guide\n\n## Installation\n\nRun npm install." > docs/guide.md
184+
cd demo-site
185+
npm install
201186
```
202187

203-
### Step 3 — Link the local plugin
188+
### Step 3 — Configure and Build
189+
190+
The demo site is already configured to use the local plugin. You just need to add your Moss credentials to `demo-site/docs/.vitepress/config.ts` (or use environment variables).
204191

205192
```bash
206-
# From inside /tmp/test-docs
207-
npm install /path/to/vitepress-plugin-moss
193+
# From inside demo-site/
194+
npx vitepress build docs
208195
```
209196

210-
### Step 4 — Configure VitePress
211-
212-
```ts
213-
// docs/.vitepress/config.ts
214-
import { defineConfig } from 'vitepress'
215-
import { mossIndexerPlugin } from 'vitepress-plugin-moss'
216-
217-
export default defineConfig({
218-
title: 'Test Docs',
219-
themeConfig: {
220-
search: {
221-
provider: 'moss' as any,
222-
options: {
223-
projectId: process.env.MOSS_PROJECT_ID!,
224-
projectKey: process.env.MOSS_PROJECT_KEY!,
225-
indexName: 'test-docs',
226-
},
227-
},
228-
},
229-
async buildEnd(siteConfig) {
230-
const plugin = await mossIndexerPlugin(siteConfig)
231-
if (typeof plugin.buildEnd === 'function') {
232-
await (plugin.buildEnd as Function).call({ environment: { name: 'client' } })
233-
}
234-
},
235-
})
236-
```
197+
### Step 4 — Preview
237198

238-
### Step 5 — Run the build
199+
Start the preview server to test the search modal.
239200

240201
```bash
241-
cd /tmp/test-docs
242-
MOSS_PROJECT_ID=xxx MOSS_PROJECT_KEY=yyy npx vitepress build docs
202+
npx vitepress preview docs
243203
```
244204

245-
You should see the indexing output described in [Build output](#build-output) above.
205+
Open [http://localhost:4173](http://localhost:4173) in your browser and verify the search functionality.
246206

247207
---
248208

vitepress-plugin-moss/env.d.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
declare module '*.png' {
2+
const value: string
3+
export default value
4+
}
5+
6+
declare module 'virtual:moss-config' {
7+
const getMossConfig: () => any
8+
export default getMossConfig
9+
}

vitepress-plugin-moss/index.ts

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -41,38 +41,34 @@ export function mossIndexerPlugin(): Plugin {
4141
}
4242
},
4343
configResolved(config) {
44-
console.error('[MossPlugin] configResolved called')
4544
siteConfig = (config as any).vitepress
4645
},
4746
load(id) {
4847
if (id === resolvedVirtualModuleId) {
4948
// If siteConfig isn't available yet or search isn't moss, return empty config
50-
if (siteConfig?.site?.themeConfig?.search?.provider !== 'moss') {
49+
const searchConfig = siteConfig?.site?.themeConfig?.search as any
50+
if (searchConfig?.provider !== 'moss') {
5151
return 'export default () => ({})'
5252
}
53-
const searchOptions = siteConfig.site.themeConfig.search.options || {}
53+
const searchOptions = searchConfig.options || {}
5454
return `export default () => (${JSON.stringify(searchOptions)})`
5555
}
5656
},
5757
async buildEnd() {
5858
// Only run when siteConfig is available and Moss search is enabled
59-
if (!siteConfig || siteConfig.site.themeConfig?.search?.provider !== 'moss') {
59+
const searchConfig = siteConfig.site.themeConfig?.search as any
60+
if (!siteConfig || searchConfig?.provider !== 'moss') {
6061
return
6162
}
6263

6364
// Only run for client build and only during production build
6465
// NOTE: environment.name is used in newer Vite/VitePress
6566
const environment = (this as any).environment
66-
if (
67-
(environment && environment.name !== 'client') ||
68-
process.env.NODE_ENV !== 'production'
69-
)
70-
return
71-
67+
7268
try {
7369
debug('Starting Moss index sync...')
7470

75-
const searchConfig = siteConfig.site.themeConfig?.search
71+
const searchConfig = siteConfig.site.themeConfig?.search as any
7672
const searchOptions =
7773
searchConfig?.provider === 'moss' ? searchConfig.options : undefined
7874

vitepress-plugin-moss/package.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,5 +56,9 @@
5656
"search",
5757
"semantic-search"
5858
],
59-
"license": "MIT"
59+
"license": "MIT",
60+
"author": "",
61+
"directories": {
62+
"doc": "docs"
63+
}
6064
}

0 commit comments

Comments
 (0)