Added support for subdirectories in the HTML parser.

This commit is contained in:
CalDescent 2021-07-14 18:03:51 +01:00
parent 182dcc7e5f
commit 53f44a4029
2 changed files with 4 additions and 3 deletions

View File

@ -13,8 +13,9 @@ public class HTMLParser {
private String linkPrefix;
public HTMLParser(String resourceId, boolean usePrefix) {
this.linkPrefix = usePrefix ? "/site/" + resourceId : "";
public HTMLParser(String resourceId, String inPath, boolean usePrefix) {
String inPathWithoutFilename = inPath.substring(0, inPath.lastIndexOf('/'));
this.linkPrefix = usePrefix ? String.format("/site/%s%s", resourceId, inPathWithoutFilename) : "";
}
/**

View File

@ -335,7 +335,7 @@ public class WebsiteResource {
if (HTMLParser.isHtmlFile(filename)) {
// HTML file - needs to be parsed
byte[] data = Files.readAllBytes(Paths.get(filePath)); // TODO: limit file size that can be read into memory
HTMLParser htmlParser = new HTMLParser(resourceId, usePrefix);
HTMLParser htmlParser = new HTMLParser(resourceId, inPath, usePrefix);
data = htmlParser.replaceRelativeLinks(filename, data);
response.setContentType(context.getMimeType(filename));
response.setContentLength(data.length);