feat: content in sub folders (#2897)
This commit is contained in:
committed by
Shawn Erquhart
parent
766ade1a3c
commit
afcfe5b6d5
@ -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');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -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';
|
||||
|
Reference in New Issue
Block a user