From 97508e5e8c18385938863c5e31b9e8cab70d6e59 Mon Sep 17 00:00:00 2001 From: Jonathan Bullock Date: Tue, 28 Aug 2018 13:52:07 +0100 Subject: [PATCH] Rebased PR and updated to use new config model - #340 --- .../app/configuration/DefaultJBakeConfiguration.java | 8 ++++++++ .../org/jbake/app/configuration/JBakeConfiguration.java | 5 +++++ .../java/org/jbake/app/configuration/JBakeProperty.java | 1 + jbake-core/src/main/java/org/jbake/util/HtmlUtil.java | 6 ++---- jbake-core/src/test/java/org/jbake/util/HtmlUtilTest.java | 2 +- 5 files changed, 17 insertions(+), 5 deletions(-) diff --git a/jbake-core/src/main/java/org/jbake/app/configuration/DefaultJBakeConfiguration.java b/jbake-core/src/main/java/org/jbake/app/configuration/DefaultJBakeConfiguration.java index 804d5052f..35c27eac3 100644 --- a/jbake-core/src/main/java/org/jbake/app/configuration/DefaultJBakeConfiguration.java +++ b/jbake-core/src/main/java/org/jbake/app/configuration/DefaultJBakeConfiguration.java @@ -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); + } } diff --git a/jbake-core/src/main/java/org/jbake/app/configuration/JBakeConfiguration.java b/jbake-core/src/main/java/org/jbake/app/configuration/JBakeConfiguration.java index a44de370f..51a762e5d 100644 --- a/jbake-core/src/main/java/org/jbake/app/configuration/JBakeConfiguration.java +++ b/jbake-core/src/main/java/org/jbake/app/configuration/JBakeConfiguration.java @@ -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 */ diff --git a/jbake-core/src/main/java/org/jbake/app/configuration/JBakeProperty.java b/jbake-core/src/main/java/org/jbake/app/configuration/JBakeProperty.java index 052cad701..d33ec23d1 100644 --- a/jbake-core/src/main/java/org/jbake/app/configuration/JBakeProperty.java +++ b/jbake-core/src/main/java/org/jbake/app/configuration/JBakeProperty.java @@ -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() {} diff --git a/jbake-core/src/main/java/org/jbake/util/HtmlUtil.java b/jbake-core/src/main/java/org/jbake/util/HtmlUtil.java index c425e1ed8..1f0c0c1e4 100644 --- a/jbake-core/src/main/java/org/jbake/util/HtmlUtil.java +++ b/jbake-core/src/main/java/org/jbake/util/HtmlUtil.java @@ -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 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(); diff --git a/jbake-core/src/test/java/org/jbake/util/HtmlUtilTest.java b/jbake-core/src/test/java/org/jbake/util/HtmlUtilTest.java index a107dd1c6..43355f4fb 100644 --- a/jbake-core/src/test/java/org/jbake/util/HtmlUtilTest.java +++ b/jbake-core/src/test/java/org/jbake/util/HtmlUtilTest.java @@ -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, "
Test
"); - config.setProperty(ConfigUtil.Keys.IMG_PATH_PREPEND_HOST,false); + config.setImgPathPrependHost(false); HtmlUtil.fixImageSourceUrls(fileContent, config);