UI updates (#151)
* infer card title * Infer entry body & image * infer image * Better terminology: EntryListing accept a single Collection * remove log * Refactored Collections VO into selectors * use selectors when showning card * fixed size cards * Added 'bio' and 'biography' to collection description inference synonyms * Removed unused card file * throw error instance * bugfix for file based collections * lint * moved components with css to own folder * Search Bugfix: More than one collection might be returned * Changed sidebar implementation. Closes #104 & #152 * Show spinning loading for unpublished entries * Refactored Sidebar into a separate container * Make preview widgets more robust
This commit is contained in:
@ -1,121 +0,0 @@
|
||||
import { FOLDER, FILES } from '../constants/collectionTypes';
|
||||
|
||||
function formatToExtension(format) {
|
||||
return {
|
||||
markdown: 'md',
|
||||
yaml: 'yml',
|
||||
json: 'json',
|
||||
html: 'html',
|
||||
}[format];
|
||||
}
|
||||
|
||||
class FolderCollection {
|
||||
constructor(collection) {
|
||||
this.collection = collection;
|
||||
}
|
||||
|
||||
entryFields() {
|
||||
return this.collection.get('fields');
|
||||
}
|
||||
|
||||
entryPath(slug) {
|
||||
return `${ this.collection.get('folder') }/${ slug }.${ this.entryExtension() }`;
|
||||
}
|
||||
|
||||
entrySlug(path) {
|
||||
return path.split('/').pop().replace(/\.[^\.]+$/, '');
|
||||
}
|
||||
|
||||
listMethod() {
|
||||
return 'entriesByFolder';
|
||||
}
|
||||
|
||||
entryExtension() {
|
||||
return this.collection.get('extension') || formatToExtension(this.collection.get('format') || 'markdown');
|
||||
}
|
||||
|
||||
allowNewEntries() {
|
||||
return this.collection.get('create');
|
||||
}
|
||||
|
||||
templateName() {
|
||||
return this.collection.get('name');
|
||||
}
|
||||
}
|
||||
|
||||
class FilesCollection {
|
||||
constructor(collection) {
|
||||
this.collection = collection;
|
||||
}
|
||||
|
||||
entryFields(slug) {
|
||||
const file = this.fileForEntry(slug);
|
||||
return file && file.get('fields');
|
||||
}
|
||||
|
||||
entryPath(slug) {
|
||||
const file = this.fileForEntry(slug);
|
||||
return file && file.get('file');
|
||||
}
|
||||
|
||||
entrySlug(path) {
|
||||
const file = this.collection.get('files').filter(f => f.get('file') === path).get(0);
|
||||
return file && file.get('name');
|
||||
}
|
||||
|
||||
fileForEntry(slug) {
|
||||
const files = this.collection.get('files');
|
||||
return files.filter(f => f.get('name') === slug).get(0);
|
||||
}
|
||||
|
||||
listMethod() {
|
||||
return 'entriesByFiles';
|
||||
}
|
||||
|
||||
allowNewEntries() {
|
||||
return false;
|
||||
}
|
||||
|
||||
templateName(slug) {
|
||||
return slug;
|
||||
}
|
||||
}
|
||||
|
||||
export default class Collection {
|
||||
constructor(collection) {
|
||||
switch (collection.get('type')) {
|
||||
case FOLDER:
|
||||
this.collection = new FolderCollection(collection);
|
||||
break;
|
||||
case FILES:
|
||||
this.collection = new FilesCollection(collection);
|
||||
break;
|
||||
default:
|
||||
throw ('Unknown collection type: %o', collection.get('type'));
|
||||
}
|
||||
}
|
||||
|
||||
entryFields(slug) {
|
||||
return this.collection.entryFields(slug);
|
||||
}
|
||||
|
||||
entryPath(slug) {
|
||||
return this.collection.entryPath(slug);
|
||||
}
|
||||
|
||||
entrySlug(path) {
|
||||
return this.collection.entrySlug(path);
|
||||
}
|
||||
|
||||
listMethod() {
|
||||
return this.collection.listMethod();
|
||||
}
|
||||
|
||||
allowNewEntries() {
|
||||
return this.collection.allowNewEntries();
|
||||
}
|
||||
|
||||
templateName(slug) {
|
||||
return this.collection.templateName(slug);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user