Search in sources :

Example 1 with StringResource

use of com.eden.orchid.api.resources.resource.StringResource in project Orchid by JavaEden.

the class HomepageGenerator method startIndexing.

@Override
public List<? extends OrchidPage> startIndexing() {
    List<OrchidPage> pages = new ArrayList<>();
    OrchidResource resource = new StringResource(context, "index.twig", "");
    OrchidPage page = new OrchidPage(resource);
    page.getReference().setTitle("Home");
    page.setType("frontPage");
    page.addComponent("readme", ReadmeComponent.class);
    page.addComponent("license", LicenseComponent.class);
    pages.add(page);
    return pages;
}
Also used : OrchidPage(com.eden.orchid.api.theme.pages.OrchidPage) StringResource(com.eden.orchid.api.resources.resource.StringResource) OrchidResource(com.eden.orchid.api.resources.resource.OrchidResource) ArrayList(java.util.ArrayList)

Example 2 with StringResource

use of com.eden.orchid.api.resources.resource.StringResource in project Orchid by JavaEden.

the class PostsGenerator method buildArchive.

private List<PostArchivePage> buildArchive(String category, List<PostPage> posts) {
    List<PostArchivePage> archivePages = new ArrayList<>();
    int pageSize = 4;
    int pages = (int) Math.ceil(posts.size() / pageSize);
    for (int i = 0; i <= pages; i++) {
        String pageName = (!EdenUtils.isEmpty(category)) ? "archive/" + category + "/" + (i + 1) + ".html" : "archive/" + (i + 1) + ".html";
        OrchidReference pageRef = new OrchidReference(context, pageName);
        pageRef.setUsePrettyUrl(true);
        pageRef.setTitle("Archives (Page " + (i + 1) + ")");
        PostArchivePage page = new PostArchivePage(new StringResource("", pageRef));
        page.setPage(i + 1);
        page.setPageSize(pageSize);
        page.setTotalPages(posts.size());
        if (!EdenUtils.isEmpty(category)) {
            page.setCategory(category);
        }
        archivePages.add(page);
    }
    int i = 0;
    for (PostArchivePage post : archivePages) {
        if (next(posts, i) != null) {
            post.setNext(next(archivePages, i));
        }
        if (previous(posts, i) != null) {
            post.setPrevious(previous(archivePages, i));
        }
        i++;
    }
    return archivePages;
}
Also used : StringResource(com.eden.orchid.api.resources.resource.StringResource) OrchidReference(com.eden.orchid.api.theme.pages.OrchidReference) ArrayList(java.util.ArrayList)

Example 3 with StringResource

use of com.eden.orchid.api.resources.resource.StringResource in project Orchid by JavaEden.

the class WikiGenerator method setupGlossary.

private void setupGlossary() {
    OrchidResource glossary = resources.getLocalResourceEntry(wikiBaseDir + "GLOSSARY.md");
    if (glossary == null) {
        return;
    }
    String content = context.getTheme().compile(glossary.getReference().getExtension(), glossary.getContent());
    Document doc = Jsoup.parse(content);
    for (Element h2 : doc.select("h2")) {
        String id = h2.text().replaceAll("\\s+", "_").toLowerCase();
        String path = wikiBaseDir + "glossary/#" + id;
        String url = OrchidUtils.applyBaseUrl(context, path);
        Element link = new Element("a");
        link.attr("href", url);
        link.text(h2.text());
        h2.attr("id", id);
        h2.empty();
        h2.appendChild(link);
        JSONObject index = new JSONObject();
        index.put("name", h2.text());
        index.put("url", url);
        terms.add(index);
    }
    String safe = doc.toString();
    glossary = new StringResource(context, wikiBaseDir + "glossary.md", safe);
    glossary.getReference().setTitle("Glossary");
    WikiPage page = new WikiPage(glossary);
    page.getReference().setUsePrettyUrl(true);
    page.setType("wiki");
    wiki.add(page);
}
Also used : StringResource(com.eden.orchid.api.resources.resource.StringResource) JSONObject(org.json.JSONObject) OrchidResource(com.eden.orchid.api.resources.resource.OrchidResource) Element(org.jsoup.nodes.Element) Document(org.jsoup.nodes.Document)

Example 4 with StringResource

use of com.eden.orchid.api.resources.resource.StringResource in project Orchid by JavaEden.

the class WikiGenerator method setupSummary.

private void setupSummary() {
    OrchidResource summary = resources.getLocalResourceEntry(wikiBaseDir + "SUMMARY.md");
    if (summary == null) {
        return;
    }
    String content = context.getTheme().compile(summary.getReference().getExtension(), summary.getContent());
    Document doc = Jsoup.parse(content);
    Elements links = doc.select("a[href]");
    WikiPage previous = null;
    for (Element a : links) {
        String file = wikiBaseDir + a.attr("href");
        String path = wikiBaseDir + FilenameUtils.removeExtension(a.attr("href"));
        OrchidResource resource = resources.getLocalResourceEntry(file);
        if (resource == null) {
            Clog.w("Could not find wiki resource page at '#{$1}'", new Object[] { file });
            resource = new StringResource(context, path + File.separator + "index.md", a.text());
        }
        WikiPage page = new WikiPage(resource);
        if (!EdenUtils.isEmpty(FilenameUtils.getExtension(a.attr("href")))) {
            page.getReference().setUsePrettyUrl(true);
        } else {
            page.getReference().setUsePrettyUrl(true);
        }
        page.getReference().setTitle(a.text());
        page.setType("wiki");
        wiki.add(page);
        if (previous != null) {
            previous.setNext(page);
            page.setPrevious(previous);
            previous = page;
        } else {
            previous = page;
        }
        a.attr("href", page.getReference().toString());
    }
    String safe = doc.toString();
    summary = new StringResource(context, wikiBaseDir + "summary.md", safe);
    summary.getReference().setTitle("Summary");
    WikiPage page = new WikiPage(summary);
    page.getReference().setUsePrettyUrl(true);
    page.setType("wiki");
    wiki.add(page);
}
Also used : StringResource(com.eden.orchid.api.resources.resource.StringResource) OrchidResource(com.eden.orchid.api.resources.resource.OrchidResource) Element(org.jsoup.nodes.Element) Document(org.jsoup.nodes.Document) Elements(org.jsoup.select.Elements)

Aggregations

StringResource (com.eden.orchid.api.resources.resource.StringResource)4 OrchidResource (com.eden.orchid.api.resources.resource.OrchidResource)3 ArrayList (java.util.ArrayList)2 Document (org.jsoup.nodes.Document)2 Element (org.jsoup.nodes.Element)2 OrchidPage (com.eden.orchid.api.theme.pages.OrchidPage)1 OrchidReference (com.eden.orchid.api.theme.pages.OrchidReference)1 JSONObject (org.json.JSONObject)1 Elements (org.jsoup.select.Elements)1