@marvalt/wadapter 2.3.44 → 2.3.45
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/dist/client/wordpress-client.d.ts +2 -1
- package/dist/client/wordpress-client.d.ts.map +1 -1
- package/dist/generators/wordpress/wordpress-generator.d.ts.map +1 -1
- package/dist/generators.cjs +244 -61
- package/dist/generators.cjs.map +1 -1
- package/dist/generators.esm.js +244 -61
- package/dist/generators.esm.js.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.esm.js +50 -2
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +50 -2
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -289,11 +289,59 @@ class WordPressClient {
|
|
|
289
289
|
}
|
|
290
290
|
/**
|
|
291
291
|
* Fetch a specific navigation menu with its items
|
|
292
|
-
*
|
|
292
|
+
* Handles both menu term IDs and wp_navigation post IDs
|
|
293
|
+
* @param menuId Menu ID (can be menu term ID or wp_navigation post ID)
|
|
293
294
|
* @returns Menu data with hierarchical items
|
|
294
295
|
*/
|
|
295
296
|
async getMenu(menuId) {
|
|
296
|
-
|
|
297
|
+
try {
|
|
298
|
+
// First try the custom endpoint (handles both menu terms and wp_navigation posts)
|
|
299
|
+
return await this.makeRequest(`/wp-custom/v1/menus/${menuId}`);
|
|
300
|
+
}
|
|
301
|
+
catch (error) {
|
|
302
|
+
// If 404, try fetching as wp_navigation post
|
|
303
|
+
if (error.status === 404 || error.message?.includes('404')) {
|
|
304
|
+
console.log(`⚠️ Menu ID ${menuId} not found as menu term, trying as wp_navigation post...`);
|
|
305
|
+
// Try custom endpoint first
|
|
306
|
+
try {
|
|
307
|
+
const navPost = await this.makeRequest(`/wp-custom/v1/navigation/${menuId}`);
|
|
308
|
+
if (navPost.menu) {
|
|
309
|
+
return navPost.menu;
|
|
310
|
+
}
|
|
311
|
+
// If navigation post has a menu_term_id, fetch that menu
|
|
312
|
+
if (navPost.menu_term_id) {
|
|
313
|
+
return await this.makeRequest(`/wp-custom/v1/menus/${navPost.menu_term_id}`);
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
catch (navError) {
|
|
317
|
+
// If custom endpoint fails, try WordPress native REST API (WordPress 6.3+)
|
|
318
|
+
if (navError.status === 404 || navError.message?.includes('404')) {
|
|
319
|
+
console.log(`⚠️ Custom navigation endpoint not found, trying WordPress native REST API...`);
|
|
320
|
+
try {
|
|
321
|
+
// WordPress 6.3+ has native REST API for wp_navigation posts
|
|
322
|
+
const navPost = await this.makeRequest(`/wp/v2/navigation/${menuId}`);
|
|
323
|
+
// Parse blocks from content to find menu reference
|
|
324
|
+
// The content.raw contains the block JSON
|
|
325
|
+
if (navPost.content?.raw) {
|
|
326
|
+
try {
|
|
327
|
+
const blocks = JSON.parse(navPost.content.raw);
|
|
328
|
+
// Look for menu reference in blocks (this would need to be done server-side)
|
|
329
|
+
// For now, return null and let the generator fall back to HTML extraction
|
|
330
|
+
console.log(`ℹ️ Found wp_navigation post ${menuId}, but menu extraction requires server-side processing`);
|
|
331
|
+
}
|
|
332
|
+
catch (parseError) {
|
|
333
|
+
console.log(`⚠️ Could not parse navigation post content`);
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
catch (wpError) {
|
|
338
|
+
// Fall through
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
throw error;
|
|
344
|
+
}
|
|
297
345
|
}
|
|
298
346
|
async getFooter(slug = 'footer', area = 'footer') {
|
|
299
347
|
return this.makeRequest(`/wp-custom/v1/footer`, { slug, area });
|