@marvalt/wadapter 2.3.40 → 2.3.42

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.js CHANGED
@@ -940,23 +940,29 @@ function buildMenuStructure(pages, baseUrl = '/', filterPublished = true) {
940
940
  */
941
941
  function convertMenuItemsToMenuStructure(menuItems, baseUrl = '/') {
942
942
  return menuItems.map(item => {
943
- // Convert URL to relative path if it's absolute
943
+ // Preserve external URLs, convert internal absolute URLs to relative paths
944
944
  let url = item.url;
945
- if (url.startsWith('http://') || url.startsWith('https://')) {
946
- try {
947
- const urlObj = new URL(url);
948
- url = urlObj.pathname + urlObj.search + urlObj.hash;
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}`;
949
951
  }
950
- catch (e) {
951
- // Invalid URL, keep as is
952
+ // Remove trailing slash (except for root path) to match React Router routes
953
+ if (url !== '/' && url.endsWith('/')) {
954
+ url = url.slice(0, -1);
952
955
  }
953
956
  }
954
- // Ensure URL starts with /
955
- if (!url.startsWith('/')) {
956
- url = `/${url}`;
957
- }
958
957
  // Extract slug from URL (remove leading/trailing slashes)
959
- const slug = url.replace(/^\/+|\/+$/g, '') || 'home';
958
+ // For external URLs, use the title as slug or a sanitized version
959
+ let slug;
960
+ if (isExternalUrl) {
961
+ slug = item.title.toLowerCase().replace(/\s+/g, '-').replace(/[^a-z0-9-]/g, '') || 'external';
962
+ }
963
+ else {
964
+ slug = url.replace(/^\/+|\/+$/g, '') || 'home';
965
+ }
960
966
  const menuItem = {
961
967
  id: item.id,
962
968
  title: item.title,