@mel000000/weweb-dynamic-metadata 1.0.11 → 1.0.13

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,6 +1,6 @@
1
1
  {
2
2
  "name": "@mel000000/weweb-dynamic-metadata",
3
- "version": "1.0.11",
3
+ "version": "1.0.13",
4
4
  "type": "module",
5
5
  "description": "Generate dynamic metadata for WeWeb static exports",
6
6
  "main": "src/index.js",
@@ -18,7 +18,7 @@ async function readConfig() {
18
18
 
19
19
  return {
20
20
  supabase,
21
- outputDir, // Pass this through
21
+ outputDir,
22
22
  pages: pages.map(page => ({
23
23
  route: page.route,
24
24
  table: page.table,
@@ -65,18 +65,6 @@ function generateMetadataJs(metadataObject) {
65
65
  window.METADATA = ${JSON.stringify(metadataObject, null, 2)};`;
66
66
  }
67
67
 
68
- async function updateTemplateScriptSrc(templatePath, newSrc) {
69
- try {
70
- let content = await fs.readFile(templatePath, 'utf-8');
71
- content = content.replace(
72
- /<script src="\/article\/metadata\.js"><\/script>/,
73
- `<script src="${newSrc}"></script>`
74
- );
75
- await fs.writeFile(templatePath, content, 'utf-8');
76
- } catch (error) {
77
- // Silently fail - this is non-critical
78
- }
79
- }
80
68
 
81
69
  async function ensureTemplateExists(templatePath) {
82
70
  if (await fs.pathExists(templatePath)) return;
@@ -97,7 +85,7 @@ async function ensureTemplateExists(templatePath) {
97
85
  await fs.writeFile(templatePath, minimalTemplate, 'utf-8');
98
86
  }
99
87
 
100
- // ========== FIXED: Original working reference HTML ==========
88
+ // ========== reference HTML ==========
101
89
  function generateReferenceHtml(id, title, relativeTemplatePath) {
102
90
  return `<!DOCTYPE html>
103
91
  <html>
@@ -110,7 +98,7 @@ function generateReferenceHtml(id, title, relativeTemplatePath) {
110
98
  <script>
111
99
  (function() {
112
100
  // Store the ID in a global variable for the template to use
113
- window.CURRENT_ARTICLE_ID = ${JSON.stringify(String(id))};
101
+ window.__REFERENCE_CONTENT_ID = ${JSON.stringify(String(id))};
114
102
 
115
103
  // Fetch the template and replace the current document
116
104
  fetch('${relativeTemplatePath}')
@@ -123,7 +111,7 @@ function generateReferenceHtml(id, title, relativeTemplatePath) {
123
111
  })
124
112
  .catch(error => {
125
113
  console.error('Failed to load template:', error);
126
- document.body.innerHTML = '<h1>Error loading article</h1><p>Please refresh the page</p>';
114
+ document.body.innerHTML = '<h1>Error loading content</h1><p>Please refresh the page</p>';
127
115
  });
128
116
  })();
129
117
  </script>
@@ -164,11 +152,11 @@ export async function processFiles() {
164
152
  const baseDir = config.outputDir || getOutputDir();
165
153
 
166
154
  const paramDir = path.join(baseDir, routeName, '_param');
167
- const articleRootDir = path.join(baseDir, routeName);
155
+ const contentRootDir = path.join(baseDir, routeName);
168
156
  const templatePath = path.join(paramDir, 'index.html');
169
157
 
170
158
  await fs.ensureDir(paramDir);
171
- await fs.ensureDir(articleRootDir);
159
+ await fs.ensureDir(contentRootDir);
172
160
 
173
161
  // Ensure template exists and inject script
174
162
  await ensureTemplateExists(templatePath);
@@ -191,38 +179,26 @@ export async function processFiles() {
191
179
 
192
180
  // Write metadata.js
193
181
  const metadataObj = Object.fromEntries(metadataMap);
194
- const metadataJsPath = path.join(articleRootDir, 'metadata.js');
182
+ const metadataJsPath = path.join(contentRootDir, 'metadata.js');
195
183
  await fs.writeFile(metadataJsPath, generateMetadataJs(metadataObj));
196
184
 
197
185
  // Copy to _param for compatibility
198
186
  await fs.copyFile(metadataJsPath, path.join(paramDir, 'metadata.js'));
199
187
 
200
- // Update template script src
201
- await updateTemplateScriptSrc(templatePath, '/article/metadata.js');
202
188
 
203
189
  // Create reference files using the ORIGINAL working logic
204
190
  const relativeTemplatePath = '../_param/index.html';
205
- let referencesCreated = 0;
206
191
 
207
192
  for (const [id, metadata] of metadataMap.entries()) {
208
193
  try {
209
- const articleDir = path.join(baseDir, routeName, id);
210
- await fs.ensureDir(articleDir);
194
+ const contentDir = path.join(baseDir, routeName, id);
195
+ await fs.ensureDir(contentDir);
211
196
 
212
197
  await fs.writeFile(
213
- path.join(articleDir, 'index.html'),
198
+ path.join(contentDir, 'index.html'),
214
199
  generateReferenceHtml(id, metadata.title, relativeTemplatePath)
215
200
  );
216
201
 
217
- // Create a small metadata.js reference
218
- const articleMetadataJsPath = path.join(articleDir, 'metadata.js');
219
- const metadataReference = `// Reference to central metadata file
220
- // This file points to the main metadata.js
221
- // The actual metadata is loaded from /article/metadata.js`;
222
-
223
- await fs.writeFile(articleMetadataJsPath, metadataReference, 'utf-8');
224
-
225
- referencesCreated++;
226
202
  } catch (error) {
227
203
  // Silently continue
228
204
  }
@@ -234,11 +210,10 @@ export async function processFiles() {
234
210
  succeeded: successCount,
235
211
  failed: failCount,
236
212
  metadataEntries: metadataMap.size,
237
- referencesCreated
238
213
  });
239
214
 
240
215
  summary.totalMetadataEntries += metadataMap.size;
241
- summary.outputDirectories.push(articleRootDir);
216
+ summary.outputDirectories.push(contentRootDir);
242
217
  }
243
218
 
244
219
  summary.duration = ((Date.now() - startTime) / 1000).toFixed(2);
@@ -1,8 +1,9 @@
1
1
  // src/templates/metadata-injector.js
2
2
  export async function metadata_injector_script(page) {
3
+ const baseRoute = page.route.split('/')[1];
3
4
  return `
4
5
  <!-- METADATA INJECTOR -->
5
- <script src="/${page.route}/metadata.js"></script>
6
+ <script src="/${baseRoute}/metadata.js"></script>
6
7
 
7
8
  <script>
8
9
  (function() {
@@ -17,12 +18,12 @@ export async function metadata_injector_script(page) {
17
18
  const parts = path.split('/').filter(p => p.length);
18
19
 
19
20
  // Case 1: /content/2
20
- if (parts[0] === ${JSON.stringify(page.route)} && parts[1] && parts[1] !== '_param') {
21
+ if (parts[0] === ${JSON.stringify(baseRoute)} && parts[1] && parts[1] !== '_param') {
21
22
  return parts[1];
22
23
  }
23
24
 
24
25
  // Case 2: /content/_param/?id=2
25
- if (parts[0] === ${JSON.stringify(page.route)} && parts[1] === '_param') {
26
+ if (parts[0] === ${JSON.stringify(baseRoute)} && parts[1] === '_param') {
26
27
  return new URLSearchParams(window.location.search).get('id');
27
28
  }
28
29