feat: content in sub folders (#2897)

This commit is contained in:
Erez Rokah
2019-11-28 05:39:33 +02:00
committed by Shawn Erquhart
parent 766ade1a3c
commit afcfe5b6d5
44 changed files with 7218 additions and 8225 deletions

View File

@ -1,6 +1,6 @@
import { OrderedMap, fromJS } from 'immutable';
import { configLoaded } from 'Actions/config';
import collections, { selectAllowDeletion } from '../collections';
import collections, { selectAllowDeletion, selectEntryPath, selectEntrySlug } from '../collections';
import { FILES, FOLDER } from 'Constants/collectionTypes';
describe('collections', () => {
@ -48,4 +48,32 @@ describe('collections', () => {
).toBe(false);
});
});
describe('selectEntryPath', () => {
it('should return path', () => {
expect(
selectEntryPath(
fromJS({
type: FOLDER,
folder: 'posts',
}),
'dir1/dir2/slug',
),
).toBe('posts/dir1/dir2/slug.md');
});
});
describe('selectEntrySlug', () => {
it('should return slug', () => {
expect(
selectEntrySlug(
fromJS({
type: FOLDER,
folder: 'posts',
}),
'posts/dir1/dir2/slug.md',
),
).toBe('dir1/dir2/slug');
});
});
});

View File

@ -39,15 +39,17 @@ const selectors = {
return collection.get('fields');
},
entryPath(collection, slug) {
return `${collection.get('folder').replace(/\/$/, '')}/${slug}.${this.entryExtension(
collection,
)}`;
const folder = collection.get('folder').replace(/\/$/, '');
return `${folder}/${slug}.${this.entryExtension(collection)}`;
},
entrySlug(collection, path) {
return path
.split('/')
const folder = collection.get('folder').replace(/\/$/, '');
const slug = path
.split(folder + '/')
.pop()
.replace(new RegExp(`\\.${escapeRegExp(this.entryExtension(collection))}$`), '');
return slug;
},
listMethod() {
return 'entriesByFolder';