@mintlify/common 1.0.447 → 1.0.449
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/rss/index.d.ts +20 -1
- package/dist/rss/index.js +111 -0
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/dist/types/rss.d.ts +6 -0
- package/package.json +3 -3
package/dist/rss/index.d.ts
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
|
-
import type { FrontmatterContent, Root, RootContent } from 'mdast';
|
|
1
|
+
import type { FrontmatterContent, Heading, Parent, Root, RootContent } from 'mdast';
|
|
2
2
|
import { MdxJsxFlowElement } from 'mdast-util-mdx-jsx';
|
|
3
|
+
import { RSSItemV2 } from '../types/rss.js';
|
|
3
4
|
export declare const UPDATE_MAX = 15;
|
|
4
5
|
export type UpdateMDXComponent = MdxJsxFlowElement;
|
|
5
6
|
export declare const isFrontmatter: (node: RootContent | undefined) => node is FrontmatterContent;
|
|
6
7
|
export declare const isUpdate: (node: RootContent | undefined) => node is UpdateMDXComponent;
|
|
8
|
+
export declare const isHeading: (node: RootContent | undefined) => node is Heading;
|
|
9
|
+
export declare const isNormalMarkdown: (node: RootContent | undefined) => node is RootContent;
|
|
7
10
|
export declare const containsUpdates: (tree: Root) => boolean;
|
|
8
11
|
export declare const getTags: (node: UpdateMDXComponent) => string[] | undefined;
|
|
9
12
|
export declare const getRssPropsData: (updateComponent: UpdateMDXComponent) => {
|
|
@@ -16,3 +19,19 @@ export declare const compareUpdates: ({ newTree, previousTree, }: {
|
|
|
16
19
|
newTree: Root;
|
|
17
20
|
previousTree: Root;
|
|
18
21
|
}) => UpdateMDXComponent[];
|
|
22
|
+
export declare const matchRSSTitle: (node: MdxJsxFlowElement, title: string) => boolean;
|
|
23
|
+
export declare const splitChildrenAtHeadings: (children: RootContent[]) => RootContent[][];
|
|
24
|
+
export declare const getMarkdownHeadingProps: (heading: Parent) => {
|
|
25
|
+
title: string | undefined;
|
|
26
|
+
anchor: string | undefined;
|
|
27
|
+
};
|
|
28
|
+
export declare const updateGroupToRSSItemV2: ({ group, date, }: {
|
|
29
|
+
group: RootContent[];
|
|
30
|
+
date?: string;
|
|
31
|
+
}) => RSSItemV2 | undefined;
|
|
32
|
+
export declare const getNewContent: (newUpdateComponents: UpdateMDXComponent[]) => RSSItemV2[];
|
|
33
|
+
export declare const getNewMarkdownUpdates: ({ newTree, previousTree, previousUpdates, }: {
|
|
34
|
+
newTree: Root;
|
|
35
|
+
previousTree: Root;
|
|
36
|
+
previousUpdates: RSSItemV2[];
|
|
37
|
+
}) => RSSItemV2[];
|
package/dist/rss/index.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import slugify from '@sindresorhus/slugify';
|
|
2
|
+
import { stringifyTree } from '../mdx/index.js';
|
|
1
3
|
import { getArrayExpressionStringProperties, getObjectExpressionStringProperty, } from '../mdx/utils.js';
|
|
2
4
|
export const UPDATE_MAX = 15;
|
|
3
5
|
export const isFrontmatter = (node) => {
|
|
@@ -6,6 +8,22 @@ export const isFrontmatter = (node) => {
|
|
|
6
8
|
export const isUpdate = (node) => {
|
|
7
9
|
return (node === null || node === void 0 ? void 0 : node.type) === 'mdxJsxFlowElement' && node.name === 'Update';
|
|
8
10
|
};
|
|
11
|
+
export const isHeading = (node) => {
|
|
12
|
+
if (!node) {
|
|
13
|
+
return false;
|
|
14
|
+
}
|
|
15
|
+
return node.type === 'heading';
|
|
16
|
+
};
|
|
17
|
+
export const isNormalMarkdown = (node) => {
|
|
18
|
+
if (!node) {
|
|
19
|
+
return false;
|
|
20
|
+
}
|
|
21
|
+
return (node.type !== 'mdxJsxFlowElement' &&
|
|
22
|
+
node.type !== 'mdxJsxTextElement' &&
|
|
23
|
+
node.type !== 'html' &&
|
|
24
|
+
node.type !== 'code' &&
|
|
25
|
+
node.type !== 'inlineCode');
|
|
26
|
+
};
|
|
9
27
|
export const containsUpdates = (tree) => {
|
|
10
28
|
return tree.children.some((child) => isUpdate(child));
|
|
11
29
|
};
|
|
@@ -63,3 +81,96 @@ export const compareUpdates = ({ newTree, previousTree, }) => {
|
|
|
63
81
|
});
|
|
64
82
|
return newUpdates;
|
|
65
83
|
};
|
|
84
|
+
export const matchRSSTitle = (node, title) => {
|
|
85
|
+
const { rssTitle } = getRssPropsData(node);
|
|
86
|
+
const label = getUpdateTitle(node);
|
|
87
|
+
const nodeTitle = label || rssTitle;
|
|
88
|
+
return nodeTitle === title;
|
|
89
|
+
};
|
|
90
|
+
export const splitChildrenAtHeadings = (children) => {
|
|
91
|
+
return children.reduce((acc, child) => {
|
|
92
|
+
if (isHeading(child)) {
|
|
93
|
+
acc.push([child]);
|
|
94
|
+
}
|
|
95
|
+
else {
|
|
96
|
+
if (isNormalMarkdown(child)) {
|
|
97
|
+
if (acc.length === 0) {
|
|
98
|
+
acc.push([child]);
|
|
99
|
+
}
|
|
100
|
+
else {
|
|
101
|
+
const lastGroup = acc[acc.length - 1];
|
|
102
|
+
if (lastGroup) {
|
|
103
|
+
lastGroup.push(child);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
return acc;
|
|
109
|
+
}, []);
|
|
110
|
+
};
|
|
111
|
+
export const getMarkdownHeadingProps = (heading) => {
|
|
112
|
+
const headingContent = heading.children[0];
|
|
113
|
+
let title = undefined;
|
|
114
|
+
let anchor = undefined;
|
|
115
|
+
if ((headingContent === null || headingContent === void 0 ? void 0 : headingContent.type) === 'text') {
|
|
116
|
+
title = headingContent.value;
|
|
117
|
+
}
|
|
118
|
+
if (title) {
|
|
119
|
+
anchor = slugify(title);
|
|
120
|
+
}
|
|
121
|
+
return { title, anchor };
|
|
122
|
+
};
|
|
123
|
+
export const updateGroupToRSSItemV2 = ({ group, date, }) => {
|
|
124
|
+
const dateToUse = date || new Date().toISOString();
|
|
125
|
+
const heading = group[0];
|
|
126
|
+
if (!heading || !isHeading(heading)) {
|
|
127
|
+
return undefined;
|
|
128
|
+
}
|
|
129
|
+
const { title, anchor } = getMarkdownHeadingProps(heading);
|
|
130
|
+
const content = group.slice(1);
|
|
131
|
+
const contentString = stringifyTree({
|
|
132
|
+
type: 'root',
|
|
133
|
+
children: content,
|
|
134
|
+
});
|
|
135
|
+
if (!title || !anchor) {
|
|
136
|
+
return undefined;
|
|
137
|
+
}
|
|
138
|
+
return { title, date: dateToUse, anchor, content: contentString };
|
|
139
|
+
};
|
|
140
|
+
export const getNewContent = (newUpdateComponents) => {
|
|
141
|
+
const newUpdates = [];
|
|
142
|
+
for (const component of newUpdateComponents) {
|
|
143
|
+
const children = component.children;
|
|
144
|
+
const updatesByHeading = splitChildrenAtHeadings(children);
|
|
145
|
+
for (const group of updatesByHeading) {
|
|
146
|
+
const newUpdate = updateGroupToRSSItemV2({ group });
|
|
147
|
+
if (newUpdate) {
|
|
148
|
+
newUpdates.push(newUpdate);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
return newUpdates;
|
|
153
|
+
};
|
|
154
|
+
export const getNewMarkdownUpdates = ({ newTree, previousTree, previousUpdates, }) => {
|
|
155
|
+
const firstUpdateInNewTree = newTree.children.find(isUpdate);
|
|
156
|
+
const firstUpdateInPreviousTree = previousTree.children.find(isUpdate);
|
|
157
|
+
if (!isUpdate(firstUpdateInNewTree) || !isUpdate(firstUpdateInPreviousTree)) {
|
|
158
|
+
// no last updates found to compare
|
|
159
|
+
return [];
|
|
160
|
+
}
|
|
161
|
+
const firstUpdateTitleInNewTree = getUpdateTitle(firstUpdateInNewTree);
|
|
162
|
+
const firstUpdateTitleInPreviousTree = getUpdateTitle(firstUpdateInPreviousTree);
|
|
163
|
+
if (firstUpdateTitleInNewTree !== firstUpdateTitleInPreviousTree) {
|
|
164
|
+
// last update component has changed
|
|
165
|
+
return [];
|
|
166
|
+
}
|
|
167
|
+
const newUpdates = splitChildrenAtHeadings(firstUpdateInNewTree.children);
|
|
168
|
+
const actuallyNewUpdates = [];
|
|
169
|
+
for (const group of newUpdates) {
|
|
170
|
+
const newUpdate = updateGroupToRSSItemV2({ group });
|
|
171
|
+
if (newUpdate && !previousUpdates.find((update) => update.title === newUpdate.title)) {
|
|
172
|
+
actuallyNewUpdates.push(newUpdate);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
return actuallyNewUpdates;
|
|
176
|
+
};
|