@lownoise-studio/rendershield 0.3.0 → 1.0.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/CHANGELOG.md +58 -0
- package/CONTRIBUTING.md +41 -0
- package/README.md +209 -138
- package/SECURITY.md +25 -0
- package/dist/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +43 -21
- package/dist/cli.js.map +1 -1
- package/dist/commands/build.d.ts +2 -0
- package/dist/commands/build.d.ts.map +1 -0
- package/dist/commands/build.js +10 -9
- package/dist/commands/build.js.map +1 -1
- package/dist/commands/init.d.ts +2 -0
- package/dist/commands/init.d.ts.map +1 -0
- package/dist/commands/init.js +7 -7
- package/dist/commands/init.js.map +1 -1
- package/dist/commands/verify.d.ts +19 -0
- package/dist/commands/verify.d.ts.map +1 -0
- package/dist/commands/verify.js +60 -64
- package/dist/commands/verify.js.map +1 -1
- package/dist/core/generateRobots.d.ts +3 -0
- package/dist/core/generateRobots.d.ts.map +1 -0
- package/dist/core/generateSitemap.d.ts +3 -0
- package/dist/core/generateSitemap.d.ts.map +1 -0
- package/dist/core/generateWorker.d.ts +3 -0
- package/dist/core/generateWorker.d.ts.map +1 -0
- package/dist/core/generateWorker.js +85 -75
- package/dist/core/generateWorker.js.map +1 -1
- package/dist/core/loadConfig.d.ts +3 -0
- package/dist/core/loadConfig.d.ts.map +1 -0
- package/dist/core/loadConfig.js +99 -40
- package/dist/core/loadConfig.js.map +1 -1
- package/dist/core/loadMarkdown.d.ts +3 -0
- package/dist/core/loadMarkdown.d.ts.map +1 -0
- package/dist/core/loadMarkdown.js +4 -3
- package/dist/core/loadMarkdown.js.map +1 -1
- package/dist/core/renderHtml.d.ts +3 -0
- package/dist/core/renderHtml.d.ts.map +1 -0
- package/dist/core/renderHtml.js +30 -11
- package/dist/core/renderHtml.js.map +1 -1
- package/dist/core/validateOutput.d.ts +28 -0
- package/dist/core/validateOutput.d.ts.map +1 -0
- package/dist/core/validateOutput.js +9 -3
- package/dist/core/validateOutput.js.map +1 -1
- package/dist/errors.d.ts +14 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +24 -0
- package/dist/errors.js.map +1 -0
- package/dist/index.d.ts +20 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +19 -0
- package/dist/index.js.map +1 -0
- package/dist/types.d.ts +53 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +1 -1
- package/dist/types.js.map +1 -1
- package/docs/deploy-cloudflare.md +40 -14
- package/package.json +30 -4
- package/src/cli.ts +86 -60
- package/src/commands/build.ts +199 -185
- package/src/commands/init.ts +7 -7
- package/src/commands/verify.ts +266 -233
- package/src/core/generateWorker.ts +97 -87
- package/src/core/loadConfig.ts +261 -142
- package/src/core/loadMarkdown.ts +11 -5
- package/src/core/renderHtml.ts +41 -13
- package/src/core/validateOutput.ts +335 -325
- package/src/errors.ts +48 -0
- package/src/index.ts +40 -0
- package/src/types.ts +4 -1
package/src/core/renderHtml.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { MarkdownDoc, RenderShieldConfig } from "../types.js";
|
|
1
|
+
import { MarkdownDoc, RenderShieldConfig, SchemaType } from "../types.js";
|
|
2
2
|
|
|
3
3
|
function escapeHtml(s: string): string {
|
|
4
4
|
return s
|
|
@@ -15,6 +15,37 @@ function joinUrl(base: string, pathname: string): string {
|
|
|
15
15
|
return b + p;
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
+
function resolveSchemaType(cfg: RenderShieldConfig, doc: MarkdownDoc): SchemaType {
|
|
19
|
+
const collection = cfg.content.markdown.collections.find((c) => c.name === doc.collection);
|
|
20
|
+
return collection?.schemaType ?? "Article";
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function buildJsonLd(
|
|
24
|
+
schemaType: SchemaType,
|
|
25
|
+
cfg: RenderShieldConfig,
|
|
26
|
+
doc: MarkdownDoc,
|
|
27
|
+
canonicalUrl: string,
|
|
28
|
+
ogImageUrl: string
|
|
29
|
+
): Record<string, unknown> {
|
|
30
|
+
const base = {
|
|
31
|
+
"@context": "https://schema.org",
|
|
32
|
+
"@type": schemaType,
|
|
33
|
+
mainEntityOfPage: canonicalUrl,
|
|
34
|
+
image: ogImageUrl,
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
if (schemaType === "WebPage") {
|
|
38
|
+
return { ...base, name: doc.title };
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
return {
|
|
42
|
+
...base,
|
|
43
|
+
headline: doc.title,
|
|
44
|
+
author: { "@type": "Person", name: cfg.site.authorName },
|
|
45
|
+
datePublished: doc.datePublished,
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
|
|
18
49
|
export function renderPageHtml(cfg: RenderShieldConfig, doc: MarkdownDoc): string {
|
|
19
50
|
const canonicalUrl = joinUrl(cfg.site.canonicalBase, doc.routePath);
|
|
20
51
|
const ogImageUrl = doc.coverImage.startsWith("http")
|
|
@@ -23,16 +54,9 @@ export function renderPageHtml(cfg: RenderShieldConfig, doc: MarkdownDoc): strin
|
|
|
23
54
|
|
|
24
55
|
const title = `${doc.title} - ${cfg.site.siteName}`;
|
|
25
56
|
const description = doc.excerpt;
|
|
26
|
-
|
|
27
|
-
const
|
|
28
|
-
|
|
29
|
-
"@type": "Article",
|
|
30
|
-
headline: doc.title,
|
|
31
|
-
author: { "@type": "Person", name: cfg.site.authorName },
|
|
32
|
-
datePublished: doc.datePublished,
|
|
33
|
-
image: ogImageUrl,
|
|
34
|
-
mainEntityOfPage: canonicalUrl,
|
|
35
|
-
};
|
|
57
|
+
const schemaType = resolveSchemaType(cfg, doc);
|
|
58
|
+
const ogType = schemaType === "WebPage" ? "website" : "article";
|
|
59
|
+
const jsonLd = buildJsonLd(schemaType, cfg, doc, canonicalUrl, ogImageUrl);
|
|
36
60
|
|
|
37
61
|
// NOTE: doc.htmlContent is already HTML from markdown-it.
|
|
38
62
|
// We trust it as generated output, not user-injected raw HTML (markdown-it html:false).
|
|
@@ -46,7 +70,7 @@ export function renderPageHtml(cfg: RenderShieldConfig, doc: MarkdownDoc): strin
|
|
|
46
70
|
<meta name="description" content="${escapeHtml(description)}">
|
|
47
71
|
<link rel="canonical" href="${escapeHtml(canonicalUrl)}">
|
|
48
72
|
|
|
49
|
-
<meta property="og:type" content="
|
|
73
|
+
<meta property="og:type" content="${ogType}">
|
|
50
74
|
<meta property="og:title" content="${escapeHtml(doc.title)}">
|
|
51
75
|
<meta property="og:description" content="${escapeHtml(description)}">
|
|
52
76
|
<meta property="og:image" content="${escapeHtml(ogImageUrl)}">
|
|
@@ -57,7 +81,11 @@ export function renderPageHtml(cfg: RenderShieldConfig, doc: MarkdownDoc): strin
|
|
|
57
81
|
<meta name="twitter:description" content="${escapeHtml(description)}">
|
|
58
82
|
<meta name="twitter:image" content="${escapeHtml(ogImageUrl)}">
|
|
59
83
|
|
|
60
|
-
<script type="application/ld+json">${
|
|
84
|
+
<script type="application/ld+json">${((): string => {
|
|
85
|
+
const raw = JSON.stringify(jsonLd);
|
|
86
|
+
// Case-insensitive: </script> and </SCRIPT> etc. must not break out of the tag
|
|
87
|
+
return raw.replace(/<\/script>/gi, "<\\/script>");
|
|
88
|
+
})()}</script>
|
|
61
89
|
</head>
|
|
62
90
|
<body>
|
|
63
91
|
<main>
|