-
Notifications
You must be signed in to change notification settings - Fork 326
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixes Image Sources #459
Fixes Image Sources #459
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,7 +29,7 @@ public void shouldNotAddBodyHTMLElement(){ | |
Map<String, Object> fileContent = new HashMap<String, Object>(); | ||
fileContent.put(Attributes.ROOTPATH, "../../../"); | ||
fileContent.put(Attributes.URI, "blog/2017/05/first_post.html"); | ||
fileContent.put(Attributes.BODY, "<div> Test <img src='blog/2017/05/first.jpg' /></div>"); | ||
fileContent.put(Attributes.BODY, "<div> Test <img src='/blog/2017/05/first.jpg' /></div>"); | ||
|
||
HtmlUtil.fixImageSourceUrls(fileContent, config); | ||
|
||
|
@@ -40,34 +40,50 @@ public void shouldNotAddBodyHTMLElement(){ | |
|
||
} | ||
|
||
@Test | ||
public void shouldNotAddSiteHost(){ | ||
Map<String, Object> fileContent = new HashMap<String, Object>(); | ||
fileContent.put(Attributes.ROOTPATH, "../../../"); | ||
fileContent.put(Attributes.URI, "blog/2017/05/first_post.html"); | ||
fileContent.put(Attributes.BODY, "<div> Test <img src='./first.jpg' /></div>"); | ||
config.setProperty(ConfigUtil.Keys.IMG_PATH_PREPEND_HOST,false); | ||
|
||
HtmlUtil.fixImageSourceUrls(fileContent, config); | ||
|
||
String body = fileContent.get(Attributes.BODY).toString(); | ||
|
||
assertThat(body).contains("src=\"../../../blog/2017/05/first.jpg\""); | ||
|
||
} | ||
|
||
@Test | ||
public void shouldAddRootpath(){ | ||
public void shouldAddContentPath(){ | ||
Map<String, Object> fileContent = new HashMap<String, Object>(); | ||
fileContent.put(Attributes.ROOTPATH, "../../../"); | ||
fileContent.put(Attributes.URI, "blog/2017/05/first_post.html"); | ||
fileContent.put(Attributes.BODY, "<div> Test <img src='blog/2017/05/first.jpg' /></div>"); | ||
fileContent.put(Attributes.BODY, "<div> Test <img src='./first.jpg' /></div>"); | ||
|
||
HtmlUtil.fixImageSourceUrls(fileContent, config); | ||
|
||
String body = fileContent.get(Attributes.BODY).toString(); | ||
|
||
assertThat(body).contains("src=\"http://www.jbake.org/blog/2017/05/first.jpg\""); | ||
assertThat(body).contains("src=\"http://www.jbake.org/../../../blog/2017/05/first.jpg\""); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. hmm. I would have expected the url without the Attributes.ROOTPATH here. |
||
|
||
} | ||
|
||
@Test | ||
public void shouldAddContentpath(){ | ||
public void shouldAddContentPathForCurrentDirectory(){ | ||
Map<String, Object> fileContent = new HashMap<String, Object>(); | ||
fileContent.put(Attributes.ROOTPATH, "../../../"); | ||
fileContent.put(Attributes.URI, "blog/2017/05/first_post.html"); | ||
fileContent.put(Attributes.BODY, "<div> Test <img src='./first.jpg' /></div>"); | ||
fileContent.put(Attributes.BODY, "<div> Test <img src='first.jpg' /></div>"); | ||
|
||
HtmlUtil.fixImageSourceUrls(fileContent, config); | ||
|
||
String body = fileContent.get(Attributes.BODY).toString(); | ||
assertThat(body).contains("src=\"http://www.jbake.org/blog/2017/05/first.jpg\""); | ||
|
||
assertThat(body).contains("src=\"http://www.jbake.org/../../../blog/2017/05/first.jpg\""); | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same here. it's a strange looking url. as long as the site.host is present do we really need to append the rootpath here? the uri is relative to the website root already, isn't it? |
||
} | ||
|
||
@Test | ||
|
@@ -86,12 +102,12 @@ public void shouldNotAddRootPath(){ | |
} | ||
|
||
@Test | ||
public void shouldAddRootPathForNoExtension(){ | ||
public void shouldNotAddRootPathForNoExtension(){ | ||
Map<String, Object> fileContent = new HashMap<String, Object>(); | ||
fileContent.put(Attributes.ROOTPATH, "../../../"); | ||
fileContent.put(Attributes.URI, "blog/2017/05/first_post.html"); | ||
fileContent.put(Attributes.NO_EXTENSION_URI, "blog/2017/05/first_post/"); | ||
fileContent.put(Attributes.BODY, "<div> Test <img src='blog/2017/05/first.jpg' /></div>"); | ||
fileContent.put(Attributes.BODY, "<div> Test <img src='/blog/2017/05/first.jpg' /></div>"); | ||
|
||
HtmlUtil.fixImageSourceUrls(fileContent, config); | ||
|
||
|
@@ -113,7 +129,7 @@ public void shouldAddContentPathForNoExtension(){ | |
|
||
String body = fileContent.get(Attributes.BODY).toString(); | ||
|
||
assertThat(body).contains("src=\"http://www.jbake.org/blog/2017/05/first.jpg\""); | ||
assertThat(body).contains("src=\"http://www.jbake.org/../../../blog/2017/05/first.jpg\""); | ||
} | ||
|
||
@Test | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will only work for the first_post.html file. if it is an post shown with content on the index page the url would be wrong openening the file directly from a browser. on the index page it should be
blog/2017/05/first.jpg
.