Skip to content

Commit

Permalink
Only scan a limited number of lines for a headers block separator.
Browse files Browse the repository at this point in the history
  • Loading branch information
OndraZizka committed Oct 26, 2018
1 parent 2026116 commit 462023f
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
package org.jbake.app.configuration;

import org.apache.commons.configuration.CompositeConfiguration;
import org.apache.commons.configuration.Configuration;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.apache.commons.configuration.CompositeConfiguration;
import org.apache.commons.configuration.Configuration;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* The default implementation of a {@link JBakeConfiguration}
Expand All @@ -32,6 +31,9 @@ public class DefaultJBakeConfiguration implements JBakeConfiguration {
private Logger logger = LoggerFactory.getLogger(DefaultJBakeConfiguration.class);
private CompositeConfiguration compositeConfiguration;

public static final int MAX_HEADER_LINES_DEFAULT = 50;


/**
* Some deprecated implementations just need access to the configuration without access to the source folder
*
Expand Down Expand Up @@ -468,6 +470,12 @@ public String getVersion() {
return getAsString(JBakeProperty.VERSION);
}

@Override
public int getMaxHeaderLinesScan()
{
return getAsInt(JBakeProperty.MAX_HEADER_LINES_SCAN, MAX_HEADER_LINES_DEFAULT);
}

public void setDestinationFolderName(String folderName) {
setProperty(JBakeProperty.DESTINATION_FOLDER, folderName);
setupDefaultDestination();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,12 @@ public interface JBakeConfiguration {
*/
String getVersion();

/**
* @return Maximum lines to scan when looking for a JBake in-file header.
*/
int getMaxHeaderLinesScan();


/**
* Set a property value for the given key
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public class JBakeProperty {
public static final String IMG_PATH_UPDATE = "img.path.update";
public static final String IMG_PATH_PREPEND_HOST = "img.path.prepend.host";
public static final String VERSION = "version";
public static final String MAX_HEADER_LINES_SCAN = "header.maxLines";

private JBakeProperty() {}

Expand Down
6 changes: 2 additions & 4 deletions jbake-core/src/main/java/org/jbake/parser/MarkupEngine.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,6 @@ public abstract class MarkupEngine implements ParserEngine {

private JBakeConfiguration configuration;

public static final int MAX_HEADER_LINES = 50;


/**
* Tests if this markup engine can process the document.
*
Expand Down Expand Up @@ -174,9 +171,10 @@ private boolean hasHeader2(Configuration config, List<String> contents) {

List<String> headerLines = new ArrayList<>();

int scanMaxLines = configuration.getMaxHeaderLinesScan();

//for (String line : contents) {
for (int i = 0; i < contents.size() && i < MAX_HEADER_LINES; i++) {
for (int i = 0; i < contents.size() && i < scanMaxLines; i++) {
String line = contents.get(i);
if (StringUtils.isBlank(line))
continue;
Expand Down
4 changes: 3 additions & 1 deletion jbake-core/src/main/resources/default.properties
Original file line number Diff line number Diff line change
Expand Up @@ -116,4 +116,6 @@ header.separator=~~~~~~
# update image path
img.path.update=false
# Prepend site.host to image paths
img.path.prepend.host=true
img.path.prepend.host=true
# JBake will only scan this number of lines for a headers block separator.
header.maxLines=50

0 comments on commit 462023f

Please sign in to comment.