@clidey/dory 0.33.3 → 0.34.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@clidey/dory",
3
3
  "private": false,
4
- "version": "0.33.3",
4
+ "version": "0.34.0",
5
5
  "type": "module",
6
6
  "description": "A CLI tool for building and previewing documentation sites",
7
7
  "keywords": [
@@ -76,6 +76,7 @@
76
76
  "sass-embedded": "^1.89.2",
77
77
  "sirv": "^3.0.1",
78
78
  "tailwindcss": "^4.1.16",
79
+ "terser": "^5.44.1",
79
80
  "tsx": "^4.20.4",
80
81
  "typescript": "~5.8.3",
81
82
  "unist-util-visit": "^5.0.0",
@@ -85,7 +86,6 @@
85
86
  },
86
87
  "packageManager": "pnpm@10.10.0+sha512.d615db246fe70f25dcfea6d8d73dee782ce23e2245e3c4f6f888249fb568149318637dca73c2c5c8ef2a4ca0d5657fb9567188bfab47f566d1ee6ce987815c39",
87
88
  "devDependencies": {
88
- "@types/node": "^24.0.12",
89
- "terser": "^5.44.1"
89
+ "@types/node": "^24.0.12"
90
90
  }
91
91
  }
@@ -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
- await Promise.all(
116
- preloadedFrontMatter.map(async (fm) => {
117
- const fileEntry = fileEntries.find(([filePath]) => pathFromFilename(filePath) === fm.path);
118
- if (fileEntry) {
119
- const [, loader] = fileEntry;
120
- const rawContent = (await loader()).default;
121
- const { content } = parseFrontMatter(rawContent);
122
-
123
- searchIndex.add({
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)
@@ -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
+ }
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
  ],