Repository navigation
Expand file tree
/
Copy pathlibrary-create-periodical.js
More file actions
68 lines (63 loc) · 1.85 KB
/
Copy pathlibrary-create-periodical.js
File metadata and controls
68 lines (63 loc) · 1.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import { Periodical } from '../.codex/library/objects/Periodical.js';
import { PeriodicalModal } from '../.codex/library/modals/PeriodicalModal.js';
import { Log } from '../.codex/utils/logger.js';
export function buildInvokeCommand(app) {
return {
name: 'Create Library Periodical',
id: 'library-create-periodical',
callback() {
new PeriodicalModal(app, async (result) => {
try {
if (!result.filterTag) {
const error = new Error(
'Periodical requires a filter tag -- it scopes the generated Issues.base file.'
);
Log.error(
'library-create-periodical',
error.message,
error
);
throw error;
}
const folder = await Periodical.resolveFolder(app);
const { filterTag, ...periodicalOptions } = result;
const baseFilename = `${ result.filename } Issues.base`;
await app.vault.create(
`${ folder }/${ baseFilename }`,
buildIssuesBase(filterTag)
);
Log.log('library-create-periodical', `${ baseFilename } created.`);
const periodical = new Periodical(app, { ...periodicalOptions, folder });
const file = await periodical.create();
await app.workspace.getLeaf(false).openFile(file);
} catch (error) {
Log.error(
'library-create-periodical',
'Periodical creation failed.',
error
);
throw error;
}
}).open();
}
};
};
// Scopes the issues table to Collection notes carrying filterTag --
// the curator is responsible for applying that same tag to each
// Collection (issue) belonging to this periodical.
function buildIssuesBase(filterTag) {
return [
'filters:',
' and:',
` - file.hasTag("${ filterTag }")`,
' - \'class == "collection"\'',
'views:',
' - type: table',
' name: Issues',
' order:',
' - file.name',
' - year',
' - citation',
'',
].join('\n');
}