@mel000000/weweb-dynamic-metadata 1.0.18 → 1.0.19
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 +1 -1
- package/src/core/file-processor.js +23 -10
package/package.json
CHANGED
|
@@ -86,7 +86,7 @@ async function ensureTemplateExists(templatePath) {
|
|
|
86
86
|
}
|
|
87
87
|
|
|
88
88
|
// ========== reference HTML ==========
|
|
89
|
-
function generateReferenceHtml(id, title, relativeTemplatePath) {
|
|
89
|
+
function generateReferenceHtml(id, title, relativeTemplatePath, routeName) {
|
|
90
90
|
return `<!DOCTYPE html>
|
|
91
91
|
<html>
|
|
92
92
|
<head>
|
|
@@ -111,7 +111,7 @@ function generateReferenceHtml(id, title, relativeTemplatePath) {
|
|
|
111
111
|
})
|
|
112
112
|
.catch(error => {
|
|
113
113
|
console.error('Failed to load template:', error);
|
|
114
|
-
document.body.innerHTML = '<h1>Error loading
|
|
114
|
+
document.body.innerHTML = '<h1>Error loading content</h1><p>Please refresh the page</p>';
|
|
115
115
|
});
|
|
116
116
|
})();
|
|
117
117
|
</script>
|
|
@@ -122,11 +122,12 @@ function generateReferenceHtml(id, title, relativeTemplatePath) {
|
|
|
122
122
|
</noscript>
|
|
123
123
|
</head>
|
|
124
124
|
<body>
|
|
125
|
-
<p>Loading
|
|
125
|
+
<p>Loading content ${id}... <a href="${relativeTemplatePath}?id=${id}">Click here if not redirected</a></p>
|
|
126
126
|
</body>
|
|
127
127
|
</html>`;
|
|
128
128
|
}
|
|
129
129
|
|
|
130
|
+
|
|
130
131
|
// ========== MAIN PROCESSOR ==========
|
|
131
132
|
export async function processFiles() {
|
|
132
133
|
const startTime = Date.now();
|
|
@@ -148,13 +149,18 @@ export async function processFiles() {
|
|
|
148
149
|
const ids = await discoverIds(page);
|
|
149
150
|
|
|
150
151
|
// Setup paths
|
|
151
|
-
const routeName = page.
|
|
152
|
+
const routeName = page.routeName;
|
|
152
153
|
const baseDir = config.outputDir || getOutputDir();
|
|
153
154
|
|
|
154
155
|
const paramDir = path.join(baseDir, routeName, '_param');
|
|
155
156
|
const contentRootDir = path.join(baseDir, routeName);
|
|
156
157
|
const templatePath = path.join(paramDir, 'index.html');
|
|
157
158
|
|
|
159
|
+
console.log(`📁 Processing ${routeName}...`);
|
|
160
|
+
console.log(` IDs found: ${ids.length}`);
|
|
161
|
+
console.log(` Template path: ${templatePath}`);
|
|
162
|
+
console.log(` Content root: ${contentRootDir}`);
|
|
163
|
+
|
|
158
164
|
await fs.ensureDir(paramDir);
|
|
159
165
|
await fs.ensureDir(contentRootDir);
|
|
160
166
|
|
|
@@ -172,8 +178,10 @@ export async function processFiles() {
|
|
|
172
178
|
const metadata = await fetchMetadata(page, id);
|
|
173
179
|
metadataMap.set(String(id), metadata);
|
|
174
180
|
successCount++;
|
|
181
|
+
console.log(` ✅ Fetched metadata for ID: ${id}`);
|
|
175
182
|
} catch (error) {
|
|
176
183
|
failCount++;
|
|
184
|
+
console.error(` ❌ Failed to fetch ID ${id}:`, error.message);
|
|
177
185
|
}
|
|
178
186
|
}
|
|
179
187
|
|
|
@@ -181,33 +189,38 @@ export async function processFiles() {
|
|
|
181
189
|
const metadataObj = Object.fromEntries(metadataMap);
|
|
182
190
|
const metadataJsPath = path.join(contentRootDir, 'metadata.js');
|
|
183
191
|
await fs.writeFile(metadataJsPath, generateMetadataJs(metadataObj));
|
|
192
|
+
console.log(` 📝 Written metadata.js with ${metadataMap.size} entries`);
|
|
184
193
|
|
|
185
194
|
// Copy to _param for compatibility
|
|
186
195
|
await fs.copyFile(metadataJsPath, path.join(paramDir, 'metadata.js'));
|
|
187
196
|
|
|
188
|
-
|
|
189
|
-
// Create reference files
|
|
197
|
+
// Create reference files for each ID
|
|
190
198
|
const relativeTemplatePath = '../_param/index.html';
|
|
191
199
|
let referencesCreated = 0;
|
|
192
|
-
|
|
200
|
+
|
|
193
201
|
for (const [id, metadata] of metadataMap.entries()) {
|
|
194
202
|
try {
|
|
203
|
+
// ✅ This creates the ID-specific directory (e.g., /article/1/)
|
|
195
204
|
const contentDir = path.join(baseDir, routeName, id);
|
|
196
205
|
await fs.ensureDir(contentDir);
|
|
197
206
|
|
|
207
|
+
// ✅ This writes the reference HTML to the ID directory
|
|
208
|
+
const indexPath = path.join(contentDir, 'index.html');
|
|
198
209
|
await fs.writeFile(
|
|
199
|
-
|
|
200
|
-
generateReferenceHtml(id, metadata.title, relativeTemplatePath, routeName)
|
|
210
|
+
indexPath,
|
|
211
|
+
generateReferenceHtml(id, metadata.title, relativeTemplatePath, routeName)
|
|
201
212
|
);
|
|
202
213
|
|
|
203
214
|
referencesCreated++;
|
|
215
|
+
console.log(` ✅ Created reference HTML for ID: ${id} at ${indexPath}`);
|
|
204
216
|
} catch (error) {
|
|
205
|
-
console.error(`Failed to create reference for ID ${id}:`, error.message);
|
|
217
|
+
console.error(` ❌ Failed to create reference for ID ${id}:`, error.message);
|
|
206
218
|
}
|
|
207
219
|
}
|
|
208
220
|
|
|
209
221
|
summary.pages.push({
|
|
210
222
|
route: page.route,
|
|
223
|
+
routeName: routeName,
|
|
211
224
|
total: ids.length,
|
|
212
225
|
succeeded: successCount,
|
|
213
226
|
failed: failCount,
|