From d350b66aa158758dccf790e641fb19cf1378a03f Mon Sep 17 00:00:00 2001 From: Matthieu Fesselier <contact@matthieufesselier.com> Date: Fri, 4 Feb 2022 16:53:56 +0100 Subject: [PATCH] update: add attributes on menu entry --- src/orbit-envoy.pug | 46 ++++++++++++++++++++++++++++++++ src/views/partials/menu-left.pug | 2 +- 2 files changed, 47 insertions(+), 1 deletion(-) diff --git a/src/orbit-envoy.pug b/src/orbit-envoy.pug index 5e460625..fbd7a968 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 b0c39659..efa045de 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') -- GitLab