nizel-plugin-frontmatter-ui 0.1.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/README.md ADDED
@@ -0,0 +1,5 @@
1
+ # nizel-plugin-frontmatter-ui
2
+
3
+ Helpers for rendering frontmatter metadata in native apps. Core Nizel already parses frontmatter; this package provides `renderFrontmatterMeta()` and a `::frontmatter` custom block renderer.
4
+
5
+ The browser build exposes `NizelFrontmatterUi` from `dist/frontmatter-ui.iife.js`.
@@ -0,0 +1,59 @@
1
+ "use strict";
2
+ var NizelFrontmatterUi = (() => {
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
+
21
+ // src/index.ts
22
+ var index_exports = {};
23
+ __export(index_exports, {
24
+ default: () => index_default,
25
+ frontmatterUiPlugin: () => frontmatterUiPlugin,
26
+ renderFrontmatterMeta: () => renderFrontmatterMeta
27
+ });
28
+ var frontmatterUiPlugin = (options = {}) => ({
29
+ name: "frontmatter-ui",
30
+ blocks: {
31
+ frontmatter: frontmatterBlock(options)
32
+ }
33
+ });
34
+ var renderFrontmatterMeta = (meta, options = {}) => {
35
+ const rows = Object.entries(meta).map(([key, value]) => `<dt>${escapeHtml(key)}</dt><dd>${escapeHtml(formatValue(value))}</dd>`).join("");
36
+ return `<dl class="${escapeHtml(options.className ?? "frontmatter")}">${rows}</dl>`;
37
+ };
38
+ var frontmatterBlock = (options) => ({
39
+ name: "frontmatter",
40
+ parse({ content, props }) {
41
+ const contentMeta = Object.fromEntries(content.split("\n").filter(Boolean).map((line) => {
42
+ const [key, ...value] = line.split(":");
43
+ return [key.trim(), value.join(":").trim()];
44
+ }));
45
+ const meta = { ...props, ...contentMeta };
46
+ return { meta };
47
+ },
48
+ formats: {
49
+ html(node) {
50
+ if (node.type !== "customBlock") return "";
51
+ return renderFrontmatterMeta(node.value?.meta ?? {}, options);
52
+ }
53
+ }
54
+ });
55
+ var formatValue = (value) => Array.isArray(value) ? value.join(", ") : String(value);
56
+ var escapeHtml = (value) => value.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;");
57
+ var index_default = frontmatterUiPlugin;
58
+ return __toCommonJS(index_exports);
59
+ })();
@@ -0,0 +1,8 @@
1
+ import type { NizelPlugin } from 'nizel';
2
+ export type FrontmatterUiPluginOptions = {
3
+ className?: string;
4
+ };
5
+ export declare const frontmatterUiPlugin: (options?: FrontmatterUiPluginOptions) => NizelPlugin;
6
+ export declare const renderFrontmatterMeta: (meta: Record<string, unknown>, options?: FrontmatterUiPluginOptions) => string;
7
+ export default frontmatterUiPlugin;
8
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAwB,WAAW,EAAE,MAAM,OAAO,CAAC;AAE/D,MAAM,MAAM,0BAA0B,GAAG;IACvC,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF,eAAO,MAAM,mBAAmB,GAAI,UAAS,0BAA+B,KAAG,WAK7E,CAAC;AAEH,eAAO,MAAM,qBAAqB,GAChC,MAAM,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC7B,UAAS,0BAA+B,KACvC,MAKF,CAAC;AAuBF,eAAe,mBAAmB,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,34 @@
1
+ export const frontmatterUiPlugin = (options = {}) => ({
2
+ name: 'frontmatter-ui',
3
+ blocks: {
4
+ frontmatter: frontmatterBlock(options),
5
+ },
6
+ });
7
+ export const renderFrontmatterMeta = (meta, options = {}) => {
8
+ const rows = Object.entries(meta)
9
+ .map(([key, value]) => `<dt>${escapeHtml(key)}</dt><dd>${escapeHtml(formatValue(value))}</dd>`)
10
+ .join('');
11
+ return `<dl class="${escapeHtml(options.className ?? 'frontmatter')}">${rows}</dl>`;
12
+ };
13
+ const frontmatterBlock = (options) => ({
14
+ name: 'frontmatter',
15
+ parse({ content, props }) {
16
+ const contentMeta = Object.fromEntries(content.split('\n').filter(Boolean).map((line) => {
17
+ const [key, ...value] = line.split(':');
18
+ return [key.trim(), value.join(':').trim()];
19
+ }));
20
+ const meta = { ...props, ...contentMeta };
21
+ return { meta };
22
+ },
23
+ formats: {
24
+ html(node) {
25
+ if (node.type !== 'customBlock')
26
+ return '';
27
+ return renderFrontmatterMeta(node.value?.meta ?? {}, options);
28
+ },
29
+ },
30
+ });
31
+ const formatValue = (value) => Array.isArray(value) ? value.join(', ') : String(value);
32
+ const escapeHtml = (value) => value.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;');
33
+ export default frontmatterUiPlugin;
34
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAMA,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,UAAsC,EAAE,EAAe,EAAE,CAAC,CAAC;IAC7F,IAAI,EAAE,gBAAgB;IACtB,MAAM,EAAE;QACN,WAAW,EAAE,gBAAgB,CAAC,OAAO,CAAC;KACvC;CACF,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,qBAAqB,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AE,IAAI,IAAI,EAAE,EAAE,OAAO,CAAC,CAAC;QACpH,CAAC;KACF;CACF,CAAC,CAAC;AAEH,MAAM,WAAW,GAAG,CAAC,KAAc,EAAU,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AACxG,MAAM,UAAU,GAAG,CAAC,KAAa,EAAU,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;AAE/I,eAAe,mBAAmB,CAAC"}
package/package.json ADDED
@@ -0,0 +1,23 @@
1
+ {
2
+ "name": "nizel-plugin-frontmatter-ui",
3
+ "version": "0.1.0",
4
+ "description": "Frontmatter UI helper plugin for Nizel.",
5
+ "repository": { "type": "git", "url": "https://github.com/silvandiepen/nizel" },
6
+ "type": "module",
7
+ "main": "./dist/index.js",
8
+ "types": "./dist/index.d.ts",
9
+ "exports": {
10
+ ".": { "types": "./dist/index.d.ts", "import": "./dist/index.js" },
11
+ "./browser": { "types": "./dist/index.d.ts", "import": "./dist/index.js" }
12
+ },
13
+ "files": ["dist", "README.md"],
14
+ "scripts": {
15
+ "build": "tsc -p tsconfig.json && npm run build:browser",
16
+ "build:browser": "esbuild src/index.ts --bundle --platform=browser --format=iife --global-name=NizelFrontmatterUi --target=safari14 --outfile=dist/frontmatter-ui.iife.js",
17
+ "typecheck": "tsc -p tsconfig.json --noEmit",
18
+ "test": "npm run build && vitest run test/*.mjs"
19
+ },
20
+ "peerDependencies": { "nizel": "^0.1.0" },
21
+ "devDependencies": { "esbuild": "^0.27.3" },
22
+ "publishConfig": { "access": "public", "provenance": true }
23
+ }