@umami/shiso 0.17.0 → 0.19.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/index.d.ts +2 -2
- package/dist/index.js +107 -52
- package/dist/index.mjs +103 -48
- package/dist/server.d.ts +16 -5
- package/dist/server.js +60 -84
- package/package.json +2 -2
- package/server/index.d.ts +0 -29
- package/server/index.js +0 -183
package/dist/index.d.ts
CHANGED
|
@@ -26,9 +26,9 @@ declare module '@umami/shiso/Docs' {
|
|
|
26
26
|
|
|
27
27
|
declare module '@umami/shiso/Shiso' {
|
|
28
28
|
import { JSX } from 'react';
|
|
29
|
-
import type { ShisoConfig } from '@/lib/types';
|
|
29
|
+
import type { ShisoConfig, ShisoContent } from '@/lib/types';
|
|
30
30
|
export interface ShisoProps {
|
|
31
|
-
content:
|
|
31
|
+
content: ShisoContent;
|
|
32
32
|
type: string;
|
|
33
33
|
config: ShisoConfig;
|
|
34
34
|
components?: {
|
package/dist/index.js
CHANGED
|
@@ -59,9 +59,9 @@ var parseMdx = (code) => {
|
|
|
59
59
|
return { error: err.message };
|
|
60
60
|
}
|
|
61
61
|
};
|
|
62
|
-
function Markdown({
|
|
62
|
+
function Markdown({ code }) {
|
|
63
63
|
const components = (0, import_react.useMDXComponents)();
|
|
64
|
-
const { Component, error } = parseMdx(
|
|
64
|
+
const { Component, error } = parseMdx(code);
|
|
65
65
|
if (error) {
|
|
66
66
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("h1", { children: [
|
|
67
67
|
"Error rendering MDX: ",
|
|
@@ -74,13 +74,22 @@ function Markdown({ content }) {
|
|
|
74
74
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Component, { components });
|
|
75
75
|
}
|
|
76
76
|
|
|
77
|
-
// src/components/
|
|
77
|
+
// src/components/Blogs.tsx
|
|
78
78
|
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
79
|
+
function Blogs() {
|
|
80
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("h1", { children: "All the blogs!" });
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// src/components/Blog.tsx
|
|
84
|
+
var import_jsx_runtime3 = require("react/jsx-runtime");
|
|
79
85
|
function Blog({ content }) {
|
|
80
|
-
|
|
81
|
-
/* @__PURE__ */ (0,
|
|
82
|
-
|
|
83
|
-
|
|
86
|
+
if (!content) {
|
|
87
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(Blogs, {});
|
|
88
|
+
}
|
|
89
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { className: Blog_default.blog, children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { className: Blog_default.main, children: /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: Blog_default.content, children: [
|
|
90
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("h1", { children: content?.meta?.title }),
|
|
91
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("p", { className: Blog_default.description, children: content?.meta?.description }),
|
|
92
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(Markdown, { code: content?.code })
|
|
84
93
|
] }) }) });
|
|
85
94
|
}
|
|
86
95
|
|
|
@@ -102,7 +111,7 @@ var import_react_zen = require("@umami/react-zen");
|
|
|
102
111
|
var CodeBlock_default = { "container": "CodeBlock_container__YmFmN", "button": "CodeBlock_button__NDg0Y", "copy": "CodeBlock_copy__MmQzM", "check": "CodeBlock_check__YmI0Z" };
|
|
103
112
|
|
|
104
113
|
// src/components/CodeBlock.tsx
|
|
105
|
-
var
|
|
114
|
+
var import_jsx_runtime4 = require("react/jsx-runtime");
|
|
106
115
|
function CodeBlock(props) {
|
|
107
116
|
const textInput = (0, import_react2.useRef)(null);
|
|
108
117
|
const [copied, setCopied] = (0, import_react2.useState)(false);
|
|
@@ -113,14 +122,14 @@ function CodeBlock(props) {
|
|
|
113
122
|
setCopied(false);
|
|
114
123
|
}, 1e3);
|
|
115
124
|
};
|
|
116
|
-
return /* @__PURE__ */ (0,
|
|
125
|
+
return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("pre", { ref: textInput, className: CodeBlock_default.container, children: [
|
|
117
126
|
props.children,
|
|
118
|
-
/* @__PURE__ */ (0,
|
|
127
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("button", { "aria-label": "Copy code", className: CodeBlock_default.button, onClick: handleCopy, children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_react_zen.Icon, { size: "sm", className: copied ? CodeBlock_default.check : CodeBlock_default.copy, children: copied ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_react_zen.Icons.Check, {}) : /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_react_zen.Icons.Copy, {}) }) })
|
|
119
128
|
] });
|
|
120
129
|
}
|
|
121
130
|
|
|
122
131
|
// src/components/Shiso.tsx
|
|
123
|
-
var
|
|
132
|
+
var import_jsx_runtime5 = require("react/jsx-runtime");
|
|
124
133
|
var defaultTemplates = {
|
|
125
134
|
docs: Docs,
|
|
126
135
|
blog: Blog
|
|
@@ -129,9 +138,9 @@ var ShisoContext = (0, import_react3.createContext)(null);
|
|
|
129
138
|
function Shiso({ content, type, config, components, templates }) {
|
|
130
139
|
const Component = { ...defaultTemplates, ...templates }[type];
|
|
131
140
|
if (!Component) {
|
|
132
|
-
return /* @__PURE__ */ (0,
|
|
141
|
+
return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("h1", { children: `Component not found for type: ${type}` });
|
|
133
142
|
}
|
|
134
|
-
return /* @__PURE__ */ (0,
|
|
143
|
+
return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(ShisoContext.Provider, { value: { content, type, config }, children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_react4.MDXProvider, { components: { ...components, pre: CodeBlock }, children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Component, { content, config }) }) });
|
|
135
144
|
}
|
|
136
145
|
|
|
137
146
|
// src/components/hooks/useShiso.ts
|
|
@@ -149,7 +158,7 @@ var import_classnames = __toESM(require("classnames"));
|
|
|
149
158
|
var PageLinks_default = { "title": "PageLinks_title__YjEwN", "links": "PageLinks_links__OWRlM", "link": "PageLinks_link__NDJjM", "indent-1": "PageLinks_indent-1__MDU1M", "indent-2": "PageLinks_indent-2__MDBmY", "indent-3": "PageLinks_indent-3__ZmY2O", "indent-4": "PageLinks_indent-4__MDA4N", "indent-5": "PageLinks_indent-5__MDBlM", "indent-6": "PageLinks_indent-6__NjIwM", "selected": "PageLinks_selected__NjEyY" };
|
|
150
159
|
|
|
151
160
|
// src/components/PageLinks.tsx
|
|
152
|
-
var
|
|
161
|
+
var import_jsx_runtime6 = require("react/jsx-runtime");
|
|
153
162
|
function PageLinks({ items, offset = 0 }) {
|
|
154
163
|
const [hash, setHash] = (0, import_react6.useState)(items?.[0]?.id);
|
|
155
164
|
(0, import_react6.useEffect)(() => {
|
|
@@ -168,10 +177,10 @@ function PageLinks({ items, offset = 0 }) {
|
|
|
168
177
|
if (!items?.length) {
|
|
169
178
|
return null;
|
|
170
179
|
}
|
|
171
|
-
return /* @__PURE__ */ (0,
|
|
172
|
-
/* @__PURE__ */ (0,
|
|
180
|
+
return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(import_react_zen2.Column, { gap: "3", minWidth: "240px", className: PageLinks_default.links, children: [
|
|
181
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_react_zen2.Text, { size: "2", weight: "bold", children: "On this page" }),
|
|
173
182
|
items.map(({ name, id, size }) => {
|
|
174
|
-
return /* @__PURE__ */ (0,
|
|
183
|
+
return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
175
184
|
"a",
|
|
176
185
|
{
|
|
177
186
|
href: `#${id}`,
|
|
@@ -196,24 +205,24 @@ var import_link = __toESM(require("next/link"));
|
|
|
196
205
|
var SideNav_default = { "nav": "SideNav_nav__YWMxN", "item": "SideNav_item__YTQzN", "selected": "SideNav_selected__ZDI0N", "items": "SideNav_items__Y2YwZ" };
|
|
197
206
|
|
|
198
207
|
// src/components/SideNav.tsx
|
|
199
|
-
var
|
|
208
|
+
var import_jsx_runtime7 = require("react/jsx-runtime");
|
|
200
209
|
function SideNav({ tabs, navigation }) {
|
|
201
210
|
const pathname = (0, import_navigation.usePathname)();
|
|
202
211
|
const tab = tabs?.find(({ url, id }) => id !== "docs" ? pathname.startsWith(url) : false);
|
|
203
212
|
const menu = navigation[tab?.id || "docs"];
|
|
204
|
-
return /* @__PURE__ */ (0,
|
|
205
|
-
return /* @__PURE__ */ (0,
|
|
206
|
-
return /* @__PURE__ */ (0,
|
|
213
|
+
return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_react_zen3.Box, { className: SideNav_default.nav, children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_react_zen3.List, { items: navigation, "aria-label": "nav", children: menu.map(({ section, pages }) => {
|
|
214
|
+
return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_react_zen3.ListSection, { title: section, className: SideNav_default.items, children: pages.map(({ label: text, url }, index) => {
|
|
215
|
+
return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
|
|
207
216
|
import_react_zen3.ListItem,
|
|
208
217
|
{
|
|
209
218
|
className: (0, import_classnames2.default)(SideNav_default.item, {
|
|
210
219
|
[SideNav_default.selected]: url === pathname
|
|
211
220
|
}),
|
|
212
|
-
children: /* @__PURE__ */ (0,
|
|
221
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_link.default, { href: url, prefetch: false, children: text })
|
|
213
222
|
},
|
|
214
223
|
index
|
|
215
224
|
);
|
|
216
|
-
}) },
|
|
225
|
+
}) }, section);
|
|
217
226
|
}) }) });
|
|
218
227
|
}
|
|
219
228
|
|
|
@@ -221,13 +230,13 @@ function SideNav({ tabs, navigation }) {
|
|
|
221
230
|
var import_link2 = __toESM(require("next/link"));
|
|
222
231
|
var import_navigation2 = require("next/navigation");
|
|
223
232
|
var import_react_zen4 = require("@umami/react-zen");
|
|
224
|
-
var
|
|
233
|
+
var import_jsx_runtime8 = require("react/jsx-runtime");
|
|
225
234
|
function TopNav({ tabs }) {
|
|
226
235
|
const pathname = (0, import_navigation2.usePathname)();
|
|
227
236
|
const tab = tabs?.find(({ id, url }) => id !== "docs" ? pathname.startsWith(url) : false);
|
|
228
237
|
const selected = tab?.id || "docs";
|
|
229
|
-
return /* @__PURE__ */ (0,
|
|
230
|
-
return /* @__PURE__ */ (0,
|
|
238
|
+
return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_react_zen4.Tabs, { selectedKey: selected, children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_react_zen4.TabList, { items: tabs, children: ({ id, label, url }) => {
|
|
239
|
+
return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_react_zen4.Tab, { id, children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_link2.default, { href: url, children: label }) });
|
|
231
240
|
} }) });
|
|
232
241
|
}
|
|
233
242
|
|
|
@@ -238,40 +247,86 @@ var import_react_zen5 = require("@umami/react-zen");
|
|
|
238
247
|
var ContentArea_default = { "content": "ContentArea_content__OTBiZ" };
|
|
239
248
|
|
|
240
249
|
// src/components/ContentArea.tsx
|
|
241
|
-
var
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
/* @__PURE__ */ (0,
|
|
246
|
-
/* @__PURE__ */ (0,
|
|
247
|
-
/* @__PURE__ */ (0,
|
|
250
|
+
var import_link3 = __toESM(require("next/link"));
|
|
251
|
+
var import_jsx_runtime9 = require("react/jsx-runtime");
|
|
252
|
+
function ContentArea({ section, title, description, code, next, prev }) {
|
|
253
|
+
return /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(import_react_zen5.Box, { flexGrow: 1, children: [
|
|
254
|
+
section && /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_react_zen5.Text, { color: "primary", weight: "bold", children: section }),
|
|
255
|
+
title && /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_react_zen5.Heading, { size: "8", as: "h1", children: title }),
|
|
256
|
+
description && /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_react_zen5.Text, { color: "muted", children: description }),
|
|
257
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_react_zen5.Box, { className: ContentArea_default.content, children: /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(Markdown, { code }) }),
|
|
258
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(import_react_zen5.Row, { justifyContent: "space-between", children: [
|
|
259
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)(NavigationButton, { ...prev, isPrev: true }),
|
|
260
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)(NavigationButton, { ...next })
|
|
261
|
+
] })
|
|
248
262
|
] });
|
|
249
263
|
}
|
|
264
|
+
var NavigationButton = ({
|
|
265
|
+
label,
|
|
266
|
+
url,
|
|
267
|
+
isPrev
|
|
268
|
+
}) => {
|
|
269
|
+
if (!url || !label) {
|
|
270
|
+
return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_react_zen5.Box, {});
|
|
271
|
+
}
|
|
272
|
+
return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_link3.default, { href: url, children: /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(import_react_zen5.Row, { alignItems: "center", gap: "3", marginY: "3", children: [
|
|
273
|
+
isPrev && /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_react_zen5.Icon, { size: "sm", rotate: 180, children: /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_react_zen5.Icons.Chevron, {}) }),
|
|
274
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_react_zen5.Text, { size: "3", weight: "bold", children: label }),
|
|
275
|
+
!isPrev && /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_react_zen5.Icon, { size: "sm", children: /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_react_zen5.Icons.Chevron, {}) })
|
|
276
|
+
] }) });
|
|
277
|
+
};
|
|
250
278
|
|
|
251
279
|
// src/components/Docs.tsx
|
|
252
|
-
var
|
|
280
|
+
var import_jsx_runtime10 = require("react/jsx-runtime");
|
|
281
|
+
function parseContent(content, config = {}) {
|
|
282
|
+
const { tabs, navigation } = config;
|
|
283
|
+
const keys = Object.keys(navigation);
|
|
284
|
+
let next, prev, section, found;
|
|
285
|
+
keys.forEach((key) => {
|
|
286
|
+
if (!found) {
|
|
287
|
+
const groups = navigation[key];
|
|
288
|
+
found = groups?.find((group, groupIndex) => {
|
|
289
|
+
return group.pages.find((page, pageIndex) => {
|
|
290
|
+
const match = content.path.replace(/(\/index)?\.mdx$/, "").endsWith(page.url);
|
|
291
|
+
if (match) {
|
|
292
|
+
const prevGroup = groups[groupIndex - 1];
|
|
293
|
+
const nextGroup = groups[groupIndex + 1];
|
|
294
|
+
prev = group.pages[pageIndex - 1] || prevGroup?.pages?.at(-1);
|
|
295
|
+
next = group.pages[pageIndex + 1] || nextGroup?.pages?.[0];
|
|
296
|
+
section = group.section;
|
|
297
|
+
}
|
|
298
|
+
return match;
|
|
299
|
+
});
|
|
300
|
+
});
|
|
301
|
+
}
|
|
302
|
+
});
|
|
303
|
+
return { ...content, tabs, navigation, section, next, prev };
|
|
304
|
+
}
|
|
253
305
|
function Docs() {
|
|
254
306
|
const { content, config } = useShiso();
|
|
255
307
|
if (!content) {
|
|
256
|
-
return /* @__PURE__ */ (0,
|
|
308
|
+
return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(import_react_zen6.Heading, { size: "6", children: "Page not found" });
|
|
257
309
|
}
|
|
258
|
-
const { tabs, navigation
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
})
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
310
|
+
const { tabs, navigation, code, meta, section, next, prev, anchors } = parseContent(
|
|
311
|
+
content,
|
|
312
|
+
config?.docs
|
|
313
|
+
);
|
|
314
|
+
return /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(import_react_zen6.Box, { flexGrow: "1", children: [
|
|
315
|
+
tabs && /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(TopNav, { tabs }),
|
|
316
|
+
/* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(import_react_zen6.Grid, { gap: "6", columns: "240px 1fr 240px", children: [
|
|
317
|
+
/* @__PURE__ */ (0, import_jsx_runtime10.jsx)(SideNav, { tabs, navigation }),
|
|
318
|
+
/* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
|
|
319
|
+
ContentArea,
|
|
320
|
+
{
|
|
321
|
+
section,
|
|
322
|
+
title: meta?.title,
|
|
323
|
+
description: meta?.description,
|
|
324
|
+
code,
|
|
325
|
+
next,
|
|
326
|
+
prev
|
|
327
|
+
}
|
|
328
|
+
),
|
|
329
|
+
/* @__PURE__ */ (0, import_jsx_runtime10.jsx)(PageLinks, { items: anchors, offset: 150 })
|
|
275
330
|
] })
|
|
276
331
|
] });
|
|
277
332
|
}
|
package/dist/index.mjs
CHANGED
|
@@ -23,9 +23,9 @@ var parseMdx = (code) => {
|
|
|
23
23
|
return { error: err.message };
|
|
24
24
|
}
|
|
25
25
|
};
|
|
26
|
-
function Markdown({
|
|
26
|
+
function Markdown({ code }) {
|
|
27
27
|
const components = useMDXComponents();
|
|
28
|
-
const { Component, error } = parseMdx(
|
|
28
|
+
const { Component, error } = parseMdx(code);
|
|
29
29
|
if (error) {
|
|
30
30
|
return /* @__PURE__ */ jsxs("h1", { children: [
|
|
31
31
|
"Error rendering MDX: ",
|
|
@@ -38,13 +38,22 @@ function Markdown({ content }) {
|
|
|
38
38
|
return /* @__PURE__ */ jsx(Component, { components });
|
|
39
39
|
}
|
|
40
40
|
|
|
41
|
+
// src/components/Blogs.tsx
|
|
42
|
+
import { jsx as jsx2 } from "react/jsx-runtime";
|
|
43
|
+
function Blogs() {
|
|
44
|
+
return /* @__PURE__ */ jsx2("h1", { children: "All the blogs!" });
|
|
45
|
+
}
|
|
46
|
+
|
|
41
47
|
// src/components/Blog.tsx
|
|
42
|
-
import { jsx as
|
|
48
|
+
import { jsx as jsx3, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
43
49
|
function Blog({ content }) {
|
|
44
|
-
|
|
45
|
-
/* @__PURE__ */
|
|
46
|
-
|
|
47
|
-
|
|
50
|
+
if (!content) {
|
|
51
|
+
return /* @__PURE__ */ jsx3(Blogs, {});
|
|
52
|
+
}
|
|
53
|
+
return /* @__PURE__ */ jsx3("div", { className: Blog_default.blog, children: /* @__PURE__ */ jsx3("div", { className: Blog_default.main, children: /* @__PURE__ */ jsxs2("div", { className: Blog_default.content, children: [
|
|
54
|
+
/* @__PURE__ */ jsx3("h1", { children: content?.meta?.title }),
|
|
55
|
+
/* @__PURE__ */ jsx3("p", { className: Blog_default.description, children: content?.meta?.description }),
|
|
56
|
+
/* @__PURE__ */ jsx3(Markdown, { code: content?.code })
|
|
48
57
|
] }) }) });
|
|
49
58
|
}
|
|
50
59
|
|
|
@@ -66,7 +75,7 @@ import { Icon, Icons } from "@umami/react-zen";
|
|
|
66
75
|
var CodeBlock_default = { "container": "CodeBlock_container__YmFmN", "button": "CodeBlock_button__NDg0Y", "copy": "CodeBlock_copy__MmQzM", "check": "CodeBlock_check__YmI0Z" };
|
|
67
76
|
|
|
68
77
|
// src/components/CodeBlock.tsx
|
|
69
|
-
import { jsx as
|
|
78
|
+
import { jsx as jsx4, jsxs as jsxs3 } from "react/jsx-runtime";
|
|
70
79
|
function CodeBlock(props) {
|
|
71
80
|
const textInput = useRef(null);
|
|
72
81
|
const [copied, setCopied] = useState(false);
|
|
@@ -79,12 +88,12 @@ function CodeBlock(props) {
|
|
|
79
88
|
};
|
|
80
89
|
return /* @__PURE__ */ jsxs3("pre", { ref: textInput, className: CodeBlock_default.container, children: [
|
|
81
90
|
props.children,
|
|
82
|
-
/* @__PURE__ */
|
|
91
|
+
/* @__PURE__ */ jsx4("button", { "aria-label": "Copy code", className: CodeBlock_default.button, onClick: handleCopy, children: /* @__PURE__ */ jsx4(Icon, { size: "sm", className: copied ? CodeBlock_default.check : CodeBlock_default.copy, children: copied ? /* @__PURE__ */ jsx4(Icons.Check, {}) : /* @__PURE__ */ jsx4(Icons.Copy, {}) }) })
|
|
83
92
|
] });
|
|
84
93
|
}
|
|
85
94
|
|
|
86
95
|
// src/components/Shiso.tsx
|
|
87
|
-
import { jsx as
|
|
96
|
+
import { jsx as jsx5 } from "react/jsx-runtime";
|
|
88
97
|
var defaultTemplates = {
|
|
89
98
|
docs: Docs,
|
|
90
99
|
blog: Blog
|
|
@@ -93,9 +102,9 @@ var ShisoContext = createContext(null);
|
|
|
93
102
|
function Shiso({ content, type, config, components, templates }) {
|
|
94
103
|
const Component = { ...defaultTemplates, ...templates }[type];
|
|
95
104
|
if (!Component) {
|
|
96
|
-
return /* @__PURE__ */
|
|
105
|
+
return /* @__PURE__ */ jsx5("h1", { children: `Component not found for type: ${type}` });
|
|
97
106
|
}
|
|
98
|
-
return /* @__PURE__ */
|
|
107
|
+
return /* @__PURE__ */ jsx5(ShisoContext.Provider, { value: { content, type, config }, children: /* @__PURE__ */ jsx5(MDXProvider, { components: { ...components, pre: CodeBlock }, children: /* @__PURE__ */ jsx5(Component, { content, config }) }) });
|
|
99
108
|
}
|
|
100
109
|
|
|
101
110
|
// src/components/hooks/useShiso.ts
|
|
@@ -113,7 +122,7 @@ import classNames from "classnames";
|
|
|
113
122
|
var PageLinks_default = { "title": "PageLinks_title__YjEwN", "links": "PageLinks_links__OWRlM", "link": "PageLinks_link__NDJjM", "indent-1": "PageLinks_indent-1__MDU1M", "indent-2": "PageLinks_indent-2__MDBmY", "indent-3": "PageLinks_indent-3__ZmY2O", "indent-4": "PageLinks_indent-4__MDA4N", "indent-5": "PageLinks_indent-5__MDBlM", "indent-6": "PageLinks_indent-6__NjIwM", "selected": "PageLinks_selected__NjEyY" };
|
|
114
123
|
|
|
115
124
|
// src/components/PageLinks.tsx
|
|
116
|
-
import { jsx as
|
|
125
|
+
import { jsx as jsx6, jsxs as jsxs4 } from "react/jsx-runtime";
|
|
117
126
|
function PageLinks({ items, offset = 0 }) {
|
|
118
127
|
const [hash, setHash] = useState2(items?.[0]?.id);
|
|
119
128
|
useEffect(() => {
|
|
@@ -133,9 +142,9 @@ function PageLinks({ items, offset = 0 }) {
|
|
|
133
142
|
return null;
|
|
134
143
|
}
|
|
135
144
|
return /* @__PURE__ */ jsxs4(Column, { gap: "3", minWidth: "240px", className: PageLinks_default.links, children: [
|
|
136
|
-
/* @__PURE__ */
|
|
145
|
+
/* @__PURE__ */ jsx6(Text, { size: "2", weight: "bold", children: "On this page" }),
|
|
137
146
|
items.map(({ name, id, size }) => {
|
|
138
|
-
return /* @__PURE__ */
|
|
147
|
+
return /* @__PURE__ */ jsx6(
|
|
139
148
|
"a",
|
|
140
149
|
{
|
|
141
150
|
href: `#${id}`,
|
|
@@ -160,24 +169,24 @@ import Link from "next/link";
|
|
|
160
169
|
var SideNav_default = { "nav": "SideNav_nav__YWMxN", "item": "SideNav_item__YTQzN", "selected": "SideNav_selected__ZDI0N", "items": "SideNav_items__Y2YwZ" };
|
|
161
170
|
|
|
162
171
|
// src/components/SideNav.tsx
|
|
163
|
-
import { jsx as
|
|
172
|
+
import { jsx as jsx7 } from "react/jsx-runtime";
|
|
164
173
|
function SideNav({ tabs, navigation }) {
|
|
165
174
|
const pathname = usePathname();
|
|
166
175
|
const tab = tabs?.find(({ url, id }) => id !== "docs" ? pathname.startsWith(url) : false);
|
|
167
176
|
const menu = navigation[tab?.id || "docs"];
|
|
168
|
-
return /* @__PURE__ */
|
|
169
|
-
return /* @__PURE__ */
|
|
170
|
-
return /* @__PURE__ */
|
|
177
|
+
return /* @__PURE__ */ jsx7(Box, { className: SideNav_default.nav, children: /* @__PURE__ */ jsx7(List, { items: navigation, "aria-label": "nav", children: menu.map(({ section, pages }) => {
|
|
178
|
+
return /* @__PURE__ */ jsx7(ListSection, { title: section, className: SideNav_default.items, children: pages.map(({ label: text, url }, index) => {
|
|
179
|
+
return /* @__PURE__ */ jsx7(
|
|
171
180
|
ListItem,
|
|
172
181
|
{
|
|
173
182
|
className: classNames2(SideNav_default.item, {
|
|
174
183
|
[SideNav_default.selected]: url === pathname
|
|
175
184
|
}),
|
|
176
|
-
children: /* @__PURE__ */
|
|
185
|
+
children: /* @__PURE__ */ jsx7(Link, { href: url, prefetch: false, children: text })
|
|
177
186
|
},
|
|
178
187
|
index
|
|
179
188
|
);
|
|
180
|
-
}) },
|
|
189
|
+
}) }, section);
|
|
181
190
|
}) }) });
|
|
182
191
|
}
|
|
183
192
|
|
|
@@ -185,57 +194,103 @@ function SideNav({ tabs, navigation }) {
|
|
|
185
194
|
import Link2 from "next/link";
|
|
186
195
|
import { usePathname as usePathname2 } from "next/navigation";
|
|
187
196
|
import { Tabs, TabList, Tab } from "@umami/react-zen";
|
|
188
|
-
import { jsx as
|
|
197
|
+
import { jsx as jsx8 } from "react/jsx-runtime";
|
|
189
198
|
function TopNav({ tabs }) {
|
|
190
199
|
const pathname = usePathname2();
|
|
191
200
|
const tab = tabs?.find(({ id, url }) => id !== "docs" ? pathname.startsWith(url) : false);
|
|
192
201
|
const selected = tab?.id || "docs";
|
|
193
|
-
return /* @__PURE__ */
|
|
194
|
-
return /* @__PURE__ */
|
|
202
|
+
return /* @__PURE__ */ jsx8(Tabs, { selectedKey: selected, children: /* @__PURE__ */ jsx8(TabList, { items: tabs, children: ({ id, label, url }) => {
|
|
203
|
+
return /* @__PURE__ */ jsx8(Tab, { id, children: /* @__PURE__ */ jsx8(Link2, { href: url, children: label }) });
|
|
195
204
|
} }) });
|
|
196
205
|
}
|
|
197
206
|
|
|
198
207
|
// src/components/ContentArea.tsx
|
|
199
|
-
import { Heading, Box as Box2, Text as Text2 } from "@umami/react-zen";
|
|
208
|
+
import { Heading, Box as Box2, Text as Text2, Row, Icon as Icon2, Icons as Icons2 } from "@umami/react-zen";
|
|
200
209
|
|
|
201
210
|
// css-modules:/Users/mikecao/Development/umami-software/shiso/src/components/ContentArea.module.css
|
|
202
211
|
var ContentArea_default = { "content": "ContentArea_content__OTBiZ" };
|
|
203
212
|
|
|
204
213
|
// src/components/ContentArea.tsx
|
|
205
|
-
import
|
|
206
|
-
|
|
214
|
+
import Link3 from "next/link";
|
|
215
|
+
import { jsx as jsx9, jsxs as jsxs5 } from "react/jsx-runtime";
|
|
216
|
+
function ContentArea({ section, title, description, code, next, prev }) {
|
|
207
217
|
return /* @__PURE__ */ jsxs5(Box2, { flexGrow: 1, children: [
|
|
208
|
-
/* @__PURE__ */
|
|
209
|
-
/* @__PURE__ */
|
|
210
|
-
/* @__PURE__ */
|
|
211
|
-
/* @__PURE__ */
|
|
218
|
+
section && /* @__PURE__ */ jsx9(Text2, { color: "primary", weight: "bold", children: section }),
|
|
219
|
+
title && /* @__PURE__ */ jsx9(Heading, { size: "8", as: "h1", children: title }),
|
|
220
|
+
description && /* @__PURE__ */ jsx9(Text2, { color: "muted", children: description }),
|
|
221
|
+
/* @__PURE__ */ jsx9(Box2, { className: ContentArea_default.content, children: /* @__PURE__ */ jsx9(Markdown, { code }) }),
|
|
222
|
+
/* @__PURE__ */ jsxs5(Row, { justifyContent: "space-between", children: [
|
|
223
|
+
/* @__PURE__ */ jsx9(NavigationButton, { ...prev, isPrev: true }),
|
|
224
|
+
/* @__PURE__ */ jsx9(NavigationButton, { ...next })
|
|
225
|
+
] })
|
|
212
226
|
] });
|
|
213
227
|
}
|
|
228
|
+
var NavigationButton = ({
|
|
229
|
+
label,
|
|
230
|
+
url,
|
|
231
|
+
isPrev
|
|
232
|
+
}) => {
|
|
233
|
+
if (!url || !label) {
|
|
234
|
+
return /* @__PURE__ */ jsx9(Box2, {});
|
|
235
|
+
}
|
|
236
|
+
return /* @__PURE__ */ jsx9(Link3, { href: url, children: /* @__PURE__ */ jsxs5(Row, { alignItems: "center", gap: "3", marginY: "3", children: [
|
|
237
|
+
isPrev && /* @__PURE__ */ jsx9(Icon2, { size: "sm", rotate: 180, children: /* @__PURE__ */ jsx9(Icons2.Chevron, {}) }),
|
|
238
|
+
/* @__PURE__ */ jsx9(Text2, { size: "3", weight: "bold", children: label }),
|
|
239
|
+
!isPrev && /* @__PURE__ */ jsx9(Icon2, { size: "sm", children: /* @__PURE__ */ jsx9(Icons2.Chevron, {}) })
|
|
240
|
+
] }) });
|
|
241
|
+
};
|
|
214
242
|
|
|
215
243
|
// src/components/Docs.tsx
|
|
216
|
-
import { jsx as
|
|
244
|
+
import { jsx as jsx10, jsxs as jsxs6 } from "react/jsx-runtime";
|
|
245
|
+
function parseContent(content, config = {}) {
|
|
246
|
+
const { tabs, navigation } = config;
|
|
247
|
+
const keys = Object.keys(navigation);
|
|
248
|
+
let next, prev, section, found;
|
|
249
|
+
keys.forEach((key) => {
|
|
250
|
+
if (!found) {
|
|
251
|
+
const groups = navigation[key];
|
|
252
|
+
found = groups?.find((group, groupIndex) => {
|
|
253
|
+
return group.pages.find((page, pageIndex) => {
|
|
254
|
+
const match = content.path.replace(/(\/index)?\.mdx$/, "").endsWith(page.url);
|
|
255
|
+
if (match) {
|
|
256
|
+
const prevGroup = groups[groupIndex - 1];
|
|
257
|
+
const nextGroup = groups[groupIndex + 1];
|
|
258
|
+
prev = group.pages[pageIndex - 1] || prevGroup?.pages?.at(-1);
|
|
259
|
+
next = group.pages[pageIndex + 1] || nextGroup?.pages?.[0];
|
|
260
|
+
section = group.section;
|
|
261
|
+
}
|
|
262
|
+
return match;
|
|
263
|
+
});
|
|
264
|
+
});
|
|
265
|
+
}
|
|
266
|
+
});
|
|
267
|
+
return { ...content, tabs, navigation, section, next, prev };
|
|
268
|
+
}
|
|
217
269
|
function Docs() {
|
|
218
270
|
const { content, config } = useShiso();
|
|
219
271
|
if (!content) {
|
|
220
|
-
return /* @__PURE__ */
|
|
272
|
+
return /* @__PURE__ */ jsx10(Heading2, { size: "6", children: "Page not found" });
|
|
221
273
|
}
|
|
222
|
-
const { tabs, navigation
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
return section.pages.find(
|
|
227
|
-
(page) => page.url === `/docs/${content.id}` || page.url === `/docs` && content.id === "index"
|
|
228
|
-
);
|
|
229
|
-
})?.group;
|
|
230
|
-
}
|
|
231
|
-
return name;
|
|
232
|
-
}, null);
|
|
274
|
+
const { tabs, navigation, code, meta, section, next, prev, anchors } = parseContent(
|
|
275
|
+
content,
|
|
276
|
+
config?.docs
|
|
277
|
+
);
|
|
233
278
|
return /* @__PURE__ */ jsxs6(Box3, { flexGrow: "1", children: [
|
|
234
|
-
tabs && /* @__PURE__ */
|
|
279
|
+
tabs && /* @__PURE__ */ jsx10(TopNav, { tabs }),
|
|
235
280
|
/* @__PURE__ */ jsxs6(Grid, { gap: "6", columns: "240px 1fr 240px", children: [
|
|
236
|
-
/* @__PURE__ */
|
|
237
|
-
/* @__PURE__ */
|
|
238
|
-
|
|
281
|
+
/* @__PURE__ */ jsx10(SideNav, { tabs, navigation }),
|
|
282
|
+
/* @__PURE__ */ jsx10(
|
|
283
|
+
ContentArea,
|
|
284
|
+
{
|
|
285
|
+
section,
|
|
286
|
+
title: meta?.title,
|
|
287
|
+
description: meta?.description,
|
|
288
|
+
code,
|
|
289
|
+
next,
|
|
290
|
+
prev
|
|
291
|
+
}
|
|
292
|
+
),
|
|
293
|
+
/* @__PURE__ */ jsx10(PageLinks, { items: anchors, offset: 150 })
|
|
239
294
|
] })
|
|
240
295
|
] });
|
|
241
296
|
}
|
package/dist/server.d.ts
CHANGED
|
@@ -6,17 +6,28 @@
|
|
|
6
6
|
declare module '@umami/shiso/server' {
|
|
7
7
|
import { ReactElement } from 'react';
|
|
8
8
|
import type { ShisoConfig } from '@/lib/types';
|
|
9
|
-
export const getContent: (
|
|
10
|
-
|
|
9
|
+
export const getContent: (file: string) => Promise<{
|
|
10
|
+
path: string;
|
|
11
|
+
meta: {
|
|
12
|
+
[key: string]: any;
|
|
13
|
+
};
|
|
14
|
+
content: string;
|
|
15
|
+
code: string;
|
|
16
|
+
anchors: {
|
|
17
|
+
name: string;
|
|
18
|
+
id: string;
|
|
19
|
+
size: number;
|
|
20
|
+
}[];
|
|
21
|
+
} | null>;
|
|
11
22
|
export function next(type: string, config: ShisoConfig): {
|
|
12
23
|
generateMetadata: ({ params }: {
|
|
13
24
|
params: Promise<{
|
|
14
|
-
|
|
25
|
+
slug: string[];
|
|
15
26
|
}>;
|
|
16
27
|
}) => Promise<{
|
|
17
28
|
title: {
|
|
18
29
|
absolute: string;
|
|
19
|
-
default:
|
|
30
|
+
default: any;
|
|
20
31
|
};
|
|
21
32
|
}>;
|
|
22
33
|
generateStaticParams: () => Promise<any>;
|
|
@@ -26,7 +37,7 @@ declare module '@umami/shiso/server' {
|
|
|
26
37
|
config: ShisoConfig;
|
|
27
38
|
}) => ReactElement) => ({ params }: {
|
|
28
39
|
params: Promise<{
|
|
29
|
-
|
|
40
|
+
slug: string[];
|
|
30
41
|
}>;
|
|
31
42
|
}) => Promise<ReactElement<unknown, string | import("react").JSXElementConstructor<any>>>;
|
|
32
43
|
};
|
package/dist/server.js
CHANGED
|
@@ -34,15 +34,6 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
34
34
|
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
35
35
|
}
|
|
36
36
|
};
|
|
37
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
38
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
39
|
-
if (ar || !(i in from)) {
|
|
40
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
41
|
-
ar[i] = from[i];
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
45
|
-
};
|
|
46
37
|
import { cache } from 'react';
|
|
47
38
|
import { compile } from '@mdx-js/mdx';
|
|
48
39
|
import remarkGfm from 'remark-gfm';
|
|
@@ -51,94 +42,74 @@ import matter from 'gray-matter';
|
|
|
51
42
|
import fs from 'node:fs/promises';
|
|
52
43
|
import path from 'node:path';
|
|
53
44
|
import recursive from 'recursive-readdir';
|
|
54
|
-
function
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
var args_1 = [];
|
|
59
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
60
|
-
args_1[_i] = arguments[_i];
|
|
61
|
-
}
|
|
62
|
-
return __awaiter(void 0, __spreadArray([], args_1, true), void 0, function (name, folder) {
|
|
63
|
-
var file, postContent, _a, frontmatter, mdxContent, id, anchors, modifiedContent, code, _b;
|
|
64
|
-
if (name === void 0) { name = 'index'; }
|
|
65
|
-
return __generator(this, function (_c) {
|
|
66
|
-
switch (_c.label) {
|
|
67
|
-
case 0:
|
|
68
|
-
file = path.join(folder, "".concat(name, ".mdx"));
|
|
69
|
-
return [4 /*yield*/, fs.readFile(file, 'utf8')];
|
|
70
|
-
case 1:
|
|
71
|
-
postContent = _c.sent();
|
|
72
|
-
_a = matter(postContent), frontmatter = _a.data, mdxContent = _a.content;
|
|
73
|
-
id = getId(name, folder);
|
|
74
|
-
anchors = [];
|
|
75
|
-
modifiedContent = mdxContent
|
|
76
|
-
.split('\n')
|
|
77
|
-
.map(function (line) {
|
|
78
|
-
var match = line.match(/^(#+)\s+(.*)/);
|
|
79
|
-
if (match) {
|
|
80
|
-
var num = match[1], name_1 = match[2];
|
|
81
|
-
var id_1 = name_1.toLowerCase().replace(/\s+/g, '-');
|
|
82
|
-
var size = num.length;
|
|
83
|
-
anchors.push({ name: name_1, id: id_1, size: size });
|
|
84
|
-
return "<h".concat(size, " id=\"").concat(id_1, "\">").concat(name_1.replace(/\{|\}/g, ''), "</h").concat(size, ">");
|
|
85
|
-
}
|
|
86
|
-
return line;
|
|
87
|
-
})
|
|
88
|
-
.join('\n');
|
|
89
|
-
_b = String;
|
|
90
|
-
return [4 /*yield*/, compile(modifiedContent, {
|
|
91
|
-
outputFormat: 'function-body',
|
|
92
|
-
remarkPlugins: [remarkGfm],
|
|
93
|
-
rehypePlugins: [rehypeHighlight],
|
|
94
|
-
})];
|
|
95
|
-
case 2:
|
|
96
|
-
code = _b.apply(void 0, [_c.sent()]);
|
|
97
|
-
return [2 /*return*/, {
|
|
98
|
-
id: id,
|
|
99
|
-
meta: frontmatter,
|
|
100
|
-
content: postContent,
|
|
101
|
-
code: code,
|
|
102
|
-
anchors: anchors,
|
|
103
|
-
}];
|
|
104
|
-
}
|
|
105
|
-
});
|
|
106
|
-
});
|
|
107
|
-
});
|
|
108
|
-
export var getContentIds = cache(function (folder) { return __awaiter(void 0, void 0, void 0, function () {
|
|
109
|
-
var dir, files;
|
|
110
|
-
return __generator(this, function (_a) {
|
|
111
|
-
switch (_a.label) {
|
|
45
|
+
export var getContent = cache(function (file) { return __awaiter(void 0, void 0, void 0, function () {
|
|
46
|
+
var postContent, _a, frontmatter, mdxContent, anchors_1, modifiedContent, code, _b, _c;
|
|
47
|
+
return __generator(this, function (_d) {
|
|
48
|
+
switch (_d.label) {
|
|
112
49
|
case 0:
|
|
113
|
-
|
|
114
|
-
return [4 /*yield*/,
|
|
50
|
+
_d.trys.push([0, 3, , 4]);
|
|
51
|
+
return [4 /*yield*/, fs.readFile(file, 'utf8')];
|
|
115
52
|
case 1:
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
53
|
+
postContent = _d.sent();
|
|
54
|
+
_a = matter(postContent), frontmatter = _a.data, mdxContent = _a.content;
|
|
55
|
+
anchors_1 = [];
|
|
56
|
+
modifiedContent = mdxContent
|
|
57
|
+
.split('\n')
|
|
58
|
+
.map(function (line) {
|
|
59
|
+
var match = line.match(/^(#+)\s+(.*)/);
|
|
60
|
+
if (match) {
|
|
61
|
+
var num = match[1], name_1 = match[2];
|
|
62
|
+
var id = name_1.toLowerCase().replace(/\s+/g, '-');
|
|
63
|
+
var size = num.length;
|
|
64
|
+
anchors_1.push({ name: name_1, id: id, size: size });
|
|
65
|
+
return "<h".concat(size, " id=\"").concat(id, "\">").concat(name_1.replace(/\{|\}/g, ''), "</h").concat(size, ">");
|
|
66
|
+
}
|
|
67
|
+
return line;
|
|
68
|
+
})
|
|
69
|
+
.join('\n');
|
|
70
|
+
_b = String;
|
|
71
|
+
return [4 /*yield*/, compile(modifiedContent, {
|
|
72
|
+
outputFormat: 'function-body',
|
|
73
|
+
remarkPlugins: [remarkGfm],
|
|
74
|
+
rehypePlugins: [rehypeHighlight],
|
|
119
75
|
})];
|
|
76
|
+
case 2:
|
|
77
|
+
code = _b.apply(void 0, [_d.sent()]);
|
|
78
|
+
return [2 /*return*/, {
|
|
79
|
+
path: file,
|
|
80
|
+
meta: frontmatter,
|
|
81
|
+
content: postContent,
|
|
82
|
+
code: code,
|
|
83
|
+
anchors: anchors_1,
|
|
84
|
+
}];
|
|
85
|
+
case 3:
|
|
86
|
+
_c = _d.sent();
|
|
87
|
+
return [2 /*return*/, null];
|
|
88
|
+
case 4: return [2 /*return*/];
|
|
120
89
|
}
|
|
121
90
|
});
|
|
122
91
|
}); });
|
|
123
92
|
export function next(type, config) {
|
|
124
93
|
var dir = path.join(config.contentDir, type);
|
|
94
|
+
var _a = config[type].title, title = _a === void 0 ? 'Shiso' : _a;
|
|
125
95
|
function generateMetadata(_a) {
|
|
126
96
|
return __awaiter(this, arguments, void 0, function (_b) {
|
|
127
|
-
var name, content;
|
|
97
|
+
var name, file, content;
|
|
128
98
|
var _c, _d, _e;
|
|
129
99
|
var params = _b.params;
|
|
130
100
|
return __generator(this, function (_f) {
|
|
131
101
|
switch (_f.label) {
|
|
132
102
|
case 0: return [4 /*yield*/, params];
|
|
133
103
|
case 1:
|
|
134
|
-
name = (_d = (_c = (_f.sent())) === null || _c === void 0 ? void 0 : _c.
|
|
135
|
-
|
|
104
|
+
name = ((_d = (_c = (_f.sent())) === null || _c === void 0 ? void 0 : _c.slug) === null || _d === void 0 ? void 0 : _d.join('/')) || 'index';
|
|
105
|
+
file = path.join(dir, "".concat(name, ".mdx"));
|
|
106
|
+
return [4 /*yield*/, getContent(file)];
|
|
136
107
|
case 2:
|
|
137
108
|
content = _f.sent();
|
|
138
109
|
return [2 /*return*/, {
|
|
139
110
|
title: {
|
|
140
|
-
absolute: "".concat((_e = content === null || content === void 0 ? void 0 : content.meta) === null || _e === void 0 ? void 0 : _e.title, " \u2013
|
|
141
|
-
default:
|
|
111
|
+
absolute: "".concat((_e = content === null || content === void 0 ? void 0 : content.meta) === null || _e === void 0 ? void 0 : _e.title, " \u2013 ").concat(title),
|
|
112
|
+
default: title,
|
|
142
113
|
},
|
|
143
114
|
}];
|
|
144
115
|
}
|
|
@@ -147,13 +118,17 @@ export function next(type, config) {
|
|
|
147
118
|
}
|
|
148
119
|
function generateStaticParams() {
|
|
149
120
|
return __awaiter(this, void 0, void 0, function () {
|
|
150
|
-
var
|
|
121
|
+
var files;
|
|
151
122
|
return __generator(this, function (_a) {
|
|
152
123
|
switch (_a.label) {
|
|
153
|
-
case 0: return [4 /*yield*/,
|
|
124
|
+
case 0: return [4 /*yield*/, recursive(dir)];
|
|
154
125
|
case 1:
|
|
155
|
-
|
|
156
|
-
return [2 /*return*/,
|
|
126
|
+
files = _a.sent();
|
|
127
|
+
return [2 /*return*/, files
|
|
128
|
+
.map(function (file) {
|
|
129
|
+
return file.replace('.mdx', '').replace(dir, '').replace(/\\/g, '/').replace(/^\//, '');
|
|
130
|
+
})
|
|
131
|
+
.map(function (id) { return ({
|
|
157
132
|
id: id.split('/'),
|
|
158
133
|
}); })];
|
|
159
134
|
}
|
|
@@ -163,15 +138,16 @@ export function next(type, config) {
|
|
|
163
138
|
function renderPage(render) {
|
|
164
139
|
var _this = this;
|
|
165
140
|
return function (_a) { return __awaiter(_this, [_a], void 0, function (_b) {
|
|
166
|
-
var name, content;
|
|
141
|
+
var name, file, content;
|
|
167
142
|
var _c, _d;
|
|
168
143
|
var params = _b.params;
|
|
169
144
|
return __generator(this, function (_e) {
|
|
170
145
|
switch (_e.label) {
|
|
171
146
|
case 0: return [4 /*yield*/, params];
|
|
172
147
|
case 1:
|
|
173
|
-
name = (_d = (_c = (_e.sent())) === null || _c === void 0 ? void 0 : _c.
|
|
174
|
-
|
|
148
|
+
name = ((_d = (_c = (_e.sent())) === null || _c === void 0 ? void 0 : _c.slug) === null || _d === void 0 ? void 0 : _d.join('/')) || 'index';
|
|
149
|
+
file = path.join(dir, "".concat(name, ".mdx"));
|
|
150
|
+
return [4 /*yield*/, getContent(file)];
|
|
175
151
|
case 2:
|
|
176
152
|
content = _e.sent();
|
|
177
153
|
return [2 /*return*/, render({ type: type, content: content, config: config })];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@umami/shiso",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.19.0",
|
|
4
4
|
"description": "A content layer for Next.js",
|
|
5
5
|
"homepage": "https://umami.is/shiso",
|
|
6
6
|
"repository": {
|
|
@@ -46,7 +46,7 @@
|
|
|
46
46
|
"@mdx-js/loader": "^3.0.0",
|
|
47
47
|
"@mdx-js/mdx": "^3.1.0",
|
|
48
48
|
"@mdx-js/react": "^3.0.0",
|
|
49
|
-
"@umami/react-zen": "^0.
|
|
49
|
+
"@umami/react-zen": "^0.32.0",
|
|
50
50
|
"classnames": "^2.5.1",
|
|
51
51
|
"glob": "^10.3.10",
|
|
52
52
|
"gray-matter": "^4.0.3",
|
package/server/index.d.ts
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { ReactElement } from 'react';
|
|
2
|
-
export declare const getContent: (name: string | undefined, folder: string) => Promise<any>;
|
|
3
|
-
export declare const getContentIds: (folder: string) => Promise<any>;
|
|
4
|
-
export declare function next(type: string, config: {
|
|
5
|
-
[key: string]: any;
|
|
6
|
-
}): {
|
|
7
|
-
generateMetadata: ({ params }: {
|
|
8
|
-
params: Promise<{
|
|
9
|
-
id: string[];
|
|
10
|
-
}>;
|
|
11
|
-
}) => Promise<{
|
|
12
|
-
title: {
|
|
13
|
-
absolute: string;
|
|
14
|
-
default: string;
|
|
15
|
-
};
|
|
16
|
-
}>;
|
|
17
|
-
generateStaticParams: () => Promise<any>;
|
|
18
|
-
renderPage: (render: ({ type, content, config, }: {
|
|
19
|
-
type: string;
|
|
20
|
-
content: any;
|
|
21
|
-
config: {
|
|
22
|
-
[key: string]: any;
|
|
23
|
-
};
|
|
24
|
-
}) => ReactElement) => ({ params }: {
|
|
25
|
-
params: Promise<{
|
|
26
|
-
id: string[];
|
|
27
|
-
}>;
|
|
28
|
-
}) => Promise<ReactElement<unknown, string | import("react").JSXElementConstructor<any>>>;
|
|
29
|
-
};
|
package/server/index.js
DELETED
|
@@ -1,183 +0,0 @@
|
|
|
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
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
11
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
12
|
-
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
13
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
14
|
-
function step(op) {
|
|
15
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
16
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
17
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
18
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
19
|
-
switch (op[0]) {
|
|
20
|
-
case 0: case 1: t = op; break;
|
|
21
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
22
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
23
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
24
|
-
default:
|
|
25
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
26
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
27
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
28
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
29
|
-
if (t[2]) _.ops.pop();
|
|
30
|
-
_.trys.pop(); continue;
|
|
31
|
-
}
|
|
32
|
-
op = body.call(thisArg, _);
|
|
33
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
34
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
35
|
-
}
|
|
36
|
-
};
|
|
37
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
38
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
39
|
-
if (ar || !(i in from)) {
|
|
40
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
41
|
-
ar[i] = from[i];
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
45
|
-
};
|
|
46
|
-
import { cache } from 'react';
|
|
47
|
-
import { compile } from '@mdx-js/mdx';
|
|
48
|
-
import remarkGfm from 'remark-gfm';
|
|
49
|
-
import rehypeHighlight from 'rehype-highlight';
|
|
50
|
-
import matter from 'gray-matter';
|
|
51
|
-
import fs from 'node:fs/promises';
|
|
52
|
-
import path from 'node:path';
|
|
53
|
-
import recursive from 'recursive-readdir';
|
|
54
|
-
function getId(name, folder) {
|
|
55
|
-
return name.replace('.mdx', '').replace(folder, '').replace(/\\/g, '/').replace(/^\//, '');
|
|
56
|
-
}
|
|
57
|
-
export var getContent = cache(function () {
|
|
58
|
-
var args_1 = [];
|
|
59
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
60
|
-
args_1[_i] = arguments[_i];
|
|
61
|
-
}
|
|
62
|
-
return __awaiter(void 0, __spreadArray([], args_1, true), void 0, function (name, folder) {
|
|
63
|
-
var file, postContent, _a, frontmatter, mdxContent, id, anchors, modifiedContent, code, _b;
|
|
64
|
-
if (name === void 0) { name = 'index'; }
|
|
65
|
-
return __generator(this, function (_c) {
|
|
66
|
-
switch (_c.label) {
|
|
67
|
-
case 0:
|
|
68
|
-
file = path.join(folder, "".concat(name, ".mdx"));
|
|
69
|
-
return [4 /*yield*/, fs.readFile(file, 'utf8')];
|
|
70
|
-
case 1:
|
|
71
|
-
postContent = _c.sent();
|
|
72
|
-
_a = matter(postContent), frontmatter = _a.data, mdxContent = _a.content;
|
|
73
|
-
id = getId(name, folder);
|
|
74
|
-
anchors = [];
|
|
75
|
-
modifiedContent = mdxContent
|
|
76
|
-
.split('\n')
|
|
77
|
-
.map(function (line) {
|
|
78
|
-
var match = line.match(/^(#+)\s+(.*)/);
|
|
79
|
-
if (match) {
|
|
80
|
-
var num = match[1], name_1 = match[2];
|
|
81
|
-
var id_1 = name_1.toLowerCase().replace(/\s+/g, '-');
|
|
82
|
-
var size = num.length;
|
|
83
|
-
anchors.push({ name: name_1, id: id_1, size: size });
|
|
84
|
-
return "<h".concat(size, " id=\"").concat(id_1, "\">").concat(name_1.replace(/\{|\}/g, ''), "</h").concat(size, ">");
|
|
85
|
-
}
|
|
86
|
-
return line;
|
|
87
|
-
})
|
|
88
|
-
.join('\n');
|
|
89
|
-
_b = String;
|
|
90
|
-
return [4 /*yield*/, compile(modifiedContent, {
|
|
91
|
-
outputFormat: 'function-body',
|
|
92
|
-
remarkPlugins: [remarkGfm],
|
|
93
|
-
rehypePlugins: [rehypeHighlight],
|
|
94
|
-
})];
|
|
95
|
-
case 2:
|
|
96
|
-
code = _b.apply(void 0, [_c.sent()]);
|
|
97
|
-
return [2 /*return*/, {
|
|
98
|
-
id: id,
|
|
99
|
-
meta: frontmatter,
|
|
100
|
-
content: postContent,
|
|
101
|
-
code: code,
|
|
102
|
-
anchors: anchors,
|
|
103
|
-
}];
|
|
104
|
-
}
|
|
105
|
-
});
|
|
106
|
-
});
|
|
107
|
-
});
|
|
108
|
-
export var getContentIds = cache(function (folder) { return __awaiter(void 0, void 0, void 0, function () {
|
|
109
|
-
var dir, files;
|
|
110
|
-
return __generator(this, function (_a) {
|
|
111
|
-
switch (_a.label) {
|
|
112
|
-
case 0:
|
|
113
|
-
dir = path.resolve(folder);
|
|
114
|
-
return [4 /*yield*/, recursive(dir)];
|
|
115
|
-
case 1:
|
|
116
|
-
files = _a.sent();
|
|
117
|
-
return [2 /*return*/, files.map(function (file) {
|
|
118
|
-
return getId(file, dir);
|
|
119
|
-
})];
|
|
120
|
-
}
|
|
121
|
-
});
|
|
122
|
-
}); });
|
|
123
|
-
export function next(type, config) {
|
|
124
|
-
var dir = path.join(config.contentDir, type);
|
|
125
|
-
function generateMetadata(_a) {
|
|
126
|
-
return __awaiter(this, arguments, void 0, function (_b) {
|
|
127
|
-
var name, content;
|
|
128
|
-
var _c, _d, _e;
|
|
129
|
-
var params = _b.params;
|
|
130
|
-
return __generator(this, function (_f) {
|
|
131
|
-
switch (_f.label) {
|
|
132
|
-
case 0: return [4 /*yield*/, params];
|
|
133
|
-
case 1:
|
|
134
|
-
name = (_d = (_c = (_f.sent())) === null || _c === void 0 ? void 0 : _c.id) === null || _d === void 0 ? void 0 : _d.join('/');
|
|
135
|
-
return [4 /*yield*/, getContent(name, dir)];
|
|
136
|
-
case 2:
|
|
137
|
-
content = _f.sent();
|
|
138
|
-
return [2 /*return*/, {
|
|
139
|
-
title: {
|
|
140
|
-
absolute: "".concat((_e = content === null || content === void 0 ? void 0 : content.meta) === null || _e === void 0 ? void 0 : _e.title, " \u2013 Shiso"),
|
|
141
|
-
default: 'Shiso',
|
|
142
|
-
},
|
|
143
|
-
}];
|
|
144
|
-
}
|
|
145
|
-
});
|
|
146
|
-
});
|
|
147
|
-
}
|
|
148
|
-
function generateStaticParams() {
|
|
149
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
150
|
-
var ids;
|
|
151
|
-
return __generator(this, function (_a) {
|
|
152
|
-
switch (_a.label) {
|
|
153
|
-
case 0: return [4 /*yield*/, getContentIds(dir)];
|
|
154
|
-
case 1:
|
|
155
|
-
ids = _a.sent();
|
|
156
|
-
return [2 /*return*/, ids.map(function (id) { return ({
|
|
157
|
-
id: id.split('/'),
|
|
158
|
-
}); })];
|
|
159
|
-
}
|
|
160
|
-
});
|
|
161
|
-
});
|
|
162
|
-
}
|
|
163
|
-
function renderPage(render) {
|
|
164
|
-
var _this = this;
|
|
165
|
-
return function (_a) { return __awaiter(_this, [_a], void 0, function (_b) {
|
|
166
|
-
var name, content;
|
|
167
|
-
var _c, _d;
|
|
168
|
-
var params = _b.params;
|
|
169
|
-
return __generator(this, function (_e) {
|
|
170
|
-
switch (_e.label) {
|
|
171
|
-
case 0: return [4 /*yield*/, params];
|
|
172
|
-
case 1:
|
|
173
|
-
name = (_d = (_c = (_e.sent())) === null || _c === void 0 ? void 0 : _c.id) === null || _d === void 0 ? void 0 : _d.join('/');
|
|
174
|
-
return [4 /*yield*/, getContent(name, dir)];
|
|
175
|
-
case 2:
|
|
176
|
-
content = _e.sent();
|
|
177
|
-
return [2 /*return*/, render({ type: type, content: content, config: config })];
|
|
178
|
-
}
|
|
179
|
-
});
|
|
180
|
-
}); };
|
|
181
|
-
}
|
|
182
|
-
return { generateMetadata: generateMetadata, generateStaticParams: generateStaticParams, renderPage: renderPage };
|
|
183
|
-
}
|