feat: support filename and extension vars in summary (#3375)
This commit is contained in:
@ -358,6 +358,19 @@ describe('formatters', () => {
|
||||
|
||||
expect(summaryFormatter('{{title}}-{{year}}', entry, collection)).toBe('title-2020');
|
||||
});
|
||||
|
||||
it('should handle filename and extension variables', () => {
|
||||
const { selectInferedField } = require('../../reducers/collections');
|
||||
selectInferedField.mockReturnValue('date');
|
||||
|
||||
const date = new Date('2020-01-02T13:28:27.679Z');
|
||||
const entry = fromJS({ path: 'post.md', data: { date, title: 'title' } });
|
||||
const collection = fromJS({ fields: [{ name: 'date', widget: 'date' }] });
|
||||
|
||||
expect(
|
||||
summaryFormatter('{{title}}-{{year}}-{{filename}}.{{extension}}', entry, collection),
|
||||
).toBe('title-2020-post.md');
|
||||
});
|
||||
});
|
||||
|
||||
describe('folderFormatter', () => {
|
||||
|
@ -200,9 +200,11 @@ export const summaryFormatter = (
|
||||
entry: EntryMap,
|
||||
collection: Collection,
|
||||
) => {
|
||||
const entryData = entry.get('data');
|
||||
let entryData = entry.get('data');
|
||||
const date = parseDateFromEntry(entry, collection) || null;
|
||||
const identifier = entryData.getIn(keyToPathArray(selectIdentifier(collection) as string));
|
||||
|
||||
entryData = addFileTemplateFields(entry.get('path'), entryData);
|
||||
const summary = compileStringTemplate(summaryTemplate, date, identifier, entryData);
|
||||
return summary;
|
||||
};
|
||||
|
Reference in New Issue
Block a user