Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
Original file line number Diff line number Diff line change
@@ -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
* <http://www.gnu.org/licenses/gpl-3.0.html>.
* #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<String, Object> createNodeProperties (ContentNode node, SiteProperties siteProperties) {

if (node == null) {
return Collections.emptyMap();
}

Map<String, Object> properties = new HashMap<>();

var canonicalUrl = PathUtil.toURL(node .uri());
canonicalUrl = HTTPUtil.modifyUrl(canonicalUrl, siteProperties);

properties.put("url", canonicalUrl);

return properties;
}
}
2 changes: 1 addition & 1 deletion test-server/themes/demo/templates/libs/fragments.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<title>{{node.meta.title}}</title>
<link
rel="canonical"
href="{{ node.canonicalUrl }}"
href="{{ node.properties["url"] }}"
/>
<link rel="shortcut icon" href="/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
Expand Down