use of com.eden.orchid.api.resources.resource.OrchidResource 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;
}
use of com.eden.orchid.api.resources.resource.OrchidResource in project Orchid by JavaEden.
the class IndexGenerator method generateIndexFiles.
private void generateIndexFiles() {
OrchidRootInternalIndex internalIndex = context.getInternalIndex();
Map<String, OrchidInternalIndex> mappedIndex = internalIndex.getAllIndexedPages();
OrchidIndex indices = new OrchidInternalIndex("indices");
// Render an page for each generator's individual index
mappedIndex.keySet().forEach(key -> {
OrchidResource resource = new JsonResource(new JSONElement(mappedIndex.get(key).toJSON()), new OrchidReference(context, "meta/" + key + ".index.json"));
OrchidPage page = new OrchidPage(resource);
page.renderRaw();
indices.addToIndex(indices.getOwnKey() + "/" + page.getReference().getPath(), page);
});
// Render full composite index page
OrchidResource compositeIndexResource = new JsonResource(new JSONElement(internalIndex.toJSON()), new OrchidReference(context, "meta/index.json"));
OrchidPage compositeIndexPage = new OrchidPage(compositeIndexResource);
compositeIndexPage.renderRaw();
indices.addToIndex(indices.getOwnKey() + "/" + compositeIndexPage.getReference().getPath(), compositeIndexPage);
// Render an index of all indices, so individual index pages can be found
OrchidResource indicesIndexResource = new JsonResource(new JSONElement(indices.toJSON()), new OrchidReference(context, "meta/indices.json"));
OrchidPage indicesPage = new OrchidPage(indicesIndexResource);
indicesPage.renderRaw();
}
use of com.eden.orchid.api.resources.resource.OrchidResource in project Orchid by JavaEden.
the class SassImporter method apply.
@Override
public Collection<Import> apply(String url, Import previous) {
EdenPair<String, String> thisItem = splitPath(url);
String[] availableFiles = new String[] { thisItem.first + "/" + thisItem.second + ".scss", thisItem.first + "/" + thisItem.second + ".sass", thisItem.first + "/" + "_" + thisItem.second + ".scss", thisItem.first + "/" + "_" + thisItem.second + ".sass" };
for (String availableFile : availableFiles) {
String absoluteUri = OrchidUtils.normalizePath(splitPath(previous.getAbsoluteUri().getPath()).first + "/" + availableFile);
if (absoluteUri.contains("//")) {
absoluteUri = absoluteUri.replaceAll("//", "/");
}
if (absoluteUri.startsWith("/")) {
absoluteUri = absoluteUri.substring(1);
}
OrchidResource importedResource = resources.get().getResourceEntry("assets/css/" + absoluteUri);
if (importedResource != null) {
String content = importedResource.getContent();
if (importedResource.shouldPrecompile()) {
content = context.getTheme().precompile(content, importedResource.getEmbeddedData());
}
try {
String newURI = "" + OrchidUtils.normalizePath(absoluteUri);
Import newImport = new Import(newURI, newURI, content);
return Collections.singletonList(newImport);
} catch (Exception e) {
e.printStackTrace();
}
}
}
return null;
}
use of com.eden.orchid.api.resources.resource.OrchidResource in project Orchid by JavaEden.
the class DefaultResourceSource method getResourceEntries.
@Override
public List<OrchidResource> getResourceEntries(String path, String[] fileExtensions, boolean recursive) {
List<OrchidResource> entries = new ArrayList<>();
JarFile jarFile = jarForClass(this.getClass());
if (jarFile == null) {
return entries;
}
Enumeration<JarEntry> jarEntries = jarFile.entries();
while (jarEntries.hasMoreElements()) {
JarEntry jarEntry = jarEntries.nextElement();
// we are checking a file in the jar
if (OrchidUtils.normalizePath(jarEntry.getName()).startsWith(path + "/") && !jarEntry.isDirectory()) {
if (EdenUtils.isEmpty(fileExtensions) || FilenameUtils.isExtension(jarEntry.getName(), fileExtensions)) {
if (shouldAddEntry(jarEntry.getName())) {
entries.add(new JarResource(context, jarFile, jarEntry));
}
}
}
}
return entries;
}
use of com.eden.orchid.api.resources.resource.OrchidResource in project Orchid by JavaEden.
the class PostsGenerator method getPostsList.
private List<PostPage> getPostsList(String category) {
List<OrchidResource> resourcesList;
if (EdenUtils.isEmpty(category)) {
resourcesList = resources.getLocalResourceEntries("posts", null, false);
} else {
resourcesList = resources.getLocalResourceEntries("posts/" + category, null, false);
}
List<PostPage> posts = new ArrayList<>();
for (OrchidResource entry : resourcesList) {
Matcher matcher = pageTitleRegex.matcher(entry.getReference().getFileName());
if (matcher.matches()) {
JSONObject pageData = (OrchidUtils.elementIsObject(entry.getEmbeddedData())) ? (JSONObject) entry.getEmbeddedData().getElement() : new JSONObject();
int year = Integer.parseInt(matcher.group(1));
int month = Integer.parseInt(matcher.group(2));
int day = Integer.parseInt(matcher.group(3));
Calendar calendar = Calendar.getInstance();
int hour = calendar.get(Calendar.HOUR_OF_DAY);
int minute = calendar.get(Calendar.MINUTE);
int second = calendar.get(Calendar.SECOND);
String title = matcher.group(4);
if (!EdenUtils.isEmpty(entry.queryEmbeddedData("title"))) {
title = entry.queryEmbeddedData("title").toString();
} else {
title = Arrays.stream(title.split("-")).map(word -> word.substring(0, 1).toUpperCase() + word.substring(1).toLowerCase()).collect(Collectors.joining(" "));
}
if (entry.queryEmbeddedData("date") != null) {
String date = entry.queryEmbeddedData("date").toString();
try {
SimpleDateFormat formatter = new SimpleDateFormat("YYYY-MM-DD HH:MM:SS");
Date dateTime = formatter.parse(date);
calendar = Calendar.getInstance();
calendar.setTime(dateTime);
year = calendar.get(Calendar.YEAR);
month = calendar.get(Calendar.YEAR);
day = calendar.get(Calendar.YEAR);
hour = calendar.get(Calendar.HOUR_OF_DAY);
minute = calendar.get(Calendar.MINUTE);
second = calendar.get(Calendar.SECOND);
} catch (ParseException e) {
e.printStackTrace();
}
}
pageData.put("year", year);
pageData.put("month", month);
pageData.put("day", day);
pageData.put("hour", hour);
pageData.put("minute", minute);
pageData.put("second", second);
if (EdenUtils.isEmpty(category)) {
entry.getReference().stripFromPath("blog");
} else {
pageData.put("category", category);
entry.getReference().stripFromPath("blog/" + category);
}
pageData.put("title", title);
setPermalink(entry.getReference(), pageData);
PostPage post = new PostPage(entry);
post.setType("post");
post.setData(pageData);
String excerpt = excerptStrategy.getExcerpt(post);
post.getData().put("excerpt", excerpt);
posts.add(post);
}
}
posts.sort((o1, o2) -> {
String[] criteria = new String[] { "year", "month", "day", "hour", "minute", "second" };
for (String item : criteria) {
if (o1.getData().has(item) && o1.getData().has(item)) {
int result = o2.getData().optInt(item) - o1.getData().optInt(item);
if (result != 0) {
return result;
}
}
}
return 0;
});
int i = 0;
for (PostPage post : posts) {
if (next(posts, i) != null) {
post.setNext(next(posts, i));
}
if (previous(posts, i) != null) {
post.setPrevious(previous(posts, i));
}
i++;
}
return posts;
}
Aggregations