@datocms/astro 0.3.0 → 0.3.1
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/package.json
CHANGED
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
|
|
8
8
|
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
|
|
9
9
|
|
|
10
|
+
- [Setup](#setup)
|
|
10
11
|
- [Basic usage](#basic-usage)
|
|
11
12
|
- [Customization](#customization)
|
|
12
13
|
- [Custom components for blocks, inline records or links to records](#custom-components-for-blocks-inline-records-or-links-to-records)
|
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
type Block,
|
|
3
|
-
type InlineItem,
|
|
4
|
-
type ItemLink,
|
|
5
|
-
type Node,
|
|
6
|
-
RenderError,
|
|
7
|
-
type StructuredText,
|
|
8
|
-
isBlock,
|
|
9
|
-
isBlockquote,
|
|
10
|
-
isCode,
|
|
11
|
-
isHeading,
|
|
12
|
-
isInlineItem,
|
|
13
|
-
isItemLink,
|
|
14
|
-
isLink,
|
|
15
|
-
isList,
|
|
16
|
-
isListItem,
|
|
17
|
-
isParagraph,
|
|
18
|
-
isRoot,
|
|
19
|
-
isSpan,
|
|
20
|
-
isThematicBreak,
|
|
21
|
-
} from 'datocms-structured-text-utils';
|
|
22
|
-
|
|
23
|
-
import Blockquote from './nodes/Blockquote.astro';
|
|
24
|
-
import Code from './nodes/Code.astro';
|
|
25
|
-
import Heading from './nodes/Heading.astro';
|
|
26
|
-
import Link from './nodes/Link.astro';
|
|
27
|
-
import List from './nodes/List.astro';
|
|
28
|
-
import ListItem from './nodes/ListItem.astro';
|
|
29
|
-
import Paragraph from './nodes/Paragraph.astro';
|
|
30
|
-
import Root from './nodes/Root.astro';
|
|
31
|
-
import Span from './nodes/Span.astro';
|
|
32
|
-
import ThematicBreak from './nodes/ThematicBreak.astro';
|
|
33
|
-
|
|
34
|
-
import type { PredicateComponentTuple } from './types';
|
|
35
|
-
|
|
36
|
-
export const defaultComponents: PredicateComponentTuple[] = [
|
|
37
|
-
[isParagraph, Paragraph],
|
|
38
|
-
[isRoot, Root],
|
|
39
|
-
[isSpan, Span],
|
|
40
|
-
[isLink, Link],
|
|
41
|
-
[isList, List],
|
|
42
|
-
[isHeading, Heading],
|
|
43
|
-
[isBlockquote, Blockquote],
|
|
44
|
-
[isListItem, ListItem],
|
|
45
|
-
[isThematicBreak, ThematicBreak],
|
|
46
|
-
[isCode, Code],
|
|
47
|
-
];
|
|
48
|
-
|
|
49
|
-
export const throwRenderErrorForMissingComponent = (node: Node) => {
|
|
50
|
-
if (isInlineItem(node)) {
|
|
51
|
-
throw new RenderError(
|
|
52
|
-
`The Structured Text document contains an 'inlineItem' node, but no component for rendering is specified!`,
|
|
53
|
-
node,
|
|
54
|
-
);
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
if (isItemLink(node)) {
|
|
58
|
-
throw new RenderError(
|
|
59
|
-
`The Structured Text document contains an 'itemLink' node, but no component for rendering is specified!`,
|
|
60
|
-
node,
|
|
61
|
-
);
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
if (isBlock(node)) {
|
|
65
|
-
throw new RenderError(
|
|
66
|
-
`The Structured Text document contains a 'block' node, but no component for rendering is specified!`,
|
|
67
|
-
node,
|
|
68
|
-
);
|
|
69
|
-
}
|
|
70
|
-
};
|
|
71
|
-
|
|
72
|
-
export const throwRenderErrorForMissingBlock = (node: Block) => {
|
|
73
|
-
throw new RenderError(
|
|
74
|
-
`The Structured Text document contains a 'block' node, but cannot find a record with ID ${node.item} inside data.blocks!`,
|
|
75
|
-
node,
|
|
76
|
-
);
|
|
77
|
-
};
|
|
78
|
-
|
|
79
|
-
export const throwRenderErrorForMissingLink = (node: ItemLink | InlineItem) => {
|
|
80
|
-
throw new RenderError(
|
|
81
|
-
`The Structured Text document contains an 'itemLink' node, but cannot find a record with ID ${node.item} inside data.links!`,
|
|
82
|
-
node,
|
|
83
|
-
);
|
|
84
|
-
};
|
|
85
|
-
|
|
86
|
-
export const findBlock = (node: Block, blocks: StructuredText['blocks']) =>
|
|
87
|
-
(blocks || []).find(({ id }) => id === node.item);
|
|
88
|
-
|
|
89
|
-
export const findLink = (node: ItemLink | InlineItem, links: StructuredText['links']) =>
|
|
90
|
-
(links || []).find(({ id }) => id === node.item);
|