@marvalt/wadapter 2.3.40 → 2.3.41
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/index.esm.js +15 -13
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +15 -13
- package/dist/index.js.map +1 -1
- package/dist/utils/wordpress-menu.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/index.esm.js
CHANGED
|
@@ -937,23 +937,25 @@ function buildMenuStructure(pages, baseUrl = '/', filterPublished = true) {
|
|
|
937
937
|
*/
|
|
938
938
|
function convertMenuItemsToMenuStructure(menuItems, baseUrl = '/') {
|
|
939
939
|
return menuItems.map(item => {
|
|
940
|
-
//
|
|
940
|
+
// Preserve external URLs, convert internal absolute URLs to relative paths
|
|
941
941
|
let url = item.url;
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
// Invalid URL, keep as is
|
|
942
|
+
const isExternalUrl = url.startsWith('http://') || url.startsWith('https://');
|
|
943
|
+
if (isExternalUrl) ;
|
|
944
|
+
else {
|
|
945
|
+
// For relative URLs, ensure they start with /
|
|
946
|
+
if (!url.startsWith('/')) {
|
|
947
|
+
url = `/${url}`;
|
|
949
948
|
}
|
|
950
949
|
}
|
|
951
|
-
// Ensure URL starts with /
|
|
952
|
-
if (!url.startsWith('/')) {
|
|
953
|
-
url = `/${url}`;
|
|
954
|
-
}
|
|
955
950
|
// Extract slug from URL (remove leading/trailing slashes)
|
|
956
|
-
|
|
951
|
+
// For external URLs, use the title as slug or a sanitized version
|
|
952
|
+
let slug;
|
|
953
|
+
if (isExternalUrl) {
|
|
954
|
+
slug = item.title.toLowerCase().replace(/\s+/g, '-').replace(/[^a-z0-9-]/g, '') || 'external';
|
|
955
|
+
}
|
|
956
|
+
else {
|
|
957
|
+
slug = url.replace(/^\/+|\/+$/g, '') || 'home';
|
|
958
|
+
}
|
|
957
959
|
const menuItem = {
|
|
958
960
|
id: item.id,
|
|
959
961
|
title: item.title,
|