You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by cz...@apache.org on 2024/09/12 06:51:19 UTC

(sling-whiteboard) branch master updated: Update title handling

This is an automated email from the ASF dual-hosted git repository.

cziegeler pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-whiteboard.git


The following commit(s) were added to refs/heads/master by this push:
     new 3136a51c Update title handling
3136a51c is described below

commit 3136a51c2eded0df1740de96ff1268c628fe2259
Author: Carsten Ziegeler <cz...@apache.org>
AuthorDate: Thu Sep 12 08:51:11 2024 +0200

    Update title handling
---
 .../java/org/apache/sling/mdresource/impl/HtmlServlet.java   | 12 +++++++++++-
 .../mdresource/impl/md/handler/YamlFrontMatterHandler.java   |  1 -
 2 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/mdresourcedecorator/src/main/java/org/apache/sling/mdresource/impl/HtmlServlet.java b/mdresourcedecorator/src/main/java/org/apache/sling/mdresource/impl/HtmlServlet.java
index 794bbc5a..dcdd726d 100644
--- a/mdresourcedecorator/src/main/java/org/apache/sling/mdresource/impl/HtmlServlet.java
+++ b/mdresourcedecorator/src/main/java/org/apache/sling/mdresource/impl/HtmlServlet.java
@@ -81,7 +81,12 @@ public class HtmlServlet extends HttpServlet {
         pw.println("<html>");
         pw.println("<head>");
         final ValueMap props = request.getResource().getValueMap();
-        final String title = props.get("jcr:title", String.class);
+        boolean hasMainHeading = true;
+        String title = props.get("jcr:title", String.class);
+        if ( title == null ) {
+            title = props.get("title", String.class);
+            hasMainHeading = false;
+        }
         if (title != null) {
             pw.print("<title>");
             pw.print(title);
@@ -102,6 +107,11 @@ public class HtmlServlet extends HttpServlet {
         if (html instanceof String) {
             pw.println(html.toString());
         } else if (html instanceof List) {
+            if (!hasMainHeading) {
+                pw.print("<h1>");
+                pw.print(title);
+                pw.println("</h1>");
+            }
             boolean startSection = true;
             for (final Map.Entry<String, String> element : (List<Map.Entry<String,String>>) html) {
                 if (startSection) {
diff --git a/mdresourcedecorator/src/main/java/org/apache/sling/mdresource/impl/md/handler/YamlFrontMatterHandler.java b/mdresourcedecorator/src/main/java/org/apache/sling/mdresource/impl/md/handler/YamlFrontMatterHandler.java
index a7b53477..854569c0 100644
--- a/mdresourcedecorator/src/main/java/org/apache/sling/mdresource/impl/md/handler/YamlFrontMatterHandler.java
+++ b/mdresourcedecorator/src/main/java/org/apache/sling/mdresource/impl/md/handler/YamlFrontMatterHandler.java
@@ -47,7 +47,6 @@ public class YamlFrontMatterHandler implements NodeHandler {
                 result.properties.put(entry.getKey(), entry.getValue().toArray(new String[0]));
             }
         }
-
         return true;
     }
 }