use of com.eden.common.util.EdenPair in project Orchid by JavaEden.
the class PostsGenerator method startIndexing.
@Override
public List<? extends OrchidPage> startIndexing() {
// Map category names to pairs of PostPages and PostArchivePages
Map<String, EdenPair<List<PostPage>, List<PostArchivePage>>> categories = new HashMap<>();
List<String> categoryNames = new ArrayList<>();
if (OrchidUtils.elementIsArray(context.query("options.posts.categories"))) {
JSONArray categoriesArray = (JSONArray) context.query("options.posts.categories").getElement();
for (int i = 0; i < categoriesArray.length(); i++) {
if (!EdenUtils.isEmpty(categoriesArray.getString(i))) {
categoryNames.add(categoriesArray.getString(i));
}
}
} else {
categoryNames.add(null);
}
for (String category : categoryNames) {
List<PostPage> posts = getPostsList(category);
List<PostArchivePage> archive = buildArchive(category, posts);
categories.put(category, new EdenPair<>(posts, archive));
}
List<OrchidPage> allPages = new ArrayList<>();
for (String key : categories.keySet()) {
allPages.addAll(categories.get(key).first);
allPages.addAll(categories.get(key).second);
}
return allPages;
}
use of com.eden.common.util.EdenPair in project Orchid by JavaEden.
the class FrontMatterPrecompiler method parseFrontMatter.
private EdenPair<JSONObject, Integer> parseFrontMatter(String input) {
if (input.startsWith("---")) {
Matcher m = Pattern.compile("^---(\\w+)?$", Pattern.MULTILINE).matcher(input);
int matches = 0;
int fmStart = 0;
int fmEnd = 0;
int contentStart = 0;
// if we find a match, get the group
while (m.find()) {
if (matches == 0) {
fmStart = m.end();
matches++;
} else if (matches == 1) {
fmEnd = m.start();
contentStart = m.end();
matches++;
break;
}
}
if (matches == 2) {
String parsedType = input.substring(0, fmStart).replaceAll("---", "");
List<String> extensions = new ArrayList<>();
if (!EdenUtils.isEmpty(parsedType)) {
extensions.add(parsedType);
}
if (!EdenUtils.isEmpty(context.query("options.frontMatterExt"))) {
extensions.add(context.query("options.frontMatterExt").toString());
}
extensions.add(defaultType);
final String frontMatterText = input.substring(fmStart, fmEnd);
JSONObject frontMatter = extensions.stream().map(ext -> context.getTheme().parse(ext, frontMatterText)).filter(OrchidUtils::elementIsObject).map(el -> (JSONObject) el.getElement()).findFirst().orElseGet(JSONObject::new);
return new EdenPair<>(frontMatter, contentStart);
}
}
return new EdenPair<>(null, 0);
}
Aggregations