@mel000000/weweb-dynamic-metadata 1.0.12 → 1.0.14
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
|
@@ -18,7 +18,7 @@ async function readConfig() {
|
|
|
18
18
|
|
|
19
19
|
return {
|
|
20
20
|
supabase,
|
|
21
|
-
outputDir,
|
|
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
|
-
// ==========
|
|
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.
|
|
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}')
|
|
@@ -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
|
|
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(
|
|
159
|
+
await fs.ensureDir(contentRootDir);
|
|
172
160
|
|
|
173
161
|
// Ensure template exists and inject script
|
|
174
162
|
await ensureTemplateExists(templatePath);
|
|
@@ -191,14 +179,12 @@ export async function processFiles() {
|
|
|
191
179
|
|
|
192
180
|
// Write metadata.js
|
|
193
181
|
const metadataObj = Object.fromEntries(metadataMap);
|
|
194
|
-
const metadataJsPath = path.join(
|
|
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';
|
|
@@ -206,21 +192,21 @@ export async function processFiles() {
|
|
|
206
192
|
|
|
207
193
|
for (const [id, metadata] of metadataMap.entries()) {
|
|
208
194
|
try {
|
|
209
|
-
const
|
|
210
|
-
await fs.ensureDir(
|
|
195
|
+
const contentDir = path.join(baseDir, routeName, id);
|
|
196
|
+
await fs.ensureDir(contentDir);
|
|
211
197
|
|
|
212
198
|
await fs.writeFile(
|
|
213
|
-
path.join(
|
|
199
|
+
path.join(contentDir, 'index.html'),
|
|
214
200
|
generateReferenceHtml(id, metadata.title, relativeTemplatePath)
|
|
215
201
|
);
|
|
216
202
|
|
|
217
203
|
// Create a small metadata.js reference
|
|
218
|
-
const
|
|
204
|
+
const contentMetadataJsPath = path.join(contentRootDir, 'metadata.js');
|
|
219
205
|
const metadataReference = `// Reference to central metadata file
|
|
220
206
|
// This file points to the main metadata.js
|
|
221
207
|
// The actual metadata is loaded from /article/metadata.js`;
|
|
222
208
|
|
|
223
|
-
await fs.writeFile(
|
|
209
|
+
await fs.writeFile(contentMetadataJsPath, metadataReference, 'utf-8');
|
|
224
210
|
|
|
225
211
|
referencesCreated++;
|
|
226
212
|
} catch (error) {
|
|
@@ -238,7 +224,7 @@ export async function processFiles() {
|
|
|
238
224
|
});
|
|
239
225
|
|
|
240
226
|
summary.totalMetadataEntries += metadataMap.size;
|
|
241
|
-
summary.outputDirectories.push(
|
|
227
|
+
summary.outputDirectories.push(contentRootDirRootDir);
|
|
242
228
|
}
|
|
243
229
|
|
|
244
230
|
summary.duration = ((Date.now() - startTime) / 1000).toFixed(2);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// src/templates/metadata-injector.js
|
|
2
2
|
export async function metadata_injector_script(page) {
|
|
3
|
-
const baseRoute = page.route.split('/')[
|
|
3
|
+
const baseRoute = page.route.split('/')[1];
|
|
4
4
|
return `
|
|
5
5
|
<!-- METADATA INJECTOR -->
|
|
6
6
|
<script src="/${baseRoute}/metadata.js"></script>
|