Skip to content

Commit

Permalink
Rebased PR and updated to use new config model - jbake-org#340
Browse files Browse the repository at this point in the history
  • Loading branch information
jonbullock committed Aug 28, 2018
1 parent 46a1960 commit 97508e5
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -531,4 +531,12 @@ public void setHeaderSeparator(String headerSeparator) {
setProperty(JBakeProperty.HEADER_SEPARATOR, headerSeparator);
}

@Override
public boolean getImgPathPrependHost() {
return getAsBoolean(JBakeProperty.IMG_PATH_PREPEND_HOST);
}

public void setImgPathPrependHost(boolean imgPathPrependHost) {
setProperty(JBakeProperty.IMG_PATH_PREPEND_HOST, imgPathPrependHost);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,11 @@ public interface JBakeConfiguration {
*/
boolean getUriWithoutExtension();

/**
* @return Flag indicating if image paths should be prepended with {@link #getSiteHost()} value
*/
boolean getImgPathPrependHost();

/**
* @return Version of JBake
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public class JBakeProperty {
public static final String THYMELEAF_LOCALE = "thymeleaf.locale";
public static final String URI_NO_EXTENSION = "uri.noExtension";
public static final String URI_NO_EXTENSION_PREFIX = "uri.noExtension.prefix";
public static final String IMG_PATH_PREPEND_HOST = "img.path.prepend.host";
public static final String VERSION = "version";

private JBakeProperty() {}
Expand Down
6 changes: 2 additions & 4 deletions jbake-core/src/main/java/org/jbake/util/HtmlUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,12 @@ public class HtmlUtil {
* @param fileContents Map representing file contents
* @param configuration Configuration object
*/

//TODO: use JBakeConfiguration
public static void fixImageSourceUrls(Map<String, Object> fileContents, JBakeConfiguration configuration){

String htmlContent = fileContents.get(Attributes.BODY).toString();

boolean prependSiteHost = config.getBoolean(Keys.IMG_PATH_PREPEND_HOST);
String siteHost = config.getString(Keys.SITE_HOST);
boolean prependSiteHost = configuration.getImgPathPrependHost();
String siteHost = configuration.getSiteHost();
String rootPath = fileContents.get(Attributes.ROOTPATH).toString();
String uri = fileContents.get(Attributes.URI).toString();

Expand Down
2 changes: 1 addition & 1 deletion jbake-core/src/test/java/org/jbake/util/HtmlUtilTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public void shouldNotAddSiteHost(){
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);
config.setImgPathPrependHost(false);

HtmlUtil.fixImageSourceUrls(fileContent, config);

Expand Down

0 comments on commit 97508e5

Please sign in to comment.