@curvenote/renderers 0.5.7 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/any/index.d.ts.map +1 -1
- package/dist/any/index.js +0 -6
- package/dist/articles.d.ts +5 -0
- package/dist/articles.d.ts.map +1 -0
- package/dist/articles.js +15 -0
- package/dist/cards.d.ts +8 -0
- package/dist/cards.d.ts.map +1 -0
- package/dist/cards.js +15 -0
- package/dist/collections.d.ts +6 -0
- package/dist/collections.d.ts.map +1 -0
- package/dist/collections.js +12 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -3
- package/dist/transforms/articles.d.ts +35 -0
- package/dist/transforms/articles.d.ts.map +1 -0
- package/dist/transforms/articles.js +61 -0
- package/dist/transforms/cards.d.ts +52 -0
- package/dist/transforms/cards.d.ts.map +1 -0
- package/dist/transforms/cards.js +68 -0
- package/dist/transforms/collections.d.ts +15 -0
- package/dist/transforms/collections.d.ts.map +1 -0
- package/dist/transforms/collections.js +44 -0
- package/dist/transforms/index.d.ts +8 -0
- package/dist/transforms/index.d.ts.map +1 -0
- package/dist/transforms/index.js +25 -0
- package/dist/transforms/outputs.d.ts +3 -0
- package/dist/transforms/outputs.d.ts.map +1 -0
- package/dist/transforms/outputs.js +20 -0
- package/package.json +11 -9
package/dist/any/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/any/index.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/any/index.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAG3D,cAAc,aAAa,CAAC;AAC5B,cAAc,YAAY,CAAC;AAE3B,eAAO,MAAM,aAAa,EAAE,aAI3B,CAAC"}
|
package/dist/any/index.js
CHANGED
|
@@ -1,14 +1,8 @@
|
|
|
1
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import { MyST } from 'myst-to-react';
|
|
3
1
|
import { AnyRenderer } from './renderers.js';
|
|
4
2
|
export * from './models.js';
|
|
5
3
|
export * from './types.js';
|
|
6
|
-
function Block({ node }) {
|
|
7
|
-
return (_jsx("div", { children: _jsx(MyST, { ast: node.children }) }));
|
|
8
|
-
}
|
|
9
4
|
export const ANY_RENDERERS = {
|
|
10
5
|
block: {
|
|
11
|
-
base: Block,
|
|
12
6
|
'block[kind=any:bundle]': AnyRenderer,
|
|
13
7
|
},
|
|
14
8
|
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"articles.d.ts","sourceRoot":"","sources":["../src/articles.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAuC1D,eAAO,MAAM,kBAAkB;;CAA0C,CAAC"}
|
package/dist/articles.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { ArticleListing } from '@curvenote/theme';
|
|
3
|
+
const ArticlesRenderer = ({ node }) => {
|
|
4
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
5
|
+
return (_jsxs("div", { children: [!node.error && (_jsx(ArticleListing, { total: node.total, works: node.items, layout: node.layout, narrow: !node.wide, v2: true, show: {
|
|
6
|
+
collection: (_a = node['show-collection']) !== null && _a !== void 0 ? _a : false,
|
|
7
|
+
kind: (_b = node['show-kind']) !== null && _b !== void 0 ? _b : false,
|
|
8
|
+
thumbnail: (_c = node['show-thumbnails']) !== null && _c !== void 0 ? _c : false,
|
|
9
|
+
date: (_d = node['show-date']) !== null && _d !== void 0 ? _d : false,
|
|
10
|
+
count: (_e = node['show-count']) !== null && _e !== void 0 ? _e : false,
|
|
11
|
+
authors: (_f = node['show-authors']) !== null && _f !== void 0 ? _f : false,
|
|
12
|
+
doi: (_g = node['show-doi']) !== null && _g !== void 0 ? _g : false,
|
|
13
|
+
} })), !node.error && node.items.length === 0 && (_jsx("div", { className: "px-2 py-4 text-gray-600 border-gray-500 border-gray-[1px] rounded bg-gray-50", children: "There are no articles in this listing yet." })), node.error && (_jsx("div", { className: "text-red-500 p-4 my-2 bg-red-50 border-[1px] border-red-500 rounded", children: node.error }))] }));
|
|
14
|
+
};
|
|
15
|
+
export const ARTICLES_RENDERERS = { curvenoteArticles: ArticlesRenderer };
|
package/dist/cards.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { NodeRenderer } from '@myst-theme/providers';
|
|
2
|
+
export declare const CARD_RENDERERS: {
|
|
3
|
+
card: {
|
|
4
|
+
"card[kind=curvenoteArticleListItem]": NodeRenderer;
|
|
5
|
+
"card[kind=curvenoteExternalListItem]": NodeRenderer;
|
|
6
|
+
};
|
|
7
|
+
};
|
|
8
|
+
//# sourceMappingURL=cards.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cards.d.ts","sourceRoot":"","sources":["../src/cards.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAqD1D,eAAO,MAAM,cAAc;;;;;CAK1B,CAAC"}
|
package/dist/cards.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { ArticleListItemV2 } from '@curvenote/theme';
|
|
3
|
+
import { MyST } from 'myst-to-react';
|
|
4
|
+
import { CardKindArticleListItem, CardKindExternalListItem } from './transforms/index.js';
|
|
5
|
+
const CustomCardsRenderer = ({ node }) => {
|
|
6
|
+
const { title, url, thumbnail, authors, date, kind, collection, description, doi } = node.data.json;
|
|
7
|
+
const { parsed } = node.data;
|
|
8
|
+
return (_jsx("div", { className: "py-3", children: _jsx(ArticleListItemV2, { title: (parsed === null || parsed === void 0 ? void 0 : parsed.title) ? _jsx(MyST, { ast: parsed.title }) : (title !== null && title !== void 0 ? title : 'Untitled'), authors: authors !== null && authors !== void 0 ? authors : [], url: url, thumbnail: thumbnail, kind: kind, collection: collection, date: date, description: description, doi: doi, showThumbnail: node.data.showThumbnail }) }));
|
|
9
|
+
};
|
|
10
|
+
export const CARD_RENDERERS = {
|
|
11
|
+
card: {
|
|
12
|
+
[`card[kind=${CardKindArticleListItem}]`]: CustomCardsRenderer,
|
|
13
|
+
[`card[kind=${CardKindExternalListItem}]`]: CustomCardsRenderer,
|
|
14
|
+
},
|
|
15
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"collections.d.ts","sourceRoot":"","sources":["../src/collections.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAmB,KAAK,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAgB3E,eAAO,MAAM,mBAAmB,EAAE,YA0CjC,CAAC;AAEF,eAAO,MAAM,qBAAqB;;CAAgD,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useLinkProvider } from '@myst-theme/providers';
|
|
3
|
+
import { LockOpen } from 'lucide-react';
|
|
4
|
+
import classNames from 'classnames';
|
|
5
|
+
function Open({ className }) {
|
|
6
|
+
return (_jsxs("div", { className: classNames(className, 'text-sm font-semibold text-green-700 smallcaps opacity-80'), children: [_jsx(LockOpen, { className: "inline-block w-3 h-3 mr-1 align-middle" }), _jsx("span", { className: "align-middle", children: "open" })] }));
|
|
7
|
+
}
|
|
8
|
+
export const CollectionsRenderer = ({ node, }) => {
|
|
9
|
+
const Link = useLinkProvider();
|
|
10
|
+
return (_jsxs("div", { className: "py-3", children: [!node.error && node.items.length === 0 && (_jsx("div", { children: "There are no collections in this listing yet." })), !node.error && (_jsx("ul", { className: "space-y-8 not-prose", children: node.items.map((c) => (_jsx("li", { className: "cursor-pointer group/collection", children: _jsxs(Link, { to: `/${c.slug}`.replace('//', '/'), className: "block no-underline", children: [_jsx("h3", { className: "mt-1 text-xl font-semibold text-black group-hover/collection:text-blue-600 dark:group-hover/collection:text-blue-400 dark:text-white", children: c.content.title }), _jsx("p", { className: "mt-1 mb-2 leading-6 text-gray-600 group-hover/collection:text-gray-800 dark:text-gray-300", children: c.content.description }), _jsxs("div", { className: "text-sm text-gray-500 smallcaps", children: [_jsxs("span", { className: "align-bottom", children: [_jsx("span", { className: "font-semibold", children: c.num_published }), " item", c.num_published === 1 ? '' : 's'] }), c.open && _jsx(Open, { className: "inline-block ml-2 align-bottom" })] })] }) }, c.id))) })), node.error && (_jsx("div", { className: "text-red-500 p-4 my-2 bg-red-50 border-[1px] border-red-500 rounded", children: node.error }))] }));
|
|
11
|
+
};
|
|
12
|
+
export const COLLECTIONS_RENDERERS = { curvenoteCollections: CollectionsRenderer };
|
package/dist/index.d.ts
CHANGED
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.tsx"],"names":[],"mappings":"AAYA,eAAO,MAAM,kBAAkB,+CAW7B,CAAC;AAEH,cAAc,uBAAuB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
import { mergeRenderers } from '@myst-theme/providers';
|
|
2
|
-
import CITE_RENDERERS from './cite.js';
|
|
3
2
|
import PERSON_CARD_RENDERERS from '@curvenote/ext-person/react';
|
|
4
3
|
import BLOG_RENDERERS from '@curvenote/ext-blog/react';
|
|
5
|
-
import { OUTPUT_RENDERERS } from '@curvenote/bridge-jupyter';
|
|
6
4
|
import LANDING_RENDERERS from '@curvenote/ext-landing/react';
|
|
7
5
|
import FOOTER_RENDERERS from '@curvenote/ext-footer/react';
|
|
8
6
|
import SCIENCEICON_RENDERERS from '@scienceicons/myst/react';
|
|
7
|
+
import CITE_RENDERERS from './cite.js';
|
|
9
8
|
import { ANY_RENDERERS } from './any/index.js';
|
|
9
|
+
import { ARTICLES_RENDERERS } from './articles.js';
|
|
10
|
+
import { COLLECTIONS_RENDERERS } from './collections.js';
|
|
11
|
+
import { CARD_RENDERERS } from './cards.js';
|
|
10
12
|
export const curvenoteRenderers = mergeRenderers([
|
|
11
|
-
OUTPUT_RENDERERS,
|
|
12
13
|
CITE_RENDERERS,
|
|
13
14
|
PERSON_CARD_RENDERERS,
|
|
14
15
|
BLOG_RENDERERS,
|
|
@@ -16,4 +17,8 @@ export const curvenoteRenderers = mergeRenderers([
|
|
|
16
17
|
FOOTER_RENDERERS,
|
|
17
18
|
SCIENCEICON_RENDERERS,
|
|
18
19
|
ANY_RENDERERS,
|
|
20
|
+
CARD_RENDERERS,
|
|
21
|
+
ARTICLES_RENDERERS,
|
|
22
|
+
COLLECTIONS_RENDERERS,
|
|
19
23
|
]);
|
|
24
|
+
export * from './transforms/index.js';
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { GenericParent } from 'myst-common';
|
|
2
|
+
import type { SiteWorkListingDTO } from '@curvenote/common';
|
|
3
|
+
export interface IncomingArticlesDirective {
|
|
4
|
+
venue: string;
|
|
5
|
+
layout: 'list' | 'cards';
|
|
6
|
+
pagination: string;
|
|
7
|
+
wide?: boolean;
|
|
8
|
+
collection?: string;
|
|
9
|
+
['submission-kind']?: string;
|
|
10
|
+
status?: string;
|
|
11
|
+
limit?: number;
|
|
12
|
+
['show-thumbnails']?: boolean;
|
|
13
|
+
['show-collection']?: boolean;
|
|
14
|
+
['show-kind']?: boolean;
|
|
15
|
+
['show-date']?: boolean;
|
|
16
|
+
['show-count']?: boolean;
|
|
17
|
+
['show-authors']?: boolean;
|
|
18
|
+
['show-doi']?: boolean;
|
|
19
|
+
}
|
|
20
|
+
export type OutgoingArticlesDirective = IncomingArticlesDirective & {
|
|
21
|
+
items: SiteWorkListingDTO['items'];
|
|
22
|
+
total: SiteWorkListingDTO['total'];
|
|
23
|
+
prev?: string;
|
|
24
|
+
next?: string;
|
|
25
|
+
error?: string;
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* Performs an API lookup to populate the articles listing based on the provided
|
|
29
|
+
* options.
|
|
30
|
+
*
|
|
31
|
+
* @param node
|
|
32
|
+
* @returns
|
|
33
|
+
*/
|
|
34
|
+
export declare function transformArticles(node: GenericParent): Promise<void[]>;
|
|
35
|
+
//# sourceMappingURL=articles.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"articles.d.ts","sourceRoot":"","sources":["../../src/transforms/articles.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAIjD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAE5D,MAAM,WAAW,yBAAyB;IACxC,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC;IACzB,UAAU,EAAE,MAAM,CAAC;IACnB,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,CAAC,iBAAiB,CAAC,CAAC,EAAE,MAAM,CAAC;IAC7B,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,CAAC,iBAAiB,CAAC,CAAC,EAAE,OAAO,CAAC;IAC9B,CAAC,iBAAiB,CAAC,CAAC,EAAE,OAAO,CAAC;IAC9B,CAAC,WAAW,CAAC,CAAC,EAAE,OAAO,CAAC;IACxB,CAAC,WAAW,CAAC,CAAC,EAAE,OAAO,CAAC;IACxB,CAAC,YAAY,CAAC,CAAC,EAAE,OAAO,CAAC;IACzB,CAAC,cAAc,CAAC,CAAC,EAAE,OAAO,CAAC;IAC3B,CAAC,UAAU,CAAC,CAAC,EAAE,OAAO,CAAC;CACxB;AAED,MAAM,MAAM,yBAAyB,GAAG,yBAAyB,GAAG;IAClE,KAAK,EAAE,kBAAkB,CAAC,OAAO,CAAC,CAAC;IACnC,KAAK,EAAE,kBAAkB,CAAC,OAAO,CAAC,CAAC;IACnC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF;;;;;;GAMG;AACH,wBAAsB,iBAAiB,CAAC,IAAI,EAAE,aAAa,mBA0C1D"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import { selectAll } from 'unist-util-select';
|
|
11
|
+
import pLimit from 'p-limit';
|
|
12
|
+
/**
|
|
13
|
+
* Performs an API lookup to populate the articles listing based on the provided
|
|
14
|
+
* options.
|
|
15
|
+
*
|
|
16
|
+
* @param node
|
|
17
|
+
* @returns
|
|
18
|
+
*/
|
|
19
|
+
export function transformArticles(node) {
|
|
20
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
21
|
+
const articlesDirectives = selectAll('curvenoteArticles', node);
|
|
22
|
+
const applyLimit = pLimit(5);
|
|
23
|
+
return Promise.all(articlesDirectives.map((n) => __awaiter(this, void 0, void 0, function* () {
|
|
24
|
+
return applyLimit(() => __awaiter(this, void 0, void 0, function* () {
|
|
25
|
+
const output = n; // same object, modified in place
|
|
26
|
+
// ensure defaults
|
|
27
|
+
if (!n.pagination)
|
|
28
|
+
output.pagination = 'more';
|
|
29
|
+
if (!n.layout)
|
|
30
|
+
output.layout = 'list';
|
|
31
|
+
// build the URL
|
|
32
|
+
const apiUrl = process.env.JOURNALS_API_URL;
|
|
33
|
+
const url = new URL(`${apiUrl}sites/${n.venue}/works`);
|
|
34
|
+
if (n.collection)
|
|
35
|
+
url.searchParams.set('collection', n.collection);
|
|
36
|
+
if (n.status && n.collection)
|
|
37
|
+
url.searchParams.set('status', n.status);
|
|
38
|
+
else if (n.status && !n.collection)
|
|
39
|
+
console.warn('cn:articles directive provides status without collection, status will be ignored');
|
|
40
|
+
if (n['submission-kind'])
|
|
41
|
+
url.searchParams.set('kind', n['submission-kind']);
|
|
42
|
+
if (n.limit)
|
|
43
|
+
url.searchParams.set('limit', n.limit.toString());
|
|
44
|
+
try {
|
|
45
|
+
const res = yield fetch(url.toString());
|
|
46
|
+
if (!res.ok)
|
|
47
|
+
throw new Error(`${res.status} ${res.statusText}`);
|
|
48
|
+
const data = (yield res.json());
|
|
49
|
+
output.items = data.items;
|
|
50
|
+
output.total = data.total;
|
|
51
|
+
output.prev = data.links.prev;
|
|
52
|
+
output.next = data.links.next;
|
|
53
|
+
}
|
|
54
|
+
catch (e) {
|
|
55
|
+
output.error = 'Could not load listing';
|
|
56
|
+
console.error('Could not load listing', e);
|
|
57
|
+
}
|
|
58
|
+
}));
|
|
59
|
+
})));
|
|
60
|
+
});
|
|
61
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { type GenericParent } from 'myst-common';
|
|
2
|
+
import type { Node } from 'unist-util-select';
|
|
3
|
+
import type { SiteDTO } from '@curvenote/common';
|
|
4
|
+
export interface IncomingMaybeCustomCardDirective {
|
|
5
|
+
kind: string;
|
|
6
|
+
children: Node[];
|
|
7
|
+
url: string;
|
|
8
|
+
protocol?: string;
|
|
9
|
+
internal: boolean;
|
|
10
|
+
data: {
|
|
11
|
+
showThumbnail?: boolean;
|
|
12
|
+
json: {
|
|
13
|
+
type?: string;
|
|
14
|
+
title?: string;
|
|
15
|
+
description?: string;
|
|
16
|
+
authors?: {
|
|
17
|
+
name: string;
|
|
18
|
+
affiliation?: string;
|
|
19
|
+
orcid?: string;
|
|
20
|
+
}[];
|
|
21
|
+
doi?: string;
|
|
22
|
+
year?: string;
|
|
23
|
+
date?: string;
|
|
24
|
+
pages?: string[];
|
|
25
|
+
thumbnail?: string;
|
|
26
|
+
};
|
|
27
|
+
parsed?: {
|
|
28
|
+
title?: GenericParent;
|
|
29
|
+
description?: GenericParent;
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
export type OutgoingMaybeCustomCardDirective = IncomingMaybeCustomCardDirective & {
|
|
34
|
+
data: {
|
|
35
|
+
json: {
|
|
36
|
+
doi?: string;
|
|
37
|
+
thumbnail?: string | boolean;
|
|
38
|
+
url?: string;
|
|
39
|
+
};
|
|
40
|
+
};
|
|
41
|
+
};
|
|
42
|
+
export declare const CardKindArticleListItem = "curvenoteArticleListItem";
|
|
43
|
+
export declare const CardKindExternalListItem = "curvenoteExternalListItem";
|
|
44
|
+
/**
|
|
45
|
+
* Looks for myst card directives marked with custom kinds and transforms them
|
|
46
|
+
* ready for custom renering using data embedded in the directive.
|
|
47
|
+
*
|
|
48
|
+
* @param node
|
|
49
|
+
* @returns
|
|
50
|
+
*/
|
|
51
|
+
export declare function transformCards(site: SiteDTO, node: GenericParent): void;
|
|
52
|
+
//# sourceMappingURL=cards.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cards.d.ts","sourceRoot":"","sources":["../../src/transforms/cards.ts"],"names":[],"mappings":"AAAA,OAAO,EAAa,KAAK,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5D,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAC;AAE9C,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAEjD,MAAM,WAAW,gCAAgC;IAC/C,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,IAAI,EAAE,CAAC;IACjB,GAAG,EAAE,MAAM,CAAC;IACZ,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,OAAO,CAAC;IAClB,IAAI,EAAE;QACJ,aAAa,CAAC,EAAE,OAAO,CAAC;QACxB,IAAI,EAAE;YACJ,IAAI,CAAC,EAAE,MAAM,CAAC;YACd,KAAK,CAAC,EAAE,MAAM,CAAC;YACf,WAAW,CAAC,EAAE,MAAM,CAAC;YACrB,OAAO,CAAC,EAAE;gBACR,IAAI,EAAE,MAAM,CAAC;gBACb,WAAW,CAAC,EAAE,MAAM,CAAC;gBACrB,KAAK,CAAC,EAAE,MAAM,CAAC;aAChB,EAAE,CAAC;YACJ,GAAG,CAAC,EAAE,MAAM,CAAC;YACb,IAAI,CAAC,EAAE,MAAM,CAAC;YACd,IAAI,CAAC,EAAE,MAAM,CAAC;YACd,KAAK,CAAC,EAAE,MAAM,EAAE,CAAC;YACjB,SAAS,CAAC,EAAE,MAAM,CAAC;SACpB,CAAC;QACF,MAAM,CAAC,EAAE;YACP,KAAK,CAAC,EAAE,aAAa,CAAC;YACtB,WAAW,CAAC,EAAE,aAAa,CAAC;SAC7B,CAAC;KACH,CAAC;CACH;AAED,MAAM,MAAM,gCAAgC,GAAG,gCAAgC,GAAG;IAChF,IAAI,EAAE;QACJ,IAAI,EAAE;YACJ,GAAG,CAAC,EAAE,MAAM,CAAC;YACb,SAAS,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC;YAC7B,GAAG,CAAC,EAAE,MAAM,CAAC;SACd,CAAC;KACH,CAAC;CACH,CAAC;AAEF,eAAO,MAAM,uBAAuB,6BAA6B,CAAC;AAClE,eAAO,MAAM,wBAAwB,8BAA8B,CAAC;AAEpE;;;;;;GAMG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,aAAa,QAGhE"}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { slugToUrl } from 'myst-common';
|
|
2
|
+
import { selectAll } from 'unist-util-select';
|
|
3
|
+
export const CardKindArticleListItem = 'curvenoteArticleListItem';
|
|
4
|
+
export const CardKindExternalListItem = 'curvenoteExternalListItem';
|
|
5
|
+
/**
|
|
6
|
+
* Looks for myst card directives marked with custom kinds and transforms them
|
|
7
|
+
* ready for custom renering using data embedded in the directive.
|
|
8
|
+
*
|
|
9
|
+
* @param node
|
|
10
|
+
* @returns
|
|
11
|
+
*/
|
|
12
|
+
export function transformCards(site, node) {
|
|
13
|
+
transformArticleListItems(site, node);
|
|
14
|
+
transformExternalListItems(site, node);
|
|
15
|
+
}
|
|
16
|
+
function transformArticleListItems(site, node) {
|
|
17
|
+
const articlesListItemDirectives = selectAll(`card[kind=${CardKindArticleListItem}]`, node);
|
|
18
|
+
articlesListItemDirectives.forEach((n) => {
|
|
19
|
+
transformListItem(site, n);
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
function transformExternalListItems(site, node) {
|
|
23
|
+
const externalListItemDirectives = selectAll(`card[kind=${CardKindExternalListItem}]`, node);
|
|
24
|
+
externalListItemDirectives.forEach((n) => {
|
|
25
|
+
transformListItem(site, n);
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
function transformListItem(site, n) {
|
|
29
|
+
var _a, _b, _c, _d, _e;
|
|
30
|
+
const output = n; // same object, modified in place
|
|
31
|
+
if (!((_a = n.data) === null || _a === void 0 ? void 0 : _a.json))
|
|
32
|
+
return; // no data, leave fallback in place
|
|
33
|
+
const json = n.data.json;
|
|
34
|
+
let slug;
|
|
35
|
+
if (n.url) {
|
|
36
|
+
const tokens = n.url.split('/');
|
|
37
|
+
slug = tokens[tokens.length - 1];
|
|
38
|
+
}
|
|
39
|
+
else if (json.doi) {
|
|
40
|
+
const tokens = (_b = json.doi) === null || _b === void 0 ? void 0 : _b.split('/');
|
|
41
|
+
slug = tokens[tokens.length - 1];
|
|
42
|
+
}
|
|
43
|
+
let url;
|
|
44
|
+
if (n.kind === CardKindExternalListItem) {
|
|
45
|
+
if (n.url) {
|
|
46
|
+
url = n.url;
|
|
47
|
+
}
|
|
48
|
+
else if (json.doi) {
|
|
49
|
+
url = json.doi.startsWith('https://doi.org') ? json.doi : `https://doi.org/${json.doi}`;
|
|
50
|
+
output.url = url;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
else if (n.kind === CardKindArticleListItem) {
|
|
54
|
+
url = `/articles/${slugToUrl(slug)}`;
|
|
55
|
+
output.protocol = undefined;
|
|
56
|
+
output.internal = true;
|
|
57
|
+
output.url = url;
|
|
58
|
+
}
|
|
59
|
+
let thumbnail;
|
|
60
|
+
if (n.data.showThumbnail) {
|
|
61
|
+
thumbnail =
|
|
62
|
+
(_c = json.thumbnail) !== null && _c !== void 0 ? _c : `${process.env.JOURNALS_API_URL}sites/${site.name}/works/${slug}/thumbnail`;
|
|
63
|
+
}
|
|
64
|
+
output.data = Object.assign(Object.assign({}, output.data), { json: Object.assign(Object.assign({}, ((_e = (_d = n.data) === null || _d === void 0 ? void 0 : _d.json) !== null && _e !== void 0 ? _e : {})), { url,
|
|
65
|
+
thumbnail }) });
|
|
66
|
+
// remove fallback content
|
|
67
|
+
output.children = [];
|
|
68
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { GenericParent } from 'myst-common';
|
|
2
|
+
import type { CollectionListingDTO } from '@curvenote/common';
|
|
3
|
+
export interface IncomingCollectionsDirective {
|
|
4
|
+
venue: string;
|
|
5
|
+
show?: 'open' | 'closed' | 'all';
|
|
6
|
+
exclude?: string;
|
|
7
|
+
['show-count']?: boolean;
|
|
8
|
+
}
|
|
9
|
+
export type OutgoingCollectionsDirective = Omit<IncomingCollectionsDirective, 'exclude'> & {
|
|
10
|
+
items: CollectionListingDTO['items'];
|
|
11
|
+
exclude?: string[];
|
|
12
|
+
error?: string;
|
|
13
|
+
};
|
|
14
|
+
export declare function transformCollections(node: GenericParent): Promise<void[]>;
|
|
15
|
+
//# sourceMappingURL=collections.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"collections.d.ts","sourceRoot":"","sources":["../../src/transforms/collections.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAEjD,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AAI9D,MAAM,WAAW,4BAA4B;IAC3C,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,GAAG,QAAQ,GAAG,KAAK,CAAC;IACjC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,CAAC,YAAY,CAAC,CAAC,EAAE,OAAO,CAAC;CAC1B;AAED,MAAM,MAAM,4BAA4B,GAAG,IAAI,CAAC,4BAA4B,EAAE,SAAS,CAAC,GAAG;IACzF,KAAK,EAAE,oBAAoB,CAAC,OAAO,CAAC,CAAC;IACrC,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IACnB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,wBAAsB,oBAAoB,CAAC,IAAI,EAAE,aAAa,mBAmC7D"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import { selectAll } from 'unist-util-select';
|
|
11
|
+
import pLimit from 'p-limit';
|
|
12
|
+
export function transformCollections(node) {
|
|
13
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
14
|
+
const collectionsDirectives = selectAll('curvenoteCollections', node);
|
|
15
|
+
const limit = pLimit(5);
|
|
16
|
+
return Promise.all(collectionsDirectives.map((n) => __awaiter(this, void 0, void 0, function* () {
|
|
17
|
+
return limit(() => __awaiter(this, void 0, void 0, function* () {
|
|
18
|
+
const output = n; // same object, modified in place
|
|
19
|
+
if (!n.show)
|
|
20
|
+
output.show = 'all';
|
|
21
|
+
if (n.exclude)
|
|
22
|
+
output.exclude = n.exclude.split(',').map((s) => s.trim());
|
|
23
|
+
const apiUrl = process.env.JOURNALS_API_URL;
|
|
24
|
+
const url = new URL(`${apiUrl}sites/${n.venue}/collections`);
|
|
25
|
+
try {
|
|
26
|
+
const res = yield fetch(url.toString());
|
|
27
|
+
if (!res.ok)
|
|
28
|
+
throw new Error(`${res.status} ${res.statusText}`);
|
|
29
|
+
const data = (yield res.json());
|
|
30
|
+
if (output.exclude) {
|
|
31
|
+
output.items = data.items.filter((item) => { var _a; return !((_a = output.exclude) !== null && _a !== void 0 ? _a : []).includes(item.name); });
|
|
32
|
+
}
|
|
33
|
+
if (output.show !== 'all') {
|
|
34
|
+
output.items = output.items.filter((item) => item.open === (output.show === 'open'));
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
catch (e) {
|
|
38
|
+
output.error = 'Could not load collection listing';
|
|
39
|
+
console.error('Could not load collection listing', e);
|
|
40
|
+
}
|
|
41
|
+
}));
|
|
42
|
+
})));
|
|
43
|
+
});
|
|
44
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { PageLoader } from '@myst-theme/common';
|
|
2
|
+
import type { SiteDTO } from '@curvenote/common';
|
|
3
|
+
export * from './articles.js';
|
|
4
|
+
export * from './collections.js';
|
|
5
|
+
export * from './cards.js';
|
|
6
|
+
export * from './outputs.js';
|
|
7
|
+
export declare function applyCustomTransforms(site: SiteDTO, page: PageLoader): Promise<void>;
|
|
8
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/transforms/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAMjD,cAAc,eAAe,CAAC;AAC9B,cAAc,kBAAkB,CAAC;AACjC,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC;AAE7B,wBAAsB,qBAAqB,CAAC,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,UAAU,iBAK1E"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import { transformArticles } from './articles.js';
|
|
11
|
+
import { transformCollections } from './collections.js';
|
|
12
|
+
import { transformCards } from './cards.js';
|
|
13
|
+
import { transformDecorateNotebookOutputsWithSlugs } from './outputs.js';
|
|
14
|
+
export * from './articles.js';
|
|
15
|
+
export * from './collections.js';
|
|
16
|
+
export * from './cards.js';
|
|
17
|
+
export * from './outputs.js';
|
|
18
|
+
export function applyCustomTransforms(site, page) {
|
|
19
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
20
|
+
yield transformArticles(page.mdast);
|
|
21
|
+
yield transformCollections(page.mdast);
|
|
22
|
+
transformCards(site, page.mdast);
|
|
23
|
+
transformDecorateNotebookOutputsWithSlugs(page);
|
|
24
|
+
});
|
|
25
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"outputs.d.ts","sourceRoot":"","sources":["../../src/transforms/outputs.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAIrD,wBAAgB,yCAAyC,CAAC,IAAI,EAAE,UAAU,QAmBzE"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { normalizeLabel } from 'myst-common';
|
|
2
|
+
import { selectAll } from 'unist-util-select';
|
|
3
|
+
export function transformDecorateNotebookOutputsWithSlugs(page) {
|
|
4
|
+
selectAll('container[kind=figure]:has(output), embed:has(output), container[kind=table]:has(output)', page.mdast).forEach((node) => {
|
|
5
|
+
var _a, _b;
|
|
6
|
+
const { source } = node;
|
|
7
|
+
const output = selectAll('output', node);
|
|
8
|
+
if (source) {
|
|
9
|
+
const sideEffectOutput = output[0];
|
|
10
|
+
sideEffectOutput.notebookSlug = (_a = source.slug) !== null && _a !== void 0 ? _a : 'unknown';
|
|
11
|
+
sideEffectOutput.html_id = (_b = normalizeLabel(source.label)) === null || _b === void 0 ? void 0 : _b.html_id;
|
|
12
|
+
}
|
|
13
|
+
else {
|
|
14
|
+
console.warn(`no "source" on node`, node);
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
selectAll('block[kind=notebook-code] > output', page.mdast).forEach((node) => {
|
|
18
|
+
node.notebookSlug = page.slug;
|
|
19
|
+
});
|
|
20
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@curvenote/renderers",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -21,18 +21,20 @@
|
|
|
21
21
|
"build": "npm-run-all -l clean -p build:esm"
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@curvenote/
|
|
25
|
-
"@curvenote/ext-
|
|
26
|
-
"@curvenote/ext-
|
|
27
|
-
"@curvenote/ext-
|
|
28
|
-
"@curvenote/
|
|
24
|
+
"@curvenote/ext-blog": "^0.6.0",
|
|
25
|
+
"@curvenote/ext-footer": "^0.6.0",
|
|
26
|
+
"@curvenote/ext-landing": "^0.6.0",
|
|
27
|
+
"@curvenote/ext-person": "^0.6.0",
|
|
28
|
+
"@curvenote/theme": "^0.6.0",
|
|
29
29
|
"@heroicons/react": "^2.1.5",
|
|
30
|
-
"@myst-theme/providers": "^0.
|
|
30
|
+
"@myst-theme/providers": "^0.14.1",
|
|
31
31
|
"@scienceicons/myst": "^1.0.4",
|
|
32
32
|
"classnames": "^2.5.1",
|
|
33
33
|
"lucide-react": "^0.456.0",
|
|
34
|
-
"myst-to-react": "^0.
|
|
35
|
-
"
|
|
34
|
+
"myst-to-react": "^0.14.1",
|
|
35
|
+
"p-limit": "^3.1.0",
|
|
36
|
+
"swr": "^2.1.5",
|
|
37
|
+
"unist-util-select": "^4.0.3"
|
|
36
38
|
},
|
|
37
39
|
"peerDependencies": {
|
|
38
40
|
"react": "^16.8 || ^17.0 || ^18.0",
|