Skip to content

Commit

Permalink
Version 1.8.6
Browse files Browse the repository at this point in the history
  • Loading branch information
rahmanusta committed Oct 14, 2023
1 parent bce0efb commit 3c23f20
Showing 1 changed file with 15 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.List;
Expand All @@ -26,7 +27,7 @@ public boolean handles(String target) {
public void process(Document document, PreprocessorReader reader, String target, Map<String, Object> attributes) {

Path dirPath = Paths.get(reader.getDir());
Path targetPath = dirPath.resolve(target);
Path targetPath = resolveTargetPath(document, dirPath, target);
String targetString = targetPath.toString();
String readed = reader.read();
String content = IOHelper.readFile(targetPath);
Expand All @@ -41,4 +42,17 @@ public void process(Document document, PreprocessorReader reader, String target,
reader.pushInclude(content, target, target, lineNumber, attributes);
}

private Path resolveTargetPath(Document document, Path dirPath, String target) {
Path resolvedPath = dirPath.resolve(target);
if (Files.exists(resolvedPath)) {
return resolvedPath;
}
// Alternative resolution for attributes-{lang}.adoc
Path alternatePath = Paths.get((String) document.getAttribute("docdir")).resolve(resolvedPath);
if (Files.exists(alternatePath)) {
return alternatePath;
}
return resolvedPath;
}

}

0 comments on commit 3c23f20

Please sign in to comment.