@wealthreach/site-kit 1.0.1 → 1.0.2
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/blog/index.d.ts +16 -4
- package/dist/blog/index.js +57 -4
- package/package.json +1 -1
package/dist/blog/index.d.ts
CHANGED
|
@@ -3,10 +3,19 @@ import { SiteConfig } from '../config/index.js';
|
|
|
3
3
|
import React from 'react';
|
|
4
4
|
import '../regulatory-schema-uDKNJ7q8.js';
|
|
5
5
|
|
|
6
|
+
/** True when a blog file begins with a properly closed YAML frontmatter block (`---` or `---yaml`). */
|
|
7
|
+
declare function hasFrontmatterBlock(raw: string): boolean;
|
|
8
|
+
/** True when a file without a valid frontmatter block looks like malformed or non-YAML frontmatter. */
|
|
9
|
+
declare function looksLikeMalformedFrontmatter(raw: string): boolean;
|
|
10
|
+
/** Safely parses YAML frontmatter with gray-matter's JS/eval engines disabled. */
|
|
11
|
+
declare function parseSafeFrontmatter(raw: string): {
|
|
12
|
+
data: Record<string, unknown>;
|
|
13
|
+
content: string;
|
|
14
|
+
};
|
|
6
15
|
/**
|
|
7
|
-
* Contract 3.5 blog post frontmatter schema:
|
|
16
|
+
* Contract 3.5 / 3.8 blog post frontmatter schema:
|
|
8
17
|
* - Accepts `date` or `publishedAt` (normalizing `date` from `publishedAt` when omitted).
|
|
9
|
-
* - Holds are marked `status: "waiting"`
|
|
18
|
+
* - Holds are marked `status: "waiting"` or `published: false` (bare or quoted `"true"`/`"false"`).
|
|
10
19
|
* - Unknown `status` values fail closed in `isPostLive`.
|
|
11
20
|
*/
|
|
12
21
|
declare const postFrontmatterSchema: z.ZodPipe<z.ZodObject<{
|
|
@@ -26,7 +35,10 @@ declare const postFrontmatterSchema: z.ZodPipe<z.ZodObject<{
|
|
|
26
35
|
waiting: "waiting";
|
|
27
36
|
live: "live";
|
|
28
37
|
}>>;
|
|
29
|
-
published: z.ZodOptional<z.ZodBoolean
|
|
38
|
+
published: z.ZodOptional<z.ZodUnion<readonly [z.ZodBoolean, z.ZodPipe<z.ZodEnum<{
|
|
39
|
+
true: "true";
|
|
40
|
+
false: "false";
|
|
41
|
+
}>, z.ZodTransform<boolean, "true" | "false">>]>>;
|
|
30
42
|
}, z.core.$loose>, z.ZodTransform<{
|
|
31
43
|
date: string;
|
|
32
44
|
title: string;
|
|
@@ -127,5 +139,5 @@ declare function DraftOwnerBanner({ slug, className, }: {
|
|
|
127
139
|
className?: string;
|
|
128
140
|
}): React.JSX.Element;
|
|
129
141
|
|
|
130
|
-
export { DRAFT_AUDIENCE_COOKIE, DraftOwnerBanner, assertPostReadable, buildPostJsonLd, createFileSystemPostSource, getPostBySlug, isDraftViewEnabled, isOwnerAudienceCookie, isOwnerDraftAudience, isPostLive, loadPosts, logHiddenPost, postFrontmatterSchema };
|
|
142
|
+
export { DRAFT_AUDIENCE_COOKIE, DraftOwnerBanner, assertPostReadable, buildPostJsonLd, createFileSystemPostSource, getPostBySlug, hasFrontmatterBlock, isDraftViewEnabled, isOwnerAudienceCookie, isOwnerDraftAudience, isPostLive, loadPosts, logHiddenPost, looksLikeMalformedFrontmatter, parseSafeFrontmatter, postFrontmatterSchema };
|
|
131
143
|
export type { BlogPost, PostFrontmatter, PostSource };
|
package/dist/blog/index.js
CHANGED
|
@@ -1,6 +1,37 @@
|
|
|
1
1
|
// src/blog/frontmatter.ts
|
|
2
|
+
import matter from "gray-matter";
|
|
2
3
|
import { z } from "zod";
|
|
3
4
|
var dateField = z.union([z.string().trim().min(1), z.date()]).transform((v) => v instanceof Date ? v.toISOString().slice(0, 10) : v);
|
|
5
|
+
var publishedField = z.union([
|
|
6
|
+
z.boolean(),
|
|
7
|
+
z.enum(["true", "false"]).transform((v) => v === "true")
|
|
8
|
+
]);
|
|
9
|
+
var FRONTMATTER_BLOCK_RE = /^(?:\uFEFF)?---(?:[ \t]*(?:yaml|yml))?[ \t]*\r?\n([\s\S]*?)^---[ \t]*\r?(?:\n|$)/m;
|
|
10
|
+
var MALFORMED_FRONTMATTER_RE = /^(?:\uFEFF)?(?:---(?!-)|(?:status|published):)/;
|
|
11
|
+
var SAFE_MATTER_OPTIONS = {
|
|
12
|
+
engines: {
|
|
13
|
+
js: () => {
|
|
14
|
+
throw new Error("JavaScript frontmatter engine is disabled for security.");
|
|
15
|
+
},
|
|
16
|
+
javascript: () => {
|
|
17
|
+
throw new Error("JavaScript frontmatter engine is disabled for security.");
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
function hasFrontmatterBlock(raw) {
|
|
22
|
+
const match = raw.match(FRONTMATTER_BLOCK_RE);
|
|
23
|
+
return Boolean(match && match.index === 0);
|
|
24
|
+
}
|
|
25
|
+
function looksLikeMalformedFrontmatter(raw) {
|
|
26
|
+
return !hasFrontmatterBlock(raw) && MALFORMED_FRONTMATTER_RE.test(raw.slice(0, 1024));
|
|
27
|
+
}
|
|
28
|
+
function parseSafeFrontmatter(raw) {
|
|
29
|
+
const parsed = matter(raw, SAFE_MATTER_OPTIONS);
|
|
30
|
+
return {
|
|
31
|
+
data: parsed.data ?? {},
|
|
32
|
+
content: parsed.content
|
|
33
|
+
};
|
|
34
|
+
}
|
|
4
35
|
var postFrontmatterSchema = z.object({
|
|
5
36
|
title: z.string().trim().min(1),
|
|
6
37
|
description: z.string().trim().optional().default(""),
|
|
@@ -15,7 +46,7 @@ var postFrontmatterSchema = z.object({
|
|
|
15
46
|
videoUrl: z.string().trim().optional(),
|
|
16
47
|
transcript: z.string().optional(),
|
|
17
48
|
status: z.enum(["waiting", "live"]).optional(),
|
|
18
|
-
published:
|
|
49
|
+
published: publishedField.optional()
|
|
19
50
|
}).passthrough().superRefine((data, ctx) => {
|
|
20
51
|
if (!data.date && !data.publishedAt) {
|
|
21
52
|
ctx.addIssue({
|
|
@@ -32,7 +63,7 @@ var postFrontmatterSchema = z.object({
|
|
|
32
63
|
// src/blog/visibility.ts
|
|
33
64
|
function isPostLive(postOrFrontmatter) {
|
|
34
65
|
const fm = "frontmatter" in postOrFrontmatter && postOrFrontmatter.frontmatter !== null && typeof postOrFrontmatter.frontmatter === "object" ? postOrFrontmatter.frontmatter : postOrFrontmatter;
|
|
35
|
-
if (fm.published === false) return false;
|
|
66
|
+
if (fm.published === false || fm.published === "false") return false;
|
|
36
67
|
if (fm.status !== void 0 && fm.status !== "live") return false;
|
|
37
68
|
return true;
|
|
38
69
|
}
|
|
@@ -53,13 +84,15 @@ function assertPostReadable(post, options) {
|
|
|
53
84
|
// src/blog/source.ts
|
|
54
85
|
import fs from "fs";
|
|
55
86
|
import path from "path";
|
|
56
|
-
import matter from "gray-matter";
|
|
57
87
|
var POST_EXT_RE = /\.(?:mdx|md)$/i;
|
|
58
88
|
function createFileSystemPostSource(options) {
|
|
59
89
|
const baseDir = path.resolve(
|
|
60
90
|
options?.cwd ?? process.cwd(),
|
|
61
91
|
options?.postsDir ?? "data/blog"
|
|
62
92
|
);
|
|
93
|
+
function slugToTitle(slug) {
|
|
94
|
+
return slug.replace(/[-_]+/g, " ").replace(/\b\w/g, (ch) => ch.toUpperCase());
|
|
95
|
+
}
|
|
63
96
|
function parseFile(filePath, slug) {
|
|
64
97
|
try {
|
|
65
98
|
const raw = fs.readFileSync(
|
|
@@ -67,7 +100,24 @@ function createFileSystemPostSource(options) {
|
|
|
67
100
|
filePath,
|
|
68
101
|
"utf8"
|
|
69
102
|
);
|
|
70
|
-
|
|
103
|
+
if (!hasFrontmatterBlock(raw)) {
|
|
104
|
+
if (looksLikeMalformedFrontmatter(raw)) {
|
|
105
|
+
logHiddenPost(slug, "malformed frontmatter block");
|
|
106
|
+
return null;
|
|
107
|
+
}
|
|
108
|
+
return {
|
|
109
|
+
slug,
|
|
110
|
+
filePath,
|
|
111
|
+
frontmatter: {
|
|
112
|
+
title: slugToTitle(slug),
|
|
113
|
+
description: "",
|
|
114
|
+
date: "",
|
|
115
|
+
tags: []
|
|
116
|
+
},
|
|
117
|
+
content: raw
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
const { data, content } = parseSafeFrontmatter(raw);
|
|
71
121
|
const parsed = postFrontmatterSchema.safeParse(data);
|
|
72
122
|
if (!parsed.success) {
|
|
73
123
|
logHiddenPost(
|
|
@@ -249,11 +299,14 @@ export {
|
|
|
249
299
|
buildPostJsonLd,
|
|
250
300
|
createFileSystemPostSource,
|
|
251
301
|
getPostBySlug,
|
|
302
|
+
hasFrontmatterBlock,
|
|
252
303
|
isDraftViewEnabled,
|
|
253
304
|
isOwnerAudienceCookie,
|
|
254
305
|
isOwnerDraftAudience,
|
|
255
306
|
isPostLive,
|
|
256
307
|
loadPosts,
|
|
257
308
|
logHiddenPost,
|
|
309
|
+
looksLikeMalformedFrontmatter,
|
|
310
|
+
parseSafeFrontmatter,
|
|
258
311
|
postFrontmatterSchema
|
|
259
312
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wealthreach/site-kit",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"description": "Shared compliance, universal form tracking, BrandywineOak consent, WCAG 2.2 AA accessibility, blog/draft, and Next.js plumbing for bespoke WealthReach advisor sites.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|