Search in sources :

Example 11 with OrchidResource

use of com.eden.orchid.api.resources.resource.OrchidResource 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 12 with OrchidResource

use of com.eden.orchid.api.resources.resource.OrchidResource 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)

Example 13 with OrchidResource

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

the class LocalResourceSource method getResourceEntries.

@Override
public List<OrchidResource> getResourceEntries(String path, String[] fileExtensions, boolean recursive) {
    List<OrchidResource> entries = new ArrayList<>();
    String fullPath = getDirectory() + "/" + path;
    File file = new File(fullPath);
    if (file.exists() && file.isDirectory()) {
        Collection newFiles = FileUtils.listFiles(file, fileExtensions, recursive);
        if (!EdenUtils.isEmpty(newFiles)) {
            for (Object object : newFiles) {
                File newFile = (File) object;
                if (shouldAddEntry(newFile.getName())) {
                    FileResource entry = new FileResource(context, newFile);
                    entry.setPriority(getPriority());
                    entries.add(entry);
                }
            }
        }
    }
    return entries;
}
Also used : OrchidResource(com.eden.orchid.api.resources.resource.OrchidResource) ArrayList(java.util.ArrayList) FileResource(com.eden.orchid.api.resources.resource.FileResource) Collection(java.util.Collection) File(java.io.File)

Example 14 with OrchidResource

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

the class AssetsGenerator method startIndexing.

@Override
public List<? extends OrchidPage> startIndexing() {
    List<OrchidResource> resourcesList = resources.getResourceEntries("assets", null, true);
    List<OrchidPage> assets = new ArrayList<>();
    for (OrchidResource entry : resourcesList) {
        //            entry.getReference().setBasePath("assets");
        assets.add(new OrchidPage(entry));
    }
    return assets;
}
Also used : OrchidPage(com.eden.orchid.api.theme.pages.OrchidPage) OrchidResource(com.eden.orchid.api.resources.resource.OrchidResource) ArrayList(java.util.ArrayList)

Aggregations

OrchidResource (com.eden.orchid.api.resources.resource.OrchidResource)14 ArrayList (java.util.ArrayList)6 JSONObject (org.json.JSONObject)6 StringResource (com.eden.orchid.api.resources.resource.StringResource)3 OrchidPage (com.eden.orchid.api.theme.pages.OrchidPage)3 OrchidResponse (com.eden.orchid.server.api.OrchidResponse)2 Get (com.eden.orchid.server.api.methods.Get)2 File (java.io.File)2 SimpleDateFormat (java.text.SimpleDateFormat)2 Date (java.util.Date)2 Document (org.jsoup.nodes.Document)2 Element (org.jsoup.nodes.Element)2 JSONElement (com.eden.common.json.JSONElement)1 OrchidIndex (com.eden.orchid.api.indexing.OrchidIndex)1 FileResource (com.eden.orchid.api.resources.resource.FileResource)1 JarResource (com.eden.orchid.api.resources.resource.JarResource)1 JsonResource (com.eden.orchid.api.resources.resource.JsonResource)1 OrchidReference (com.eden.orchid.api.theme.pages.OrchidReference)1 OrchidInternalIndex (com.eden.orchid.impl.indexing.OrchidInternalIndex)1 OrchidRootInternalIndex (com.eden.orchid.impl.indexing.OrchidRootInternalIndex)1