@umami/shiso 0.18.0 → 0.20.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 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: any;
31
+ content: ShisoContent;
32
32
  type: string;
33
33
  config: ShisoConfig;
34
34
  components?: {
package/dist/index.js CHANGED
@@ -210,8 +210,8 @@ function SideNav({ tabs, navigation }) {
210
210
  const pathname = (0, import_navigation.usePathname)();
211
211
  const tab = tabs?.find(({ url, id }) => id !== "docs" ? pathname.startsWith(url) : false);
212
212
  const menu = navigation[tab?.id || "docs"];
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(({ group, pages }) => {
214
- return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_react_zen3.ListSection, { title: group, className: SideNav_default.items, children: pages.map(({ label: text, url }, index) => {
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
215
  return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
216
216
  import_react_zen3.ListItem,
217
217
  {
@@ -222,7 +222,7 @@ function SideNav({ tabs, navigation }) {
222
222
  },
223
223
  index
224
224
  );
225
- }) }, group);
225
+ }) }, section);
226
226
  }) }) });
227
227
  }
228
228
 
@@ -249,9 +249,9 @@ var ContentArea_default = { "content": "ContentArea_content__OTBiZ" };
249
249
  // src/components/ContentArea.tsx
250
250
  var import_link3 = __toESM(require("next/link"));
251
251
  var import_jsx_runtime9 = require("react/jsx-runtime");
252
- function ContentArea({ group, title, description, code, next, prev }) {
252
+ function ContentArea({ section, title, description, code, next, prev }) {
253
253
  return /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(import_react_zen5.Box, { flexGrow: 1, children: [
254
- group && /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_react_zen5.Text, { color: "primary", weight: "bold", children: group }),
254
+ section && /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_react_zen5.Text, { color: "primary", weight: "bold", children: section }),
255
255
  title && /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_react_zen5.Heading, { size: "8", as: "h1", children: title }),
256
256
  description && /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_react_zen5.Text, { color: "muted", children: description }),
257
257
  /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_react_zen5.Box, { className: ContentArea_default.content, children: /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(Markdown, { code }) }),
@@ -280,31 +280,37 @@ var NavigationButton = ({
280
280
  var import_jsx_runtime10 = require("react/jsx-runtime");
281
281
  function parseContent(content, config = {}) {
282
282
  const { tabs, navigation } = config;
283
- let next, prev, group, prevKey, found = false;
284
- for (const key in navigation) {
285
- if (!group) {
286
- group = navigation[key]?.find((section, sectionIndex) => {
287
- return section.pages.find((page, pageIndex) => {
288
- const found2 = content.path.replace(/(\/index)?\.mdx$/, "").endsWith(page.url);
289
- if (found2) {
290
- prev = section.pages[pageIndex - 1] || section[prevKey]?.pages?.[sectionIndex - 1];
291
- next = section.pages[pageIndex + 1];
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;
292
297
  }
293
- return found2;
298
+ return match;
294
299
  });
295
- })?.group;
296
- prevKey = key;
300
+ });
297
301
  }
298
- }
299
- return { ...content, tabs, navigation, group, next, prev };
302
+ });
303
+ return { ...content, tabs, navigation, section, next, prev };
300
304
  }
301
305
  function Docs() {
302
306
  const { content, config } = useShiso();
303
307
  if (!content) {
304
308
  return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(import_react_zen6.Heading, { size: "6", children: "Page not found" });
305
309
  }
306
- const { tabs, navigation, group, next, prev } = parseContent(content, config?.docs);
307
- console.log({ content, next, prev, group });
310
+ const { tabs, navigation, code, meta, section, next, prev, anchors } = parseContent(
311
+ content,
312
+ config?.docs
313
+ );
308
314
  return /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(import_react_zen6.Box, { flexGrow: "1", children: [
309
315
  tabs && /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(TopNav, { tabs }),
310
316
  /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(import_react_zen6.Grid, { gap: "6", columns: "240px 1fr 240px", children: [
@@ -312,15 +318,15 @@ function Docs() {
312
318
  /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
313
319
  ContentArea,
314
320
  {
315
- group,
316
- title: content.meta?.title,
317
- description: content.meta?.description,
318
- code: content.code,
321
+ section,
322
+ title: meta?.title,
323
+ description: meta?.description,
324
+ code,
319
325
  next,
320
326
  prev
321
327
  }
322
328
  ),
323
- /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(PageLinks, { items: content?.anchors, offset: 150 })
329
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(PageLinks, { items: anchors, offset: 150 })
324
330
  ] })
325
331
  ] });
326
332
  }
