@ubean/seo 0.5.2 → 0.6.0-beta.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/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/dist/json-ld.d.ts +12 -15
- package/dist/json-ld.js +32 -12
- package/package.json +4 -4
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { JsonLdInput, JsonLdSchema, defineJsonLd, mergeJsonLd, renderJsonLdScript, renderJsonLdScripts, schemaOrg, useSchemaOrg } from "./json-ld.js";
|
|
1
|
+
import { JsonLdInput, JsonLdSchema, defineJsonLd, mergeJsonLd, renderJsonLdScript, renderJsonLdScripts, resetSchemaOrgWarning, schemaOrg, serializeJsonLd, useSchemaOrg } from "./json-ld.js";
|
|
2
2
|
import { UseSeoMetaInput } from "@unhead/vue";
|
|
3
3
|
//#region src/index.d.ts
|
|
4
4
|
export interface RobotsOptions {
|
|
@@ -128,4 +128,4 @@ export declare function createSitemapResponse(urls: SitemapUrl[]): Response;
|
|
|
128
128
|
export declare function defineRobotsConfig(config: RobotsOptions[] | RobotsOptions): RobotsOptions[] | RobotsOptions;
|
|
129
129
|
export declare function defineSitemapConfig(urls: SitemapUrl[] | (() => SitemapUrl[] | Promise<SitemapUrl[]>)): SitemapUrl[] | (() => SitemapUrl[] | Promise<SitemapUrl[]>);
|
|
130
130
|
//#endregion
|
|
131
|
-
export { JsonLdInput, JsonLdSchema, type UseSeoMetaInput, defineJsonLd, escapeXml, formatRobotsTxt, formatSitemapXml, mergeJsonLd, renderJsonLdScript, renderJsonLdScripts, schemaOrg, useSchemaOrg };
|
|
131
|
+
export { JsonLdInput, JsonLdSchema, type UseSeoMetaInput, defineJsonLd, escapeXml, formatRobotsTxt, formatSitemapXml, mergeJsonLd, renderJsonLdScript, renderJsonLdScripts, resetSchemaOrgWarning, schemaOrg, serializeJsonLd, useSchemaOrg };
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { defineJsonLd, mergeJsonLd, renderJsonLdScript, renderJsonLdScripts, schemaOrg, useSchemaOrg } from "./json-ld.js";
|
|
1
|
+
import { defineJsonLd, mergeJsonLd, renderJsonLdScript, renderJsonLdScripts, resetSchemaOrgWarning, schemaOrg, serializeJsonLd, useSchemaOrg } from "./json-ld.js";
|
|
2
2
|
import { useSeoMeta as useSeoMeta$1 } from "@unhead/vue";
|
|
3
3
|
//#region src/index.ts
|
|
4
4
|
function useSeoMeta(meta) {
|
|
@@ -356,4 +356,4 @@ function defineSitemapConfig(urls) {
|
|
|
356
356
|
return urls;
|
|
357
357
|
}
|
|
358
358
|
//#endregion
|
|
359
|
-
export { buildLinkTags, buildMetaTags, buildTitle, createManifestResponse, createRobotsResponse, createSitemapResponse, dedupeLinkTags, dedupeMetaTags, defineJsonLd, defineManifest, defineRobotsConfig, defineSitemapConfig, escapeXml, formatRobotsTxt, formatSitemapXml, mergeJsonLd, mergeMetadata, mergeSeoLayers, renderHeadTags, renderJsonLdScript, renderJsonLdScripts, schemaOrg, useSchemaOrg, useSeoMeta };
|
|
359
|
+
export { buildLinkTags, buildMetaTags, buildTitle, createManifestResponse, createRobotsResponse, createSitemapResponse, dedupeLinkTags, dedupeMetaTags, defineJsonLd, defineManifest, defineRobotsConfig, defineSitemapConfig, escapeXml, formatRobotsTxt, formatSitemapXml, mergeJsonLd, mergeMetadata, mergeSeoLayers, renderHeadTags, renderJsonLdScript, renderJsonLdScripts, resetSchemaOrgWarning, schemaOrg, serializeJsonLd, useSchemaOrg, useSeoMeta };
|
package/dist/json-ld.d.ts
CHANGED
|
@@ -38,6 +38,13 @@ export type JsonLdInput = JsonLdSchema | JsonLdSchema[] | (() => JsonLdSchema |
|
|
|
38
38
|
* ```
|
|
39
39
|
*/
|
|
40
40
|
export declare function renderJsonLdScript(schema: JsonLdSchema | JsonLdSchema[]): string;
|
|
41
|
+
/**
|
|
42
|
+
* 把 schema 序列化为**可安全内联进 HTML/JS 字符串**的 JSON。
|
|
43
|
+
*
|
|
44
|
+
* 转义 `</script>`、U+2028/U+2029 —— 与 `renderJsonLdScript()` 是同一份实现,供 Vue 侧的
|
|
45
|
+
* `useSchemaOrg()`(把内容交给 head 的 `textContent`)复用,避免两处转义规则漂移。
|
|
46
|
+
*/
|
|
47
|
+
export declare function serializeJsonLd(schema: JsonLdSchema | JsonLdSchema[]): string;
|
|
41
48
|
/**
|
|
42
49
|
* 把多个 JSON-LD schema 合并为 `@graph` 数组(对齐 schema.org 推荐做法)。
|
|
43
50
|
*
|
|
@@ -61,22 +68,10 @@ export declare function mergeJsonLd(schemas: JsonLdSchema[]): JsonLdSchema | Jso
|
|
|
61
68
|
*/
|
|
62
69
|
export declare function defineJsonLd(schema: JsonLdInput): JsonLdInput;
|
|
63
70
|
/**
|
|
64
|
-
*
|
|
65
|
-
*
|
|
66
|
-
* 在非 Vue setup 上下文中静默降级(返回 schema 本身),不抛错。
|
|
67
|
-
*
|
|
68
|
-
* @example
|
|
69
|
-
* ```vue
|
|
70
|
-
* <script setup>
|
|
71
|
-
* useSchemaOrg({
|
|
72
|
-
* '@context': 'https://schema.org',
|
|
73
|
-
* '@type': 'Article',
|
|
74
|
-
* headline: 'My Article',
|
|
75
|
-
* author: { '@type': 'Person', name: 'John' }
|
|
76
|
-
* });
|
|
77
|
-
* </script>
|
|
78
|
-
* ```
|
|
71
|
+
* 重置「缺 head」告警标志。**仅供测试**(与 `@ubean/vue` 的 `clearMatchers()` 同一用途):
|
|
72
|
+
* 标志是模块级单例,一条用例触发过告警后,后续用例就观察不到它了。
|
|
79
73
|
*/
|
|
74
|
+
export declare function resetSchemaOrgWarning(): void;
|
|
80
75
|
export declare function useSchemaOrg(schema: JsonLdInput): JsonLdInput;
|
|
81
76
|
/**
|
|
82
77
|
* 把多个 JSON-LD schema 渲染为 `<script>` 标签数组(SSR 用)。
|
|
@@ -101,6 +96,8 @@ export declare const schemaOrg: {
|
|
|
101
96
|
headline: string;
|
|
102
97
|
author: string;
|
|
103
98
|
datePublished: string;
|
|
99
|
+
/** Article 经 CreativeWork 继承的标准属性;Google 的 Article 富结果会读它。 */
|
|
100
|
+
description?: string;
|
|
104
101
|
image?: string;
|
|
105
102
|
publisher?: string;
|
|
106
103
|
}): JsonLdSchema;
|
package/dist/json-ld.js
CHANGED
|
@@ -13,7 +13,16 @@
|
|
|
13
13
|
* ```
|
|
14
14
|
*/
|
|
15
15
|
function renderJsonLdScript(schema) {
|
|
16
|
-
return `<script type="application/ld+json">${
|
|
16
|
+
return `<script type="application/ld+json">${serializeJsonLd(schema)}<\/script>`;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* 把 schema 序列化为**可安全内联进 HTML/JS 字符串**的 JSON。
|
|
20
|
+
*
|
|
21
|
+
* 转义 `<\/script>`、U+2028/U+2029 —— 与 `renderJsonLdScript()` 是同一份实现,供 Vue 侧的
|
|
22
|
+
* `useSchemaOrg()`(把内容交给 head 的 `textContent`)复用,避免两处转义规则漂移。
|
|
23
|
+
*/
|
|
24
|
+
function serializeJsonLd(schema) {
|
|
25
|
+
return JSON.stringify(schema).replace(/</g, "\\u003c").replace(/>/g, "\\u003e").replace(/\u2028/g, "\\u2028").replace(/\u2029/g, "\\u2029");
|
|
17
26
|
}
|
|
18
27
|
/**
|
|
19
28
|
* 把多个 JSON-LD schema 合并为 `@graph` 数组(对齐 schema.org 推荐做法)。
|
|
@@ -64,17 +73,27 @@ function defineJsonLd(schema) {
|
|
|
64
73
|
* <\/script>
|
|
65
74
|
* ```
|
|
66
75
|
*/
|
|
76
|
+
let warnedMissingHead = false;
|
|
77
|
+
/**
|
|
78
|
+
* 重置「缺 head」告警标志。**仅供测试**(与 `@ubean/vue` 的 `clearMatchers()` 同一用途):
|
|
79
|
+
* 标志是模块级单例,一条用例触发过告警后,后续用例就观察不到它了。
|
|
80
|
+
*/
|
|
81
|
+
function resetSchemaOrgWarning() {
|
|
82
|
+
warnedMissingHead = false;
|
|
83
|
+
}
|
|
67
84
|
function useSchemaOrg(schema) {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
85
|
+
const head = globalThis.__UBEAN_HEAD__;
|
|
86
|
+
if (head && typeof head.push === "function") {
|
|
87
|
+
head.push({ script: [{
|
|
88
|
+
type: "application/ld+json",
|
|
89
|
+
textContent: serializeJsonLd(schema)
|
|
90
|
+
}] });
|
|
91
|
+
return schema;
|
|
92
|
+
}
|
|
93
|
+
if (!warnedMissingHead) {
|
|
94
|
+
warnedMissingHead = true;
|
|
95
|
+
console.warn("[ubean] useSchemaOrg(): 当前没有 head 实例,JSON-LD 未注入。Vue 应用请从 `ubean/client` 导入 (它走 @unhead/vue 的 useHead);非 Vue 环境请用 `renderJsonLdScript()` 自行注入。");
|
|
96
|
+
}
|
|
78
97
|
return schema;
|
|
79
98
|
}
|
|
80
99
|
/**
|
|
@@ -116,6 +135,7 @@ const schemaOrg = {
|
|
|
116
135
|
name: options.author
|
|
117
136
|
},
|
|
118
137
|
datePublished: options.datePublished,
|
|
138
|
+
...options.description ? { description: options.description } : {},
|
|
119
139
|
...options.image ? { image: options.image } : {},
|
|
120
140
|
...options.publisher ? { publisher: {
|
|
121
141
|
"@type": "Organization",
|
|
@@ -156,4 +176,4 @@ const schemaOrg = {
|
|
|
156
176
|
}
|
|
157
177
|
};
|
|
158
178
|
//#endregion
|
|
159
|
-
export { defineJsonLd, mergeJsonLd, renderJsonLdScript, renderJsonLdScripts, schemaOrg, useSchemaOrg };
|
|
179
|
+
export { defineJsonLd, mergeJsonLd, renderJsonLdScript, renderJsonLdScripts, resetSchemaOrgWarning, schemaOrg, serializeJsonLd, useSchemaOrg };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ubean/seo",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0-beta.2",
|
|
4
4
|
"description": "SEO utilities for ubean (useSeoMeta, robots, sitemap, manifest, file conventions, JSON-LD, OG image)",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist"
|
|
@@ -28,13 +28,13 @@
|
|
|
28
28
|
}
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@unhead/vue": "^3.4.
|
|
31
|
+
"@unhead/vue": "^3.4.1",
|
|
32
32
|
"pathe": "^2.0.3"
|
|
33
33
|
},
|
|
34
34
|
"devDependencies": {
|
|
35
|
-
"@types/node": "^26.
|
|
35
|
+
"@types/node": "^26.6.1",
|
|
36
36
|
"typescript": "npm:typescript-native-bridge@latest",
|
|
37
|
-
"vite-plus": "0.3.
|
|
37
|
+
"vite-plus": "0.3.3"
|
|
38
38
|
},
|
|
39
39
|
"peerDependencies": {
|
|
40
40
|
"@resvg/resvg-js": "^2.6.0",
|