diff --git a/src/orbit-envoy.pug b/src/orbit-envoy.pug index 5e460625a63b21dc54d8590155b728141b6936d4..fbd7a9685a320ce021f8fb33e9e37eb3a5514de8 100644 --- a/src/orbit-envoy.pug +++ b/src/orbit-envoy.pug @@ -139,6 +139,52 @@ for component of components component.attributes.route = component.route; component.attributes.uniq = component.uniq; } + if(component.menuAttributes) { + let federation = new Set(); + if(client.server) { + federation.add(client.server); + } + if(client.servers) { + for(server of client.servers) { + federation.add(server); + } + } + if(component.federation) { + for(target of component.federation) { + federation.add(target); + } + } + component.federation = [...federation]; + for(const [attribute, path] of Object.entries(component.menuAttributes)) { + if(typeof path === 'string') { + if(path.startsWith('federation://')) { + let contains = generateUrl(federation, path); + if(contains.length > 1) { + federations[`store://local.${component.uniq}/${attribute}/`] = { + "@cache": "false", + "@context": "https://cdn.happy-dev.fr/owl/hdcontext.jsonld", + "@type": "ldp:Container", + "@id": `store://local.${component.uniq}/${attribute}/`, + "ldp:contains": contains, + "permissions": [{"mode": {"@type": "view"}}] + }; + component.menuAttributes[attribute] = `store://local.${component.uniq}/${attribute}/`; + } else { + component.menuAttributes[attribute] = federation.values().next().value + path.replace(/federation:\//, ''); + } + } + if(path.startsWith('server://')) { + component.menuAttributes[attribute] = client.server + path.replace(/server:\//, ''); + } + } + } + /* Rewrite every parameters to kebab-case */ + let rewriteParameters = {}; + for(const [attribute, value] of Object.entries(component.menuAttributes)) { + rewriteParameters[attribute.replace(/((?<=[a-z\d])[A-Z]|(?<=[A-Z\d])[A-Z](?=[a-z]))/g, '-$1').toLowerCase()] = value; + } + component.menuAttributes = rewriteParameters; + } if(component.extensions) { for(extension of component.extensions) { if(extension.parameters) { diff --git a/src/views/partials/menu-left.pug b/src/views/partials/menu-left.pug index b0c396590becc965c0654d8824e1f8811a7edf07..efa045de58c53d0411c51699c8cfb5e8e34532f6 100644 --- a/src/views/partials/menu-left.pug +++ b/src/views/partials/menu-left.pug @@ -183,7 +183,7 @@ solid-router#navbar-router(default-route=defaultRoute) if component.experimental if component.experimental.includes('menu') div.jsMenuTab - #{"solid-"+component.type+"-menu"} + #{"solid-"+component.type+"-menu"}&attributes(component.menuAttributes) div.divider if componentSet.has('registering')