@curvenote/cli-plugin
Version:
MyST Plugins for Curvenote
108 lines (107 loc) • 4.16 kB
JavaScript
import { validateStringOptions, makePlaceholder } from '../utils.js';
export const articlesDirective = {
name: 'cn:articles',
doc: 'A listing directive that can be used to show a list of articles from a specific venue, collection or kind.',
options: {
venue: {
type: String,
doc: 'The venue to list articles from.',
required: true,
},
collection: {
type: String,
doc: 'The collection to list articles from.',
required: false,
},
status: {
type: String,
doc: 'The status of articles to list (published | in-review).',
required: false,
},
'submission-kind': {
type: String,
doc: 'The kind of articles to list.',
required: false,
},
layout: {
type: String,
doc: 'The layout of the of articles (list | cards).',
required: false,
},
wide: {
type: Boolean,
doc: 'If set, the listing will be wide.',
required: false,
},
limit: {
type: Number,
doc: 'The maximum number of articles to list.',
required: false,
},
pagination: {
type: String,
doc: 'If `limit` is set, this gives a hint to the renderer on how to handle pagination (more | all | scroll).',
required: false,
},
'show-collection': {
type: Boolean,
doc: 'If set to true, the listing will show the collection name.',
required: false,
},
'show-kind': {
type: Boolean,
doc: 'If set to true, the listing will show the kind name.',
required: false,
},
'show-date': {
type: Boolean,
doc: 'If set to true, the listing will not show the publication date.',
required: false,
},
'show-thumbnails': {
type: Boolean,
doc: 'If set to true, the listing will not show thumbnails.',
required: false,
},
'show-count': {
type: Boolean,
doc: 'If set to true, the total number of items in the listing will be shown.',
required: false,
},
'show-authors': {
type: Boolean,
doc: 'If set to true, the listing will show the authors.',
required: false,
},
'show-doi': {
type: Boolean,
doc: 'If set to true, the listing will show the DOI.',
required: false,
},
},
validate(data, vfile) {
var _a, _b, _c, _d;
if (!((_a = data.options) === null || _a === void 0 ? void 0 : _a.venue)) {
vfile.message('A venue must be supplied.');
}
validateStringOptions(vfile, 'status', (_b = data.options) === null || _b === void 0 ? void 0 : _b.status, ['published', 'in-review']);
validateStringOptions(vfile, 'layout', (_c = data.options) === null || _c === void 0 ? void 0 : _c.layout, ['list', 'cards']);
validateStringOptions(vfile, 'pagination', (_d = data.options) === null || _d === void 0 ? void 0 : _d.pagination, ['more', 'all', 'scroll']);
// TODO get hold of session?
// TODO lookup API and validate venue, collection, kind exist?
// TODO how to validate against the correct API? dev/staging/prod?
return data;
},
run(data) {
var _a, _b, _c, _d, _e;
return [
{
type: 'curvenoteArticles',
...data.options,
layout: (_b = (_a = data.options) === null || _a === void 0 ? void 0 : _a.layout) !== null && _b !== void 0 ? _b : 'list',
pagination: (_d = (_c = data.options) === null || _c === void 0 ? void 0 : _c.pagination) !== null && _d !== void 0 ? _d : 'more',
children: makePlaceholder(data, `a live listing of articles from ${(_e = data.options) === null || _e === void 0 ? void 0 : _e.venue}`),
},
];
},
};