@umami/shiso 0.29.0 → 0.31.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/server/index.js CHANGED
@@ -39,10 +39,10 @@ import { compile } from '@mdx-js/mdx';
39
39
  import remarkGfm from 'remark-gfm';
40
40
  import rehypeHighlight from 'rehype-highlight';
41
41
  import matter from 'gray-matter';
42
+ import recursive from 'recursive-readdir';
42
43
  import fs from 'node:fs/promises';
43
44
  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 () {
45
+ export var parseFile = cache(function (file) { return __awaiter(void 0, void 0, void 0, function () {
46
46
  var postContent, _a, frontmatter, mdxContent, anchors_1, modifiedContent, code, _b, _c;
47
47
  return __generator(this, function (_d) {
48
48
  switch (_d.label) {
@@ -90,8 +90,23 @@ export var getContent = cache(function (file) { return __awaiter(void 0, void 0,
90
90
  });
91
91
  }); });
92
92
  export function next(type, config) {
93
+ var _this = this;
93
94
  var dir = path.join(config.contentDir, type);
94
95
  var _a = config[type].title, title = _a === void 0 ? 'Shiso' : _a;
96
+ var getContent = function (file) { return __awaiter(_this, void 0, void 0, function () {
97
+ var content;
98
+ return __generator(this, function (_a) {
99
+ switch (_a.label) {
100
+ case 0: return [4 /*yield*/, parseFile(file)];
101
+ case 1:
102
+ content = _a.sent();
103
+ if (content) {
104
+ content['slug'] = getSlug(file, dir);
105
+ }
106
+ return [2 /*return*/, content];
107
+ }
108
+ });
109
+ }); };
95
110
  function generateMetadata(_a) {
96
111
  return __awaiter(this, arguments, void 0, function (_b) {
97
112
  var name, file, content;
@@ -116,6 +131,9 @@ export function next(type, config) {
116
131
  });
117
132
  });
118
133
  }
134
+ function getSlug(file, dir) {
135
+ return file.replace('.mdx', '').replace(dir, '').replace(/\\/g, '/').replace(/^\//, '');
136
+ }
119
137
  function generateStaticParams() {
120
138
  return __awaiter(this, void 0, void 0, function () {
121
139
  var files;
@@ -124,12 +142,8 @@ export function next(type, config) {
124
142
  case 0: return [4 /*yield*/, recursive(dir)];
125
143
  case 1:
126
144
  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('/'),
145
+ return [2 /*return*/, files.map(function (file) { return ({
146
+ slug: getSlug(file, dir).split('/'),
133
147
  }); })];
134
148
  }
135
149
  });
@@ -138,19 +152,27 @@ export function next(type, config) {
138
152
  function renderPage(render) {
139
153
  var _this = this;
140
154
  return function (_a) { return __awaiter(_this, [_a], void 0, function (_b) {
141
- var name, file, content;
155
+ var slug, file, files, content;
142
156
  var _c, _d;
143
157
  var params = _b.params;
144
158
  return __generator(this, function (_e) {
145
159
  switch (_e.label) {
146
160
  case 0: return [4 /*yield*/, params];
147
161
  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)];
162
+ slug = ((_d = (_c = (_e.sent())) === null || _c === void 0 ? void 0 : _c.slug) === null || _d === void 0 ? void 0 : _d.join('/')) || 'index';
163
+ file = path.join(dir, "".concat(slug, ".mdx"));
164
+ return [4 /*yield*/, recursive(dir)];
151
165
  case 2:
166
+ files = _e.sent();
167
+ return [4 /*yield*/, getContent(file)];
168
+ case 3:
169
+ content = _e.sent();
170
+ if (!(!content && slug.endsWith('index'))) return [3 /*break*/, 5];
171
+ return [4 /*yield*/, Promise.all(files.map(function (file) { return getContent(file); }))];
172
+ case 4:
152
173
  content = _e.sent();
153
- return [2 /*return*/, render({ type: type, content: content, config: config })];
174
+ _e.label = 5;
175
+ case 5: return [2 /*return*/, render({ type: type, config: config, content: content })];
154
176
  }
155
177
  });
156
178
  }); };
package/dist/server.d.ts DELETED
@@ -1,45 +0,0 @@
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
-
package/dist/server.js DELETED
@@ -1,159 +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
- 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
- }