@san-siva/blogkit-md 0.3.27 → 0.4.1
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.mts +2 -7
- package/dist/index.js +33 -72
- package/package.json +2 -2
- package/src/index.ts +0 -1
- package/src/client.ts +0 -1
- package/src/components/BlogPage.tsx +0 -53
package/dist/index.d.mts
CHANGED
|
@@ -1,11 +1,6 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
-
import React, { ReactNode } from 'react';
|
|
3
2
|
import { WithContext, Thing } from 'schema-dts';
|
|
4
|
-
|
|
5
|
-
type BlogPageProperties = {
|
|
6
|
-
children: ReactNode;
|
|
7
|
-
};
|
|
8
|
-
declare const BlogPage: ({ children }: BlogPageProperties) => react_jsx_runtime.JSX.Element;
|
|
3
|
+
import React from 'react';
|
|
9
4
|
|
|
10
5
|
type BlogPostProperties = {
|
|
11
6
|
filePath: string;
|
|
@@ -33,4 +28,4 @@ type MarkdownFileResult = {
|
|
|
33
28
|
};
|
|
34
29
|
declare const readMarkdownFile: (filePath: string | undefined) => Promise<MarkdownFileResult>;
|
|
35
30
|
|
|
36
|
-
export {
|
|
31
|
+
export { BlogPost, MarkdownSections, readMarkdownFile };
|
package/dist/index.js
CHANGED
|
@@ -1,43 +1,5 @@
|
|
|
1
|
-
// src/components/BlogPage.tsx
|
|
2
|
-
import { Blog, CheckList } from "@san-siva/blogkit";
|
|
3
|
-
import { useSyncExternalStore } from "react";
|
|
4
|
-
import { jsx, jsxs } from "react/jsx-runtime";
|
|
5
|
-
var STORAGE_KEY = "blogkit-md:increased-width-mode";
|
|
6
|
-
var increasedWidthMode = typeof localStorage === "undefined" ? false : localStorage.getItem(STORAGE_KEY) === "true";
|
|
7
|
-
var listeners = /* @__PURE__ */ new Set();
|
|
8
|
-
var subscribe = (listener) => {
|
|
9
|
-
listeners.add(listener);
|
|
10
|
-
return () => listeners.delete(listener);
|
|
11
|
-
};
|
|
12
|
-
var getSnapshot = () => increasedWidthMode;
|
|
13
|
-
var setIncreasedWidthMode = (value) => {
|
|
14
|
-
increasedWidthMode = value;
|
|
15
|
-
localStorage.setItem(STORAGE_KEY, String(value));
|
|
16
|
-
for (const listener of listeners) listener();
|
|
17
|
-
};
|
|
18
|
-
var BlogPage = ({ children }) => {
|
|
19
|
-
const checked = useSyncExternalStore(subscribe, getSnapshot, () => false);
|
|
20
|
-
return /* @__PURE__ */ jsxs(Blog, { increasedWidthMode: checked, children: [
|
|
21
|
-
/* @__PURE__ */ jsx(
|
|
22
|
-
CheckList,
|
|
23
|
-
{
|
|
24
|
-
items: [
|
|
25
|
-
{
|
|
26
|
-
id: "increased-width-mode",
|
|
27
|
-
isChecked: checked,
|
|
28
|
-
onClick: () => setIncreasedWidthMode(!checked),
|
|
29
|
-
children: /* @__PURE__ */ jsx("p", { children: "Increased width mode" })
|
|
30
|
-
}
|
|
31
|
-
]
|
|
32
|
-
}
|
|
33
|
-
),
|
|
34
|
-
children
|
|
35
|
-
] });
|
|
36
|
-
};
|
|
37
|
-
var BlogPage_default = BlogPage;
|
|
38
|
-
|
|
39
1
|
// src/components/BlogPost.tsx
|
|
40
|
-
import { Blog
|
|
2
|
+
import { Blog, BlogHeader, Callout as Callout2 } from "@san-siva/blogkit";
|
|
41
3
|
import { readFile } from "fs/promises";
|
|
42
4
|
import path from "path";
|
|
43
5
|
|
|
@@ -101,7 +63,7 @@ var parseMarkdown = (content) => {
|
|
|
101
63
|
import {
|
|
102
64
|
BlogSection,
|
|
103
65
|
Callout,
|
|
104
|
-
CheckList
|
|
66
|
+
CheckList,
|
|
105
67
|
CodeBlock,
|
|
106
68
|
Mermaid,
|
|
107
69
|
Table
|
|
@@ -170,7 +132,7 @@ var groupSections = (nodes) => {
|
|
|
170
132
|
|
|
171
133
|
// src/utils/renderPhrasingContent.tsx
|
|
172
134
|
import styles from "@san-siva/stylekit/styles/index.module.scss";
|
|
173
|
-
import { jsx
|
|
135
|
+
import { jsx } from "react/jsx-runtime";
|
|
174
136
|
function escapeHtml(text) {
|
|
175
137
|
return text.replaceAll("&", "&").replaceAll("<", "<").replaceAll(">", ">");
|
|
176
138
|
}
|
|
@@ -210,7 +172,7 @@ function toHtmlString(nodes) {
|
|
|
210
172
|
}
|
|
211
173
|
function renderPhrasingContent(nodes) {
|
|
212
174
|
if (nodes.some((node) => node.type === "html")) {
|
|
213
|
-
return /* @__PURE__ */
|
|
175
|
+
return /* @__PURE__ */ jsx("span", { dangerouslySetInnerHTML: { __html: toHtmlString(nodes) } });
|
|
214
176
|
}
|
|
215
177
|
return nodes.map((node, index) => {
|
|
216
178
|
var _a;
|
|
@@ -219,22 +181,22 @@ function renderPhrasingContent(nodes) {
|
|
|
219
181
|
return node.value;
|
|
220
182
|
}
|
|
221
183
|
case "strong": {
|
|
222
|
-
return /* @__PURE__ */
|
|
184
|
+
return /* @__PURE__ */ jsx("strong", { children: renderPhrasingContent(node.children) }, index);
|
|
223
185
|
}
|
|
224
186
|
case "emphasis": {
|
|
225
|
-
return /* @__PURE__ */
|
|
187
|
+
return /* @__PURE__ */ jsx("em", { children: renderPhrasingContent(node.children) }, index);
|
|
226
188
|
}
|
|
227
189
|
case "inlineCode": {
|
|
228
|
-
return /* @__PURE__ */
|
|
190
|
+
return /* @__PURE__ */ jsx("code", { children: node.value }, index);
|
|
229
191
|
}
|
|
230
192
|
case "link": {
|
|
231
|
-
return /* @__PURE__ */
|
|
193
|
+
return /* @__PURE__ */ jsx("a", { href: node.url, className: styles["a--highlighted"], children: renderPhrasingContent(node.children) }, index);
|
|
232
194
|
}
|
|
233
195
|
case "break": {
|
|
234
|
-
return /* @__PURE__ */
|
|
196
|
+
return /* @__PURE__ */ jsx("br", {}, index);
|
|
235
197
|
}
|
|
236
198
|
case "image": {
|
|
237
|
-
return /* @__PURE__ */
|
|
199
|
+
return /* @__PURE__ */ jsx(
|
|
238
200
|
"img",
|
|
239
201
|
{
|
|
240
202
|
src: node.url,
|
|
@@ -253,7 +215,7 @@ function renderPhrasingContent(nodes) {
|
|
|
253
215
|
|
|
254
216
|
// src/utils/renderMarkdown.tsx
|
|
255
217
|
import styles2 from "@san-siva/stylekit/styles/index.module.scss";
|
|
256
|
-
import { Fragment, jsx as
|
|
218
|
+
import { Fragment, jsx as jsx2, jsxs } from "react/jsx-runtime";
|
|
257
219
|
function renderNode({
|
|
258
220
|
node,
|
|
259
221
|
key,
|
|
@@ -266,17 +228,17 @@ function renderNode({
|
|
|
266
228
|
switch (node.type) {
|
|
267
229
|
case "paragraph": {
|
|
268
230
|
if (inList) {
|
|
269
|
-
return /* @__PURE__ */
|
|
231
|
+
return /* @__PURE__ */ jsx2("p", { children: renderPhrasingContent(node.children) }, key);
|
|
270
232
|
}
|
|
271
233
|
const isFollowedByParagraph = (nextNode == null ? void 0 : nextNode.type) === "paragraph";
|
|
272
234
|
const isLastInCallout = !nextNode && inCallout;
|
|
273
235
|
const marginClass = isFollowedByParagraph ? styles2["margin-bottom--1"] : isLastInCallout ? void 0 : styles2["margin-bottom--2"];
|
|
274
|
-
return /* @__PURE__ */
|
|
236
|
+
return /* @__PURE__ */ jsx2("p", { className: marginClass, children: renderPhrasingContent(node.children) }, key);
|
|
275
237
|
}
|
|
276
238
|
case "code": {
|
|
277
239
|
if (node.lang === "mermaid") {
|
|
278
240
|
const mermaidId = counters.mermaid++;
|
|
279
|
-
return /* @__PURE__ */
|
|
241
|
+
return /* @__PURE__ */ jsx2(
|
|
280
242
|
Mermaid,
|
|
281
243
|
{
|
|
282
244
|
id: `mermaid-${mermaidId}`,
|
|
@@ -287,7 +249,7 @@ function renderNode({
|
|
|
287
249
|
key
|
|
288
250
|
);
|
|
289
251
|
}
|
|
290
|
-
return /* @__PURE__ */
|
|
252
|
+
return /* @__PURE__ */ jsx2(
|
|
291
253
|
CodeBlock,
|
|
292
254
|
{
|
|
293
255
|
language: (_a = node.lang) != null ? _a : "text",
|
|
@@ -299,10 +261,10 @@ function renderNode({
|
|
|
299
261
|
);
|
|
300
262
|
}
|
|
301
263
|
case "heading": {
|
|
302
|
-
return /* @__PURE__ */
|
|
264
|
+
return /* @__PURE__ */ jsx2("p", { className: styles2["margin-bottom--2"], children: /* @__PURE__ */ jsx2("strong", { children: renderPhrasingContent(node.children) }) }, key);
|
|
303
265
|
}
|
|
304
266
|
case "thematicBreak": {
|
|
305
|
-
return /* @__PURE__ */
|
|
267
|
+
return /* @__PURE__ */ jsx2("hr", { className: styles2["margin-bottom--2"] }, key);
|
|
306
268
|
}
|
|
307
269
|
case "table": {
|
|
308
270
|
const [headerRow, ...bodyRows] = node.children;
|
|
@@ -310,9 +272,9 @@ function renderNode({
|
|
|
310
272
|
(cell) => renderPhrasingContent(cell.children)
|
|
311
273
|
);
|
|
312
274
|
const rows = bodyRows.map(
|
|
313
|
-
(row) => row.children.map((cell, index) => /* @__PURE__ */
|
|
275
|
+
(row) => row.children.map((cell, index) => /* @__PURE__ */ jsx2("p", { children: renderPhrasingContent(cell.children) }, index))
|
|
314
276
|
);
|
|
315
|
-
return /* @__PURE__ */
|
|
277
|
+
return /* @__PURE__ */ jsx2(
|
|
316
278
|
Table,
|
|
317
279
|
{
|
|
318
280
|
headers,
|
|
@@ -341,7 +303,7 @@ function renderNode({
|
|
|
341
303
|
}
|
|
342
304
|
}
|
|
343
305
|
}
|
|
344
|
-
return /* @__PURE__ */
|
|
306
|
+
return /* @__PURE__ */ jsx2(Callout, { type: calloutType, hasMarginUp: true, hasMarginDown: true, children: /* @__PURE__ */ jsx2("div", { children: strippedChildren.map(
|
|
345
307
|
(child, index) => renderNode({
|
|
346
308
|
node: child,
|
|
347
309
|
key: index,
|
|
@@ -358,17 +320,17 @@ function renderNode({
|
|
|
358
320
|
if (isTaskList) {
|
|
359
321
|
const items = node.children.map((item, index) => {
|
|
360
322
|
const para = item.children.find((c) => c.type === "paragraph");
|
|
361
|
-
const children = (para == null ? void 0 : para.type) === "paragraph" ? /* @__PURE__ */
|
|
323
|
+
const children = (para == null ? void 0 : para.type) === "paragraph" ? /* @__PURE__ */ jsx2("p", { children: renderPhrasingContent(para.children) }) : /* @__PURE__ */ jsx2("p", {});
|
|
362
324
|
return {
|
|
363
325
|
id: String(index),
|
|
364
326
|
isChecked: item.checked === true,
|
|
365
327
|
children
|
|
366
328
|
};
|
|
367
329
|
});
|
|
368
|
-
return /* @__PURE__ */
|
|
330
|
+
return /* @__PURE__ */ jsx2(CheckList, { items, hasMarginUp: true, hasMarginDown: true }, key);
|
|
369
331
|
}
|
|
370
332
|
const Tag = node.ordered ? "ol" : "ul";
|
|
371
|
-
return /* @__PURE__ */
|
|
333
|
+
return /* @__PURE__ */ jsx2(Tag, { className: styles2["margin-bottom--2"], children: node.children.map((item, index) => /* @__PURE__ */ jsx2("li", { children: item.children.map(
|
|
372
334
|
(child, index2) => renderNode({
|
|
373
335
|
node: child,
|
|
374
336
|
key: index2,
|
|
@@ -388,8 +350,8 @@ function renderNodes(nodes, counters) {
|
|
|
388
350
|
);
|
|
389
351
|
}
|
|
390
352
|
function renderSection(section, counters, key = -1) {
|
|
391
|
-
const title = section.titleNodes.length > 0 ? /* @__PURE__ */
|
|
392
|
-
return /* @__PURE__ */
|
|
353
|
+
const title = section.titleNodes.length > 0 ? /* @__PURE__ */ jsx2("p", { children: renderPhrasingContent(section.titleNodes) }) : "";
|
|
354
|
+
return /* @__PURE__ */ jsxs(BlogSection, { title, children: [
|
|
393
355
|
renderNodes(section.nodes, counters),
|
|
394
356
|
section.subsections.map(
|
|
395
357
|
(subsection, index) => renderSection(subsection, counters, index)
|
|
@@ -407,14 +369,14 @@ var renderMarkdownAst = (ast) => {
|
|
|
407
369
|
};
|
|
408
370
|
var MarkdownSections = ({
|
|
409
371
|
rendered
|
|
410
|
-
}) => /* @__PURE__ */
|
|
372
|
+
}) => /* @__PURE__ */ jsx2(Fragment, { children: rendered.sections });
|
|
411
373
|
|
|
412
374
|
// src/components/BlogPost.tsx
|
|
413
|
-
import { jsx as
|
|
375
|
+
import { jsx as jsx3, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
414
376
|
var BlogPost = async ({
|
|
415
377
|
filePath,
|
|
416
378
|
jsonLd,
|
|
417
|
-
increasedWidthMode
|
|
379
|
+
increasedWidthMode,
|
|
418
380
|
isTocEnabled
|
|
419
381
|
}) => {
|
|
420
382
|
const absolutePath = path.isAbsolute(filePath) ? filePath : path.join(process.cwd(), filePath);
|
|
@@ -422,14 +384,14 @@ var BlogPost = async ({
|
|
|
422
384
|
try {
|
|
423
385
|
content = await readFile(absolutePath, "utf8");
|
|
424
386
|
} catch (e) {
|
|
425
|
-
return /* @__PURE__ */
|
|
387
|
+
return /* @__PURE__ */ jsx3(Blog, { increasedWidthMode, isTocEnabled, children: /* @__PURE__ */ jsx3(Callout2, { type: "warning", children: /* @__PURE__ */ jsxs2("p", { children: [
|
|
426
388
|
'Could not read file: "',
|
|
427
389
|
filePath,
|
|
428
390
|
'". Make sure the path is correct and the file exists.'
|
|
429
391
|
] }) }) });
|
|
430
392
|
}
|
|
431
393
|
if (!content.trim()) {
|
|
432
|
-
return /* @__PURE__ */
|
|
394
|
+
return /* @__PURE__ */ jsx3(Blog, { increasedWidthMode, isTocEnabled, children: /* @__PURE__ */ jsxs2(Callout2, { type: "warning", children: [
|
|
433
395
|
'File "',
|
|
434
396
|
filePath,
|
|
435
397
|
'" is empty.'
|
|
@@ -437,9 +399,9 @@ var BlogPost = async ({
|
|
|
437
399
|
}
|
|
438
400
|
const { ast, title, description: desc } = parseMarkdown(content);
|
|
439
401
|
const rendered = renderMarkdownAst(ast);
|
|
440
|
-
return /* @__PURE__ */
|
|
441
|
-
title && /* @__PURE__ */
|
|
442
|
-
/* @__PURE__ */
|
|
402
|
+
return /* @__PURE__ */ jsxs2(Blog, { jsonLd, increasedWidthMode, isTocEnabled, children: [
|
|
403
|
+
title && /* @__PURE__ */ jsx3(BlogHeader, { title: [title], desc: desc ? [desc] : [] }),
|
|
404
|
+
/* @__PURE__ */ jsx3(MarkdownSections, { rendered })
|
|
443
405
|
] });
|
|
444
406
|
};
|
|
445
407
|
var BlogPost_default = BlogPost;
|
|
@@ -469,7 +431,6 @@ var readMarkdownFile = async (filePath) => {
|
|
|
469
431
|
return { success: true, rendered, title, description };
|
|
470
432
|
};
|
|
471
433
|
export {
|
|
472
|
-
BlogPage_default as BlogPage,
|
|
473
434
|
BlogPost_default as BlogPost,
|
|
474
435
|
MarkdownSections,
|
|
475
436
|
readMarkdownFile
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@san-siva/blogkit-md",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.1",
|
|
4
4
|
"description": "Converts markdown files into JSX blog posts for Blogkit",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"exports": {
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
"fix": "eslint . --config eslint.config.ts --fix"
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@san-siva/blogkit": "^1.1.
|
|
24
|
+
"@san-siva/blogkit": "^1.1.51",
|
|
25
25
|
"@san-siva/stylekit": "^1.0.14",
|
|
26
26
|
"next": "^16.0.10",
|
|
27
27
|
"react": "^19.0.0",
|
package/src/index.ts
CHANGED
package/src/client.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { default as BlogPage } from './components/BlogPage';
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
|
|
3
|
-
import { Blog, CheckList } from '@san-siva/blogkit';
|
|
4
|
-
import { useSyncExternalStore } from 'react';
|
|
5
|
-
import type { ReactNode } from 'react';
|
|
6
|
-
|
|
7
|
-
const STORAGE_KEY = 'blogkit-md:increased-width-mode';
|
|
8
|
-
|
|
9
|
-
let increasedWidthMode =
|
|
10
|
-
typeof localStorage === 'undefined'
|
|
11
|
-
? false
|
|
12
|
-
: localStorage.getItem(STORAGE_KEY) === 'true';
|
|
13
|
-
|
|
14
|
-
const listeners = new Set<() => void>();
|
|
15
|
-
|
|
16
|
-
const subscribe = (listener: () => void) => {
|
|
17
|
-
listeners.add(listener);
|
|
18
|
-
return () => listeners.delete(listener);
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
const getSnapshot = () => increasedWidthMode;
|
|
22
|
-
|
|
23
|
-
const setIncreasedWidthMode = (value: boolean) => {
|
|
24
|
-
increasedWidthMode = value;
|
|
25
|
-
localStorage.setItem(STORAGE_KEY, String(value));
|
|
26
|
-
for (const listener of listeners) listener();
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
type BlogPageProperties = {
|
|
30
|
-
children: ReactNode;
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
const BlogPage = ({ children }: BlogPageProperties) => {
|
|
34
|
-
const checked = useSyncExternalStore(subscribe, getSnapshot, () => false);
|
|
35
|
-
|
|
36
|
-
return (
|
|
37
|
-
<Blog increasedWidthMode={checked}>
|
|
38
|
-
<CheckList
|
|
39
|
-
items={[
|
|
40
|
-
{
|
|
41
|
-
id: 'increased-width-mode',
|
|
42
|
-
isChecked: checked,
|
|
43
|
-
onClick: () => setIncreasedWidthMode(!checked),
|
|
44
|
-
children: <p>Increased width mode</p>,
|
|
45
|
-
},
|
|
46
|
-
]}
|
|
47
|
-
/>
|
|
48
|
-
{children}
|
|
49
|
-
</Blog>
|
|
50
|
-
);
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
export default BlogPage;
|