package/dist/index.mjs CHANGED
@@ -174,8 +174,8 @@ function SideNav({ tabs, navigation }) {
174
174
  const pathname = usePathname();
175
175
  const tab = tabs?.find(({ url, id }) => id !== "docs" ? pathname.startsWith(url) : false);
176
176
  const menu = navigation[tab?.id || "docs"];
177
- return /* @__PURE__ */ jsx7(Box, { className: SideNav_default.nav, children: /* @__PURE__ */ jsx7(List, { items: navigation, "aria-label": "nav", children: menu.map(({ group, pages }) => {
178
- return /* @__PURE__ */ jsx7(ListSection, { title: group, className: SideNav_default.items, children: pages.map(({ label: text, url }, index) => {
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
179
  return /* @__PURE__ */ jsx7(
180
180
  ListItem,
181
181
  {
@@ -186,7 +186,7 @@ function SideNav({ tabs, navigation }) {
186
186
  },
187
187
  index
188
188
  );
189
- }) }, group);
189
+ }) }, section);
190
190
  }) }) });
191
191
  }
192
192
 
@@ -213,9 +213,9 @@ var ContentArea_default = { "content": "ContentArea_content__OTBiZ" };
213
213
  // src/components/ContentArea.tsx
214
214
  import Link3 from "next/link";
215
215
  import { jsx as jsx9, jsxs as jsxs5 } from "react/jsx-runtime";
