use of com.eden.orchid.api.theme.pages.OrchidPage 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.orchid.api.theme.pages.OrchidPage in project Orchid by JavaEden.
the class OrchidIndex method toJSON.
public JSONObject toJSON() {
JSONObject indexJson = new JSONObject();
indexJson.put("ownKey", ownKey);
if (ownPages.size() > 0) {
JSONArray ownPagesJson = new JSONArray();
for (OrchidPage page : ownPages) {
ownPagesJson.put(page.toJSON());
}
indexJson.put("ownPages", ownPagesJson);
}
if (childrenPages.keySet().size() > 0) {
JSONObject childrenPagesJson = new JSONObject();
for (Map.Entry<String, OrchidIndex> childIndex : childrenPages.entrySet()) {
childrenPagesJson.put(childIndex.getKey(), childIndex.getValue().toJSON());
}
indexJson.put("childrenPages", childrenPagesJson);
}
return indexJson;
}
use of com.eden.orchid.api.theme.pages.OrchidPage in project Orchid by JavaEden.
the class OrchidGenerators method indexGenerator.
private void indexGenerator(OrchidGenerator generator) {
Clog.d("Indexing generator: #{$1}:[#{$2 | className}]", generator.getPriority(), generator);
List<? extends OrchidPage> generatorPages = generator.startIndexing();
if (!EdenUtils.isEmpty(generator.getName()) && generatorPages != null && generatorPages.size() > 0) {
OrchidInternalIndex index = new OrchidInternalIndex(generator.getName());
for (OrchidPage page : generatorPages) {
index.addToIndex(generator.getName() + "/" + page.getReference().getPath(), page);
if (page.getResource() instanceof FreeableResource) {
((FreeableResource) page.getResource()).free();
}
}
this.internalIndex.addChildIndex(generator.getName(), index);
}
}
use of com.eden.orchid.api.theme.pages.OrchidPage in project Orchid by JavaEden.
the class Theme method scripts.
public String scripts() {
String scripts = "<!-- start:inject scripts -->";
for (OrchidPage script : context.getIndex().find("assets/js")) {
scripts += "<script src=\"" + script.getLink() + "\"></script>";
}
scripts += "<!-- end:inject scripts -->";
return scripts;
}
use of com.eden.orchid.api.theme.pages.OrchidPage in project Orchid by JavaEden.
the class OrchidContextImpl method getSiteData.
@Override
public Map<String, Object> getSiteData(Object... data) {
Map<String, Object> siteData = new HashMap<>();
Map<String, ?> root = getRoot().toMap();
for (String key : root.keySet()) {
siteData.put(key, root.get(key));
}
if (data != null && data.length > 0) {
if (data[0] instanceof OrchidPage) {
OrchidPage page = (OrchidPage) data[0];
siteData.put("page", page);
if (!EdenUtils.isEmpty(page.getType()) && !page.getType().equalsIgnoreCase("page")) {
siteData.put(page.getType(), page);
}
Map<String, OrchidComponent> pageComponents = page.getComponents();
for (Map.Entry<String, OrchidComponent> componentEntry : pageComponents.entrySet()) {
siteData.put(componentEntry.getKey(), componentEntry.getValue());
}
} else if (data[0] instanceof OrchidComponent) {
OrchidComponent component = (OrchidComponent) data[0];
siteData.put("component", component);
if (!EdenUtils.isEmpty(component.getAlias()) && !component.getAlias().equalsIgnoreCase("component")) {
siteData.put(component.getAlias(), component);
}
} else if (data[0] instanceof JSONObject) {
JSONObject jsonObject = (JSONObject) data[0];
siteData.put("data", jsonObject);
for (String key : jsonObject.keySet()) {
siteData.put(key, jsonObject.get(key));
}
} else if (data[0] instanceof Map) {
Map<String, ?> map = (Map<String, ?>) data[0];
siteData.put("data", map);
for (String key : map.keySet()) {
siteData.put(key, map.get(key));
}
} else if (data[0] instanceof JSONArray) {
JSONArray jsonArray = (JSONArray) data[0];
siteData.put("data", jsonArray);
} else if (data[0] instanceof Collection) {
Collection collection = (Collection) data[0];
siteData.put("data", collection);
}
}
siteData.put("root", root);
siteData.put("theme", getTheme());
siteData.put("index", getIndex());
siteData.put("site", this);
return siteData;
}
Aggregations