@clidey/dory 0.33.4 → 0.34.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +2 -2
- package/src/components/store.ts +9 -20
- package/src/embed/loader.ts +1 -2
- package/src/embed/widget-iframe.ts +3 -0
- package/src/plugins/docs-assets.ts +5 -1
- package/src/plugins/frontmatter-generator.ts +6 -4
- package/src/plugins/manifest-generator.ts +57 -0
- package/vite.config.embed-widget.ts +8 -11
- package/vite.config.ts +3 -0
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@clidey/dory",
|
|
3
3
|
"private": false,
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.34.1",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"description": "A CLI tool for building and previewing documentation sites",
|
|
7
7
|
"keywords": [
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
},
|
|
35
35
|
"scripts": {
|
|
36
36
|
"dev": "vite",
|
|
37
|
-
"build": "npm run build:cli && tsc -b && vite build",
|
|
37
|
+
"build": "npm run build:cli && tsc -b && vite build && npm run build:embed",
|
|
38
38
|
"build:cli": "tsc -p tsconfig.bin.json",
|
|
39
39
|
"build:docs": "tsc -b && vite build",
|
|
40
40
|
"build:embed": "npm run build:embed:loader && npm run build:embed:widget",
|
package/src/components/store.ts
CHANGED
|
@@ -108,27 +108,16 @@ export async function preloadFrontmatter() {
|
|
|
108
108
|
// Add preloaded content to search index
|
|
109
109
|
async function addPreloadedContentToSearch() {
|
|
110
110
|
if (!preloadedFrontMatter) return;
|
|
111
|
-
|
|
112
|
-
const mdxFiles = import.meta.glob<{ default: string }>('../../docs/**/*.mdx', { query: 'raw' });
|
|
113
|
-
const fileEntries = Object.entries(mdxFiles);
|
|
114
111
|
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
url: fm.path,
|
|
125
|
-
title: fm.title || '',
|
|
126
|
-
content,
|
|
127
|
-
pageTitle: fm.title || ''
|
|
128
|
-
});
|
|
129
|
-
}
|
|
130
|
-
})
|
|
131
|
-
);
|
|
112
|
+
// Content is already included in the preloaded frontmatter, no need to fetch raw files
|
|
113
|
+
preloadedFrontMatter.forEach((fm) => {
|
|
114
|
+
searchIndex.add({
|
|
115
|
+
url: fm.path,
|
|
116
|
+
title: fm.title || '',
|
|
117
|
+
content: fm.content || '',
|
|
118
|
+
pageTitle: fm.title || ''
|
|
119
|
+
});
|
|
120
|
+
});
|
|
132
121
|
}
|
|
133
122
|
|
|
134
123
|
// Load frontmatter for a specific pathname (optimized with fallback)
|
package/src/embed/loader.ts
CHANGED
|
@@ -47,9 +47,8 @@ if (typeof window !== 'undefined' && window.DoryDocs) {
|
|
|
47
47
|
widgetLoading = true;
|
|
48
48
|
widgetLoadPromise = new Promise((resolve, reject) => {
|
|
49
49
|
const script = document.createElement('script');
|
|
50
|
-
script.src = `${baseUrl}/embed-widget.js`;
|
|
50
|
+
script.src = `${config.baseUrl}/embed-widget.js`;
|
|
51
51
|
script.async = true;
|
|
52
|
-
script.type = 'module';
|
|
53
52
|
|
|
54
53
|
script.onload = () => {
|
|
55
54
|
// Widget script exposes window.__DoryWidget__
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Plugin } from 'vite';
|
|
2
|
-
import { cpSync, existsSync, readdirSync, statSync } from 'fs';
|
|
2
|
+
import { cpSync, existsSync, readdirSync, statSync, mkdirSync } from 'fs';
|
|
3
3
|
import { resolve, extname } from 'path';
|
|
4
4
|
|
|
5
5
|
/**
|
|
@@ -57,6 +57,10 @@ export function docsAssetsPlugin(): Plugin {
|
|
|
57
57
|
const stats = statSync(srcPath);
|
|
58
58
|
|
|
59
59
|
if (stats.isDirectory()) {
|
|
60
|
+
// Create destination directory if it doesn't exist
|
|
61
|
+
if (!existsSync(destPath)) {
|
|
62
|
+
mkdirSync(destPath, { recursive: true });
|
|
63
|
+
}
|
|
60
64
|
// Recursively copy directories
|
|
61
65
|
copyAssets(srcPath, destPath, itemRelativePath);
|
|
62
66
|
} else if (stats.isFile()) {
|
|
@@ -109,12 +109,13 @@ function generateFrontmatterJson(docsDir: string): Array<Record<string, any>> {
|
|
|
109
109
|
|
|
110
110
|
const filePath = mdxFilesMap[fileKey];
|
|
111
111
|
const rawContent = fs.readFileSync(filePath, 'utf-8');
|
|
112
|
-
const { data } = parseFrontmatter(rawContent);
|
|
112
|
+
const { data, content } = parseFrontmatter(rawContent);
|
|
113
113
|
const pathname = pathFromFilename(filePath, docsDir);
|
|
114
114
|
|
|
115
115
|
frontmatterArray.push({
|
|
116
116
|
...data,
|
|
117
|
-
path: pathname
|
|
117
|
+
path: pathname,
|
|
118
|
+
content: content.trim()
|
|
118
119
|
});
|
|
119
120
|
}
|
|
120
121
|
|
|
@@ -123,12 +124,13 @@ function generateFrontmatterJson(docsDir: string): Array<Record<string, any>> {
|
|
|
123
124
|
for (const fileKey of extraKeys) {
|
|
124
125
|
const filePath = mdxFilesMap[fileKey];
|
|
125
126
|
const rawContent = fs.readFileSync(filePath, 'utf-8');
|
|
126
|
-
const { data } = parseFrontmatter(rawContent);
|
|
127
|
+
const { data, content } = parseFrontmatter(rawContent);
|
|
127
128
|
const pathname = pathFromFilename(filePath, docsDir);
|
|
128
129
|
|
|
129
130
|
frontmatterArray.push({
|
|
130
131
|
...data,
|
|
131
|
-
path: pathname
|
|
132
|
+
path: pathname,
|
|
133
|
+
content: content.trim()
|
|
132
134
|
});
|
|
133
135
|
}
|
|
134
136
|
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import type { Plugin } from 'vite';
|
|
2
|
+
import { readFileSync, existsSync } from 'fs';
|
|
3
|
+
import { resolve } from 'path';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Plugin to generate manifest.json for PWA support
|
|
7
|
+
*/
|
|
8
|
+
export function manifestGenerator(): Plugin {
|
|
9
|
+
return {
|
|
10
|
+
name: 'manifest-generator',
|
|
11
|
+
generateBundle() {
|
|
12
|
+
const docsDir = resolve(process.cwd(), 'docs');
|
|
13
|
+
const doryJsonPath = resolve(docsDir, 'dory.json');
|
|
14
|
+
|
|
15
|
+
// Read dory.json to get site configuration
|
|
16
|
+
let config: any = {
|
|
17
|
+
name: 'Documentation',
|
|
18
|
+
description: 'Technical Documentation'
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
if (existsSync(doryJsonPath)) {
|
|
22
|
+
try {
|
|
23
|
+
config = JSON.parse(readFileSync(doryJsonPath, 'utf-8'));
|
|
24
|
+
} catch (error) {
|
|
25
|
+
console.warn('⚠️ Failed to parse dory.json for manifest generation');
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// Generate manifest.json content
|
|
30
|
+
const manifest = {
|
|
31
|
+
name: config.name || 'Documentation',
|
|
32
|
+
short_name: config.name || 'Docs',
|
|
33
|
+
description: config.description || 'Technical Documentation',
|
|
34
|
+
start_url: '/',
|
|
35
|
+
display: 'standalone',
|
|
36
|
+
theme_color: '#000000',
|
|
37
|
+
background_color: '#ffffff',
|
|
38
|
+
icons: [
|
|
39
|
+
{
|
|
40
|
+
src: '/favicon.svg',
|
|
41
|
+
sizes: 'any',
|
|
42
|
+
type: 'image/svg+xml'
|
|
43
|
+
}
|
|
44
|
+
]
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
// Emit the manifest.json file
|
|
48
|
+
this.emitFile({
|
|
49
|
+
type: 'asset',
|
|
50
|
+
fileName: 'manifest.json',
|
|
51
|
+
source: JSON.stringify(manifest, null, 2)
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
console.log('✅ Generated manifest.json');
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
}
|
|
@@ -3,11 +3,14 @@ import { resolve } from 'path';
|
|
|
3
3
|
|
|
4
4
|
export default defineConfig({
|
|
5
5
|
build: {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
6
|
+
rollupOptions: {
|
|
7
|
+
input: resolve(__dirname, 'src/embed/widget-iframe.ts'),
|
|
8
|
+
output: {
|
|
9
|
+
entryFileNames: 'embed-widget.js',
|
|
10
|
+
format: 'iife',
|
|
11
|
+
name: '__DoryWidget__',
|
|
12
|
+
inlineDynamicImports: true,
|
|
13
|
+
},
|
|
11
14
|
},
|
|
12
15
|
outDir: 'dist',
|
|
13
16
|
emptyOutDir: false,
|
|
@@ -21,11 +24,5 @@ export default defineConfig({
|
|
|
21
24
|
safari10: true,
|
|
22
25
|
},
|
|
23
26
|
},
|
|
24
|
-
rollupOptions: {
|
|
25
|
-
output: {
|
|
26
|
-
format: 'es',
|
|
27
|
-
inlineDynamicImports: false,
|
|
28
|
-
},
|
|
29
|
-
},
|
|
30
27
|
},
|
|
31
28
|
});
|
package/vite.config.ts
CHANGED
|
@@ -10,6 +10,7 @@ import { frontmatterDevServer } from './src/plugins/frontmatter-dev-server';
|
|
|
10
10
|
import { docsAssetsPlugin } from './src/plugins/docs-assets';
|
|
11
11
|
import { htmlMetadataInjector } from './src/plugins/html-metadata-injector';
|
|
12
12
|
import { htmlFilesMiddleware } from './src/plugins/html-files-middleware';
|
|
13
|
+
import { manifestGenerator } from './src/plugins/manifest-generator';
|
|
13
14
|
import { getMdxConfig } from './src/config/mdx';
|
|
14
15
|
|
|
15
16
|
export default defineConfig(({ command }) => ({
|
|
@@ -25,6 +26,7 @@ export default defineConfig(({ command }) => ({
|
|
|
25
26
|
llmTxtDevServer(),
|
|
26
27
|
frontmatterGenerator(),
|
|
27
28
|
frontmatterDevServer(),
|
|
29
|
+
manifestGenerator(),
|
|
28
30
|
docsAssetsPlugin(),
|
|
29
31
|
htmlMetadataInjector(),
|
|
30
32
|
],
|
|
@@ -39,6 +41,7 @@ export default defineConfig(({ command }) => ({
|
|
|
39
41
|
allowedHosts: true,
|
|
40
42
|
port: 3000,
|
|
41
43
|
strictPort: false,
|
|
44
|
+
cors: true,
|
|
42
45
|
},
|
|
43
46
|
json: {
|
|
44
47
|
stringify: false
|