@umami/shiso 0.16.0 → 0.17.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
@@ -5,6 +5,7 @@
5
5
 
6
6
  declare module '@umami/shiso' {
7
7
  import '@umami/react-zen/styles.css';
8
+ import 'highlight.js/styles/github-dark.css';
8
9
  import { Blog } from '@umami/shiso/Blog';
9
10
  import { Docs } from '@umami/shiso/Docs';
10
11
  import { Shiso } from '@umami/shiso/Shiso';
package/dist/index.js CHANGED
@@ -37,6 +37,7 @@ __export(index_exports, {
37
37
  });
38
38
  module.exports = __toCommonJS(index_exports);
39
39
  var import_styles = require("@umami/react-zen/styles.css");
40
+ var import_github_dark = require("highlight.js/styles/github-dark.css");
40
41
 
41
42
  // css-modules:/Users/mikecao/Development/umami-software/shiso/src/components/Blog.module.css
42
43
  var Blog_default = {};
package/dist/index.mjs CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  // src/components/index.ts
4
4
  import "@umami/react-zen/styles.css";
5
+ import "highlight.js/styles/github-dark.css";
5
6
 
6
7
  // css-modules:/Users/mikecao/Development/umami-software/shiso/src/components/Blog.module.css
7
8
  var Blog_default = {};
@@ -0,0 +1,34 @@
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: (name: string | undefined, folder: string) => Promise<any>;
10
+ export const getContentIds: (folder: string) => Promise<any>;
11
+ export function next(type: string, config: ShisoConfig): {
12
+ generateMetadata: ({ params }: {
13
+ params: Promise<{
14
+ id: string[];
15
+ }>;
16
+ }) => Promise<{
17
+ title: {
18
+ absolute: string;
19
+ default: string;
20
+ };
21
+ }>;
22
+ generateStaticParams: () => Promise<any>;
23
+ renderPage: (render: ({ type, content, config, }: {
24
+ type: string;
25
+ content: any;
26
+ config: ShisoConfig;
27
+ }) => ReactElement) => ({ params }: {
28
+ params: Promise<{
29
+ id: string[];
30
+ }>;
31
+ }) => Promise<ReactElement<unknown, string | import("react").JSXElementConstructor<any>>>;
32
+ };
33
+ }
34
+
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@umami/shiso",
3
- "version": "0.16.0",
3
+ "version": "0.17.0",
4
4
  "description": "A content layer for Next.js",
5
5
  "homepage": "https://umami.is/shiso",
6
6
  "repository": {
@@ -1,8 +1,9 @@
1
1
  import { ReactElement } from 'react';
2
- import type { ShisoConfig } from '@/lib/types';
3
2
  export declare const getContent: (name: string | undefined, folder: string) => Promise<any>;
4
3
  export declare const getContentIds: (folder: string) => Promise<any>;
5
- export declare function next(type: string, config: ShisoConfig): {
4
+ export declare function next(type: string, config: {
5
+ [key: string]: any;
6
+ }): {
6
7
  generateMetadata: ({ params }: {
7
8
  params: Promise<{
8
9
  id: string[];
@@ -17,7 +18,9 @@ export declare function next(type: string, config: ShisoConfig): {
17
18
  renderPage: (render: ({ type, content, config, }: {
18
19
  type: string;
19
20
  content: any;
20
- config: ShisoConfig;
21
+ config: {
22
+ [key: string]: any;
23
+ };
21
24
  }) => ReactElement) => ({ params }: {
22
25
  params: Promise<{
23
26
  id: string[];
@@ -0,0 +1,183 @@
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
+ }
@@ -1,14 +0,0 @@
1
- export interface ShisoDocsConfig {
2
- tabs?: [];
3
- }
4
- export interface ShisoBlogConfig {
5
- }
6
- export interface ShisoConfig {
7
- contentDir: string;
8
- docs?: {
9
- [key: string]: any;
10
- };
11
- blog?: {
12
- [key: string]: any;
13
- };
14
- }
@@ -1 +0,0 @@
1
- export {};
File without changes