Added a TextProvider with filter.
This commit is contained in:
parent
c7ba01380e
commit
3a1ecfe524
@ -6,23 +6,37 @@ import com.jessebrault.ssg.util.ExtensionUtil
|
||||
import org.slf4j.Logger
|
||||
import org.slf4j.LoggerFactory
|
||||
|
||||
import java.util.function.BiPredicate
|
||||
|
||||
final class TextsProviders {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(TextsProviders)
|
||||
|
||||
static CollectionProvider<Text> from(File textsDir, Collection<TextType> types) {
|
||||
from(textsDir, types) { file, relativePath -> true }
|
||||
}
|
||||
|
||||
static CollectionProvider<Text> from(
|
||||
File textsDir,
|
||||
Collection<TextType> textTypes,
|
||||
BiPredicate<File, String> filter
|
||||
) {
|
||||
CollectionProviders.fromDirectory(textsDir) { file, relativePath ->
|
||||
def extension = ExtensionUtil.getExtension(relativePath)
|
||||
if (extension) {
|
||||
def textType = types.find { it.ids.contains(extension) }
|
||||
if (!textType) {
|
||||
logger.warn('there is no TextType for file {}; skipping', file)
|
||||
return null
|
||||
if (filter.test(file, relativePath)) {
|
||||
def extension = ExtensionUtil.getExtension(relativePath)
|
||||
if (extension) {
|
||||
def textType = textTypes.find { it.ids.contains(extension) }
|
||||
if (!textType) {
|
||||
logger.warn('there is no TextType for file {}; skipping', file)
|
||||
return null
|
||||
} else {
|
||||
return new Text(relativePath, textType, file.getText())
|
||||
}
|
||||
} else {
|
||||
return new Text(relativePath, textType, file.getText())
|
||||
logger.debug('there is no extension for file {}; skipping', file)
|
||||
return null
|
||||
}
|
||||
} else {
|
||||
logger.debug('there is no extension for file {}; skipping', file)
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user