216
- function ContentArea({ group, title, description, code, next, prev }) {
216
+ function ContentArea({ section, title, description, code, next, prev }) {
217
217
  return /* @__PURE__ */ jsxs5(Box2, { flexGrow: 1, children: [
218
- group && /* @__PURE__ */ jsx9(Text2, { color: "primary", weight: "bold", children: group }),
218
+ section && /* @__PURE__ */ jsx9(Text2, { color: "primary", weight: "bold", children: section }),
219
219
  title && /* @__PURE__ */ jsx9(Heading, { size: "8", as: "h1", children: title }),
220
220
  description && /* @__PURE__ */ jsx9(Text2, { color: "muted", children: description }),
221
221
  /* @__PURE__ */ jsx9(Box2, { className: ContentArea_default.content, children: /* @__PURE__ */ jsx9(Markdown, { code }) }),
@@ -244,31 +244,37 @@ var NavigationButton = ({
244
244
  import { jsx as jsx10, jsxs as jsxs6 } from "react/jsx-runtime";
245
245
  function parseContent(content, config = {}) {
246
246
  const { tabs, navigation } = config;
247
- let next, prev, group, prevKey, found = false;
248
- for (const key in navigation) {
249
- if (!group) {
250
- group = navigation[key]?.find((section, sectionIndex) => {
251
- return section.pages.find((page, pageIndex) => {
252
- const found2 = content.path.replace(/(\/index)?\.mdx$/, "").endsWith(page.url);
253
- if (found2) {
254
- prev = section.pages[pageIndex - 1] || section[prevKey]?.pages?.[sectionIndex - 1];
255
- next = section.pages[pageIndex + 1];
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;
256
261
  }
257
- return found2;
262
+ return match;
258
263
  });
259
- })?.group;
260
- prevKey = key;
264
+ });
261
265
  }
262
- }
263
- return { ...content, tabs, navigation, group, next, prev };
266
+ });
267
+ return { ...content, tabs, navigation, section, next, prev };
264
268
  }
265
269
  function Docs() {
266
270
  const { content, config } = useShiso();
267
271
  if (!content) {
268
272
  return /* @__PURE__ */ jsx10(Heading2, { size: "6", children: "Page not found" });
269
273
  }
270
- const { tabs, navigation, group, next, prev } = parseContent(content, config?.docs);
271
- console.log({ content, next, prev, group });
274
+ const { tabs, navigation, code, meta, section, next, prev, anchors } = parseContent(
275
+ content,
276
+ config?.docs
277
+ );
272
278
  return /* @__PURE__ */ jsxs6(Box3, { flexGrow: "1", children: [
273
279
  tabs && /* @__PURE__ */ jsx10(TopNav, { tabs }),
274
280
  /* @__PURE__ */ jsxs6(Grid, { gap: "6", columns: "240px 1fr 240px", children: [
@@ -276,15 +282,15 @@ function Docs() {
276
282
  /* @__PURE__ */ jsx10(
277
283
  ContentArea,
278
284
  {
279
- group,
280
- title: content.meta?.title,
281
- description: content.meta?.description,
282
- code: content.code,
285
+ section,
286
+ title: meta?.title,
287
+ description: meta?.description,
288
+ code,
283
289
  next,
284
290
  prev
285
291
  }
286
292
  ),
287
- /* @__PURE__ */ jsx10(PageLinks, { items: content?.anchors, offset: 150 })
293
+ /* @__PURE__ */ jsx10(PageLinks, { items: anchors, offset: 150 })
288
294
  ] })
289
295
  ] });
290
296
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@umami/shiso",
3
- "version": "0.18.0",
3
+ "version": "0.20.0",
4
4
  "description": "A content layer for Next.js",
5
5
  "homepage": "https://umami.is/shiso",
6
6
  "repository": {
@@ -0,0 +1,45 @@
1
+ // Generated by dts-bundle v0.7.3
2
+ // Dependencies for this module:
3
+ // ../../react
4
+ // ../../@/lib/types
5
+
6
+ declare module '@umami/shiso/server' {
7
+ import { ReactElement } from 'react';
8
+ import type { ShisoConfig } from '@/lib/types';
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>;
22
+ export function next(type: string, config: ShisoConfig): {
23
+ generateMetadata: ({ params }: {
24
+ params: Promise<{
25
+ slug: string[];
26
+ }>;
27
+ }) => Promise<{
28
+ title: {
29
+ absolute: string;
30
+ default: any;
31
+ };
32
+ }>;
33
+ generateStaticParams: () => Promise<any>;
34
+ renderPage: (render: ({ type, content, config, }: {
35
+ type: string;
36
+ content: any;
37
+ config: ShisoConfig;
38
+ }) => ReactElement) => ({ params }: {
39
+ params: Promise<{
40
+ slug: string[];
41
+ }>;
42
+ }) => Promise<ReactElement<unknown, string | import("react").JSXElementConstructor<any>>>;
43
+ };
44
+ }
45
+
@@ -0,0 +1,159 @@
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
+ import { cache } from 'react';
38
+ import { compile } from '@mdx-js/mdx';
39
+ import remarkGfm from 'remark-gfm';
40
+ import rehypeHighlight from 'rehype-highlight';
41
+ import matter from 'gray-matter';
42
+ import fs from 'node:fs/promises';
43
+ import path from 'node:path';
44
+ import recursive from 'recursive-readdir';
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) {
49
+ case 0:
50
+ _d.trys.push([0, 3, , 4]);
51
+ return [4 /*yield*/, fs.readFile(file, 'utf8')];
52
+ case 1:
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],
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*/];
89
+ }
90
+ });
91
+ }); });
92
+ export function next(type, config) {
93
+ var dir = path.join(config.contentDir, type);
94
+ var _a = config[type].title, title = _a === void 0 ? 'Shiso' : _a;
95
+ function generateMetadata(_a) {
96
+ return __awaiter(this, arguments, void 0, function (_b) {
97
+ var name, file, content;
98
+ var _c, _d, _e;
99
+ var params = _b.params;
100
+ return __generator(this, function (_f) {
101
+ switch (_f.label) {
102
+ case 0: return [4 /*yield*/, params];
103
+ case 1:
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)];
107
+ case 2:
108
+ content = _f.sent();
109
+ return [2 /*return*/, {
110
+ title: {
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,
113
+ },
114
+ }];
115
+ }
116
+ });
117
+ });
118
+ }
119
+ function generateStaticParams() {
120
+ return __awaiter(this, void 0, void 0, function () {
121
+ var files;
122
+ return __generator(this, function (_a) {
123
+ switch (_a.label) {
124
+ case 0: return [4 /*yield*/, recursive(dir)];
125
+ case 1:
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 ({
132
+ id: id.split('/'),
133
+ }); })];
134
+ }
135
+ });
136
+ });
137
+ }
138
+ function renderPage(render) {
139
+ var _this = this;
140
+ return function (_a) { return __awaiter(_this, [_a], void 0, function (_b) {
141
+ var name, file, content;
142
+ var _c, _d;
143
+ var params = _b.params;
144
+ return __generator(this, function (_e) {
145
+ switch (_e.label) {
146
+ case 0: return [4 /*yield*/, params];
147
+ case 1:
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)];
151
+ case 2:
152
+ content = _e.sent();
153
+ return [2 /*return*/, render({ type: type, content: content, config: config })];
154
+ }
155
+ });
156
+ }); };
157
+ }
158
+ return { generateMetadata: generateMetadata, generateStaticParams: generateStaticParams, renderPage: renderPage };
159
+ }