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