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

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

commit aa03cb604a31224678a20958ca3bdb2dee5b31aa
Author: Robert Munteanu <robert@localhost>
AuthorDate: Tue Jul 24 23:28:18 2018 +0200

    Ensure that index.md files take precedence over other files.
---
 .../mdresource/impl/MarkdownResourceProvider.java   | 21 +++++++++++++--------
 1 file changed, 13 insertions(+), 8 deletions(-)

diff --git 
a/mdresourceprovider/src/main/java/org/apache/sling/mdresource/impl/MarkdownResourceProvider.java
 
b/mdresourceprovider/src/main/java/org/apache/sling/mdresource/impl/MarkdownResourceProvider.java
index 3e30f52..159d205 100644
--- 
a/mdresourceprovider/src/main/java/org/apache/sling/mdresource/impl/MarkdownResourceProvider.java
+++ 
b/mdresourceprovider/src/main/java/org/apache/sling/mdresource/impl/MarkdownResourceProvider.java
@@ -78,13 +78,13 @@ public class MarkdownResourceProvider extends 
ResourceProvider<Object> {
         
         log.info("getResource(" + path + ")");
         
-        // try .md file first
-        Path filePath = Paths.get(fsPath, path + ".md");
+        // try index.md file first
+        Path filePath = Paths.get(fsPath, path, "index.md");
         File backingFile = filePath.toFile();
         if ( !backingFile.exists() ) {
             log.info("File at " + filePath + " does not exist");
-            // try /index.md next
-            filePath = Paths.get(fsPath, path, "index.md");
+            // try direct file .md next
+            filePath = Paths.get(fsPath, path + ".md");
             backingFile = filePath.toFile();
             if ( !backingFile.exists() ) {
                 log.info("File at " + filePath + " does not exist");
@@ -117,10 +117,7 @@ public class MarkdownResourceProvider extends 
ResourceProvider<Object> {
 
     private Resource asResource(Path path, Path parent, ResolveContext<Object> 
ctx) {
         File backingFile = path.toFile();
-        if ( backingFile.isFile() && backingFile.canRead() && 
backingFile.getName().endsWith(".md") && 
!backingFile.getName().equals("index.md")) {
-            return asResource0(path, parent, ctx, backingFile);
-        }
-        
+
         if ( backingFile.isDirectory() ) {
             backingFile = new File(backingFile, "index.md");
             if ( backingFile.exists() && backingFile.canRead() ) {
@@ -128,6 +125,14 @@ public class MarkdownResourceProvider extends 
ResourceProvider<Object> {
             }
         }
         
+        if ( backingFile.isFile() && backingFile.canRead() && 
backingFile.getName().endsWith(".md") && 
!backingFile.getName().equals("index.md")) {
+               Path potentialDirectory = 
Paths.get(backingFile.getAbsolutePath().substring(0, 
backingFile.getAbsolutePath().length() - ".md".length() ));
+               if ( potentialDirectory.resolve("index.md").toFile().exists() ) 
{
+                       return null;
+               }
+            return asResource0(path, parent, ctx, backingFile);
+        }
+        
         return null;
     }
 

Reply via email to