From 0e65a0b1eebcd3de3040f8e34ad3c7b71ad06756 Mon Sep 17 00:00:00 2001 From: Thorsten Marx Date: Thu, 6 Nov 2025 14:58:23 +0100 Subject: [PATCH] introduce node.properties --- .../cms/content/DefaultContentRenderer.java | 8 +-- .../condation/cms/content/NodeProperties.java | 54 +++++++++++++++++++ .../themes/demo/templates/libs/fragments.html | 2 +- 3 files changed, 56 insertions(+), 8 deletions(-) create mode 100644 cms-content/src/main/java/com/condation/cms/content/NodeProperties.java diff --git a/cms-content/src/main/java/com/condation/cms/content/DefaultContentRenderer.java b/cms-content/src/main/java/com/condation/cms/content/DefaultContentRenderer.java index 95503f72b..f04387f32 100644 --- a/cms-content/src/main/java/com/condation/cms/content/DefaultContentRenderer.java +++ b/cms-content/src/main/java/com/condation/cms/content/DefaultContentRenderer.java @@ -154,13 +154,7 @@ public String render(final ReadOnlyFile contentFile, final RequestContext contex namespace.add(Constants.TemplateNamespaces.NODE, "uri", uri); namespace.add(Constants.TemplateNamespaces.NODE, "translation", new NodeTranslations(contentNode.orElse(null), siteProperties)); - var canonicalUrl = ""; - if (contentNode.isPresent()) { - canonicalUrl = PathUtil.toURL(contentNode.get().uri()); - canonicalUrl = HTTPUtil.modifyUrl(canonicalUrl, siteProperties); - } - namespace.add(Constants.TemplateNamespaces.NODE, "canonicalUrl", canonicalUrl); - + namespace.add(Constants.TemplateNamespaces.NODE, "properties", new MapAccess((NodeProperties.createNodeProperties(contentNode.orElse(null), siteProperties)))); TagTemplateFunction tagFunction = createTagFunction(context); namespace.add(Constants.TemplateNamespaces.CMS, TagTemplateFunction.KEY, tagFunction); diff --git a/cms-content/src/main/java/com/condation/cms/content/NodeProperties.java b/cms-content/src/main/java/com/condation/cms/content/NodeProperties.java new file mode 100644 index 000000000..a60d0ac02 --- /dev/null +++ b/cms-content/src/main/java/com/condation/cms/content/NodeProperties.java @@ -0,0 +1,54 @@ +package com.condation.cms.content; + +/*- + * #%L + * cms-content + * %% + * Copyright (C) 2023 - 2025 CondationCMS + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * . + * #L% + */ + +import com.condation.cms.api.SiteProperties; +import com.condation.cms.api.db.ContentNode; +import com.condation.cms.api.utils.HTTPUtil; +import com.condation.cms.api.utils.PathUtil; +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; + +/** + * + * @author thorstenmarx + */ +public class NodeProperties { + + public static Map createNodeProperties (ContentNode node, SiteProperties siteProperties) { + + if (node == null) { + return Collections.emptyMap(); + } + + Map properties = new HashMap<>(); + + var canonicalUrl = PathUtil.toURL(node .uri()); + canonicalUrl = HTTPUtil.modifyUrl(canonicalUrl, siteProperties); + + properties.put("url", canonicalUrl); + + return properties; + } +} diff --git a/test-server/themes/demo/templates/libs/fragments.html b/test-server/themes/demo/templates/libs/fragments.html index 8127d2e57..b5751c1e7 100644 --- a/test-server/themes/demo/templates/libs/fragments.html +++ b/test-server/themes/demo/templates/libs/fragments.html @@ -1,7 +1,7 @@ {{node.meta.title}}