Search in sources :

Example 11 with OrchidPage

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;
}
Also used : OrchidPage(com.eden.orchid.api.theme.pages.OrchidPage) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) JSONArray(org.json.JSONArray) EdenPair(com.eden.common.util.EdenPair)

Example 12 with OrchidPage

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;
}
Also used : OrchidPage(com.eden.orchid.api.theme.pages.OrchidPage) JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray) Map(java.util.Map) HashMap(java.util.HashMap)

Example 13 with OrchidPage

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);
    }
}
Also used : OrchidPage(com.eden.orchid.api.theme.pages.OrchidPage) FreeableResource(com.eden.orchid.api.resources.resource.FreeableResource) OrchidInternalIndex(com.eden.orchid.impl.indexing.OrchidInternalIndex)

Example 14 with OrchidPage

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;
}
Also used : OrchidPage(com.eden.orchid.api.theme.pages.OrchidPage)

Example 15 with OrchidPage

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;
}
Also used : OrchidPage(com.eden.orchid.api.theme.pages.OrchidPage) HashMap(java.util.HashMap) JSONArray(org.json.JSONArray) JSONObject(org.json.JSONObject) OrchidComponent(com.eden.orchid.api.theme.components.OrchidComponent) Collection(java.util.Collection) JSONObject(org.json.JSONObject) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

OrchidPage (com.eden.orchid.api.theme.pages.OrchidPage)22 OrchidResource (com.eden.orchid.api.resources.resource.OrchidResource)7 HashMap (java.util.HashMap)7 OrchidContext (com.eden.orchid.api.OrchidContext)6 ArrayList (java.util.ArrayList)5 TemplateTag (com.eden.orchid.api.compilers.TemplateTag)4 StringResource (com.eden.orchid.api.resources.resource.StringResource)4 OrchidResponse (com.eden.orchid.api.server.OrchidResponse)4 OrchidReference (com.eden.orchid.api.theme.pages.OrchidReference)4 PebbleWrapperTemplateTag (com.eden.orchid.impl.compilers.pebble.PebbleWrapperTemplateTag)4 Map (java.util.Map)4 JSONArray (org.json.JSONArray)4 JSONObject (org.json.JSONObject)3 TemplateFunction (com.eden.orchid.api.compilers.TemplateFunction)2 AssetPage (com.eden.orchid.api.theme.assets.AssetPage)2 OrchidInternalIndex (com.eden.orchid.impl.indexing.OrchidInternalIndex)2 SafeString (com.mitchellbosecke.pebble.extension.escaper.SafeString)2 Clog (com.caseyjbrooks.clog.Clog)1 JSONElement (com.eden.common.json.JSONElement)1 EdenPair (com.eden.common.util.EdenPair)1