@techjiang/vuepress-plugin-jsonld 0.0.0-stage → 1.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/CHANGELOG.md ADDED
@@ -0,0 +1,21 @@
1
+ # Changelog
2
+
3
+ 本插件遵循 [语义化版本 2.0.0](https://semver.org/lang/zh-CN/)。
4
+
5
+ ## 1.1.0 (2026-12-05)
6
+
7
+ - 支持 `author` 数组输入(多作者),统一解析为 schema.org Person / Organization 节点
8
+ - 支持 `tags` 逗号分隔字符串写法
9
+ - `datePublished` 缺失时兜底使用 VuePress 从 git 提取的页面创建日期
10
+ - 注入去重:相同 ld+json 内容不会因钩子多次触发而重复输出
11
+ - 配置项预校验:`hostname` / `type` 非法配置在插件注册阶段即给出中文警告
12
+ - 防御性增强:frontmatter 缺失兜底、空路径守卫、无效作者条目逐条警告并跳过
13
+ - 补充单元测试(`node tests/run.mjs`)
14
+
15
+ ## 1.0.0 (2026-12-05)
16
+
17
+ - 首个版本
18
+ - `extendsPage` 钩子注入 SSR 首屏 JSON-LD(TechArticle / WebSite / Organization / BreadcrumbList / FAQPage)
19
+ - 日期自动转 ISO 8601、图片自动补全 HTTPS 绝对 URL、缺失字段跳过不输出空值
20
+ - 构建时中文警告校验(指向具体文件路径)
21
+ - 配置项:`type` / `author` / `image` / `hostname` / `additionalSchemas`
package/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2026 科技酱 (TechSauce)
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/README.md CHANGED
@@ -1,3 +1,157 @@
1
- # Temporary Holding Version
1
+ # JSON-LD
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ VuePress 2 插件:**构建时**向每个页面的 head 注入符合 [schema.org](https://schema.org) 规范的 JSON-LD 结构化数据。
4
+
5
+ - 技术栈:TypeScript + ES Modules + tsup 打包
6
+ - 注入方式:通过 `extendsPage` / `onPrepared` 钩子写入页面的 head 配置,**SSR 首屏静态输出**,不依赖客户端动态插入
7
+ - 收录分类:VuePress 官方插件市场 · 站点管理 → SEO
8
+
9
+ ## 自动生成的 schema 类型
10
+
11
+ | 页面特征 | 生成类型 |
12
+ | --- | --- |
13
+ | 首页(`frontmatter.home: true` 或站点根路径) | `WebSite` + `Organization` |
14
+ | 普通文章 | `TechArticle`(可用 `type` 配置覆盖) |
15
+ | 存在父级目录页(与主题侧边栏一致的层级结构) | 额外生成 `BreadcrumbList` |
16
+ | frontmatter 声明 `faq` | 额外生成 `FAQPage` |
17
+
18
+ ## 特性
19
+
20
+ - 读取 frontmatter 的 `title` / `description` / `date` / `dateModified` / `author` / `image` / `tags`
21
+ - 日期自动转为 ISO 8601(如 `2024-03-10T01:30:00.000Z`);缺失时兜底使用 VuePress 从 git 提取的页面创建日期
22
+ - `author` 支持字符串 / 对象 / 数组(多作者),统一解析为 schema.org 节点
23
+ - `tags` 支持数组或逗号分隔字符串,输出为 `keywords`
24
+ - `image` 自动补全为基于站点 `base` 与 `hostname` 的 HTTPS 绝对 URL
25
+ - 缺失字段直接跳过该属性,绝不输出空值
26
+ - 相同 ld+json 内容自动去重,不会因钩子多次触发而重复注入
27
+ - 构建时校验:图片非绝对 HTTPS、日期格式非法、必填字段缺失时输出清晰的中文警告,并指出具体文件路径
28
+
29
+ ## 安装
30
+
31
+ ```bash
32
+ npm install @techjiang/vuepress-plugin-jsonld
33
+ ```
34
+
35
+ > 说明:无作用域的 `vuepress-plugin-jsonld` 包名已被第三方占用,故 npm 包使用 `@techjiang` 作用域发布。
36
+
37
+ ## 使用示例(.vuepress/config.ts)
38
+
39
+ ```ts
40
+ import { defineUserConfig } from 'vuepress'
41
+ import { defaultTheme } from '@vuepress/theme-default'
42
+ import { jsonldPlugin } from '@techjiang/vuepress-plugin-jsonld'
43
+
44
+ export default defineUserConfig({
45
+ base: '/blog/',
46
+ title: '科技酱的技术博客',
47
+ description: '分享前端工程化与 VuePress 的实践经验',
48
+
49
+ theme: defaultTheme({ /* ... */ }),
50
+
51
+ plugins: [
52
+ jsonldPlugin({
53
+ // 站点域名:用于把相对路径图片 / 面包屑 URL 补全为 HTTPS 绝对 URL
54
+ hostname: 'https://example.com',
55
+ // 手动覆盖文章 schema 类型(默认 'TechArticle')
56
+ type: 'TechArticle',
57
+ // 默认作者:页面未写 author 时使用
58
+ author: { name: '科技酱', url: 'https://www.asoe.cn' },
59
+ // 默认图片:页面未写 image 时使用
60
+ image: '/images/default-cover.png',
61
+ // 额外追加的自定义 schema(原样输出到每个页面)
62
+ additionalSchemas: [
63
+ {
64
+ '@context': 'https://schema.org',
65
+ '@type': 'WebSite',
66
+ potentialAction: {
67
+ '@type': 'SearchAction',
68
+ target: 'https://example.com/blog/search?q={search_term_string}',
69
+ 'query-input': 'required name=search_term_string',
70
+ },
71
+ },
72
+ ],
73
+ }),
74
+ ],
75
+ })
76
+ ```
77
+
78
+ ### 页面 frontmatter 示例
79
+
80
+ ```yaml
81
+ ---
82
+ title: 使用 JSON-LD 插件的第一篇文章
83
+ description: 演示 TechArticle schema 的自动生成
84
+ author:
85
+ - 张三
86
+ - name: 李四
87
+ url: https://example.com/lisi
88
+ date: 2024-03-10 09:30:00
89
+ dateModified: 2026-01-15T10:30:00+08:00
90
+ image: /images/cover.png
91
+ tags: JSON-LD, 结构化数据 # 数组写法亦可
92
+ faq: # 声明后额外生成 FAQPage
93
+ - question: 插件如何注入 JSON-LD?
94
+ answer: 构建时写入页面 head 配置,SSR 首屏直接输出。
95
+ ---
96
+ ```
97
+
98
+ ### 关闭单个页面的注入
99
+
100
+ ```yaml
101
+ ---
102
+ jsonld: false
103
+ ---
104
+ ```
105
+
106
+ ## 配置项
107
+
108
+ | 参数 | 类型 | 说明 |
109
+ | --- | --- | --- |
110
+ | `hostname` | `string` | 站点域名(如 `https://example.com`),用于图片与 URL 的绝对化补全 |
111
+ | `type` | `string` | 覆盖文章 schema 类型,默认 `TechArticle` |
112
+ | `author` | `string \| object \| array` | 默认作者 |
113
+ | `image` | `string` | 默认图片 |
114
+ | `additionalSchemas` | `SchemaNode[] \| ((page, app) => SchemaNode[])` | 额外追加的 schema,支持按页面动态返回 |
115
+
116
+ ## 构建警告示例
117
+
118
+ ```text
119
+ [vuepress-plugin-jsonld] 警告:图片地址 "/images/cover.png" 是相对路径,但插件未配置 hostname,无法补全为 HTTPS 绝对 URL,已跳过 image 属性;请在插件配置中添加 hostname(如 'https://example.com'),或直接使用 https:// 开头的绝对 URL
120
+ [vuepress-plugin-jsonld] 文件:/path/to/posts/hello.md
121
+ ```
122
+
123
+ ## 本地开发
124
+
125
+ ```bash
126
+ npm run build # tsup 构建插件(lib/)
127
+ npm test # 运行单元测试(node:test)
128
+ npm run demo:dev # 运行示例站点 dev server
129
+ npm run demo:build # 构建示例站点,可检查产物 HTML 中的 ld+json
130
+ ```
131
+
132
+ ## 收录到 VuePress 官方插件市场
133
+
134
+ 本插件计划提交至 [VuePress 插件市场](https://marketplace.vuejs.press/zh/plugins/) 的「站点管理 → SEO」分类(与 `@vuepress/plugin-seo`、`vuepress-plugin-open-graph` 同类)。
135
+
136
+ 提交 PR 时将遵循官方[贡献指南](https://marketplace.vuejs.press/zh/reference/contributing.html) 并声明:
137
+
138
+ - 本作品是 VuePress 2 的插件,开源且采用 Apache-2.0 协议
139
+ - 已建立详细的中文使用文档
140
+ - 兼容最新 VuePress 2 版本,并持续跟进后续版本
141
+ - 如放弃维护,将提交 PR 从列表中移除
142
+
143
+ ## 作者
144
+
145
+ **科技酱 (TechSauce)**
146
+
147
+ - 作者描述:同一个世界,同一个互联网!
148
+ - 技术文档:https://docs.asoe.cn
149
+ - GitHub:https://github.com/techjiang/
150
+ - 哔哩哔哩:https://space.bilibili.com/1768832152
151
+ - 邮箱:official@tech.asoe.cn
152
+ - 玲珑(论坛):https://forums.asoe.cn/
153
+ - QQ 群:291974598 / 474819022 / 631167288
154
+
155
+ ## License
156
+
157
+ [Apache-2.0](./LICENSE) © 科技酱 (TechSauce)
package/lib/index.d.ts ADDED
@@ -0,0 +1,134 @@
1
+ import { Page, App, Plugin } from 'vuepress/core';
2
+
3
+ /**
4
+ * Copyright 2026 科技酱 (TechSauce)
5
+ *
6
+ * Licensed under the Apache License, Version 2.0 (the "License");
7
+ * you may not use this file except in compliance with the License.
8
+ * You may obtain a copy of the License at
9
+ *
10
+ * http://www.apache.org/licenses/LICENSE-2.0
11
+ *
12
+ * Unless required by applicable law or agreed to in writing, software
13
+ * distributed under the License is distributed on an "AS IS" BASIS,
14
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ * See the License for the specific language governing permissions and
16
+ * limitations under the License.
17
+ */
18
+ /**
19
+ * vuepress-plugin-jsonld 类型声明
20
+ *
21
+ * 插件配置项与内部使用的 schema.org 节点类型定义。
22
+ */
23
+
24
+ /** 单个作者条目:字符串或 schema.org Person / Organization 对象 */
25
+ type AuthorItem = string | {
26
+ '@type'?: 'Person' | 'Organization';
27
+ name: string;
28
+ url?: string;
29
+ };
30
+ /** 作者输入:兼容字符串 / 对象 / 数组(多作者),统一解析为 schema.org 节点 */
31
+ type AuthorInput = AuthorItem | AuthorItem[];
32
+ /** schema.org JSON-LD 节点(宽松结构,允许任意 schema.org 属性) */
33
+ type SchemaNode = Record<string, unknown>;
34
+ /** 页面 frontmatter 中可识别的 JSON-LD 相关字段 */
35
+ interface JsonldFrontmatter {
36
+ title?: string;
37
+ description?: string;
38
+ /** 发布日期,接受 Date / ISO 字符串 / 时间戳 */
39
+ date?: unknown;
40
+ /** 修改日期,接受 Date / ISO 字符串 / 时间戳 */
41
+ dateModified?: unknown;
42
+ /** 作者,字符串、对象或数组(多作者) */
43
+ author?: AuthorInput;
44
+ /** 封面图,站点内相对路径(以 / 开头)或 https 绝对 URL */
45
+ image?: string;
46
+ /** 标签列表,输出为 keywords;也接受逗号分隔字符串 */
47
+ tags?: string[] | string;
48
+ /**
49
+ * FAQ 结构:存在时额外生成 FAQPage schema
50
+ * question / q 与 answer / a 均可识别
51
+ */
52
+ faq?: {
53
+ question?: string;
54
+ q?: string;
55
+ answer?: string;
56
+ a?: string;
57
+ }[];
58
+ /** 设为 false 可完全关闭该页面的 JSON-LD 注入 */
59
+ jsonld?: boolean;
60
+ [key: string]: unknown;
61
+ }
62
+ /** 插件配置项 */
63
+ interface JsonldPluginOptions {
64
+ /**
65
+ * 手动覆盖普通文章页的 schema 类型(默认 'TechArticle')。
66
+ * 例如 'Article'、'BlogPosting'、'HowTo' 等 schema.org 类型名。
67
+ */
68
+ type?: string;
69
+ /**
70
+ * 默认作者:页面 frontmatter.author 缺失时使用。
71
+ * 字符串或 schema.org Person / Organization 对象。
72
+ */
73
+ author?: AuthorInput;
74
+ /**
75
+ * 默认图片:页面 frontmatter.image 缺失时使用。
76
+ * 相对路径会基于站点 base 与 hostname 自动补全为 HTTPS 绝对 URL。
77
+ */
78
+ image?: string;
79
+ /**
80
+ * 站点域名(不带末尾斜杠),如 'https://example.com'。
81
+ * 用于把相对路径的图片 / 面包屑 URL 补全为绝对 URL;
82
+ * 未配置时,frontmatter 中的相对路径图片会触发中文警告。
83
+ */
84
+ hostname?: string;
85
+ /**
86
+ * 额外的 JSON-LD schema,会原样追加到每个页面的 head 中。
87
+ * 支持静态数组,或根据页面动态返回数组的函数。
88
+ */
89
+ additionalSchemas?: SchemaNode[] | ((page: Page, app: App) => SchemaNode[]);
90
+ }
91
+
92
+ /**
93
+ * Copyright 2026 科技酱 (TechSauce)
94
+ *
95
+ * Licensed under the Apache License, Version 2.0 (the "License");
96
+ * you may not use this file except in compliance with the License.
97
+ * You may obtain a copy of the License at
98
+ *
99
+ * http://www.apache.org/licenses/LICENSE-2.0
100
+ *
101
+ * Unless required by applicable law or agreed to in writing, software
102
+ * distributed under the License is distributed on an "AS IS" BASIS,
103
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
104
+ * See the License for the specific language governing permissions and
105
+ * limitations under the License.
106
+ */
107
+ /**
108
+ * vuepress-plugin-jsonld
109
+ *
110
+ * VuePress 2 插件:构建时(SSR 阶段)向每个页面的 head 注入符合
111
+ * schema.org 规范的 JSON-LD 结构化数据。
112
+ *
113
+ * 作者:科技酱 (TechSauce) https://docs.asoe.cn
114
+ * 核心行为:
115
+ * 1. 通过 extendsPage 钩子读取页面 frontmatter:
116
+ * title / description / date / dateModified / author / image / tags
117
+ * 2. 自动判断 schema 类型:
118
+ * - 首页(frontmatter.home === true 或站点根路径)→ WebSite + Organization
119
+ * - 普通文章 → TechArticle(可通过 options.type 覆盖)
120
+ * - 存在父级目录页(与主题侧边栏一致的层级结构)→ 额外生成 BreadcrumbList
121
+ * - frontmatter.faq → 额外生成 FAQPage
122
+ * 3. 日期自动转为 ISO 8601;image 自动补全为基于站点 base 的 HTTPS 绝对 URL;
123
+ * 缺失字段直接跳过该属性,绝不输出空值。
124
+ * 4. 通过页面 head 配置注入 <script type="application/ld+json"> —— 这是 SSR
125
+ * 静态标签,首屏 HTML 直接携带,不依赖任何客户端动态插入;
126
+ * 相同内容自动去重,不会因钩子多次触发而重复注入。
127
+ * 5. 构建时校验:图片非绝对 HTTPS、日期非法、必填字段缺失时输出清晰的
128
+ * 中文警告,并指出具体文件路径。
129
+ */
130
+
131
+ /** 插件工厂:返回 VuePress 2 插件对象 */
132
+ declare function jsonldPlugin(options?: JsonldPluginOptions): Plugin;
133
+
134
+ export { type AuthorInput, type JsonldFrontmatter, type JsonldPluginOptions, type SchemaNode, jsonldPlugin as default, jsonldPlugin };
package/lib/index.js ADDED
@@ -0,0 +1,316 @@
1
+ // src/index.ts
2
+ var PLUGIN_NAME = "vuepress-plugin-jsonld";
3
+ var warned = /* @__PURE__ */ new Set();
4
+ function warnOnce(file, message) {
5
+ const key = `${file}#${message}`;
6
+ if (warned.has(key)) return;
7
+ warned.add(key);
8
+ console.warn(`[${PLUGIN_NAME}] \u8B66\u544A\uFF1A${message}
9
+ [${PLUGIN_NAME}] \u6587\u4EF6\uFF1A${file}`);
10
+ }
11
+ function isHttpsUrl(value) {
12
+ return /^https:\/\/[^\s]+$/i.test(value);
13
+ }
14
+ function trimSlash(value) {
15
+ return value.replace(/\/+$/, "");
16
+ }
17
+ function toIsoDate(raw, file, field) {
18
+ if (raw === void 0 || raw === null || raw === "") return null;
19
+ const date = raw instanceof Date ? raw : new Date(raw);
20
+ if (Number.isNaN(date.getTime())) {
21
+ warnOnce(
22
+ file,
23
+ `\u65E5\u671F\u5B57\u6BB5\u300C${field}\u300D\u7684\u503C "${String(raw)}" \u683C\u5F0F\u975E\u6CD5\uFF0C\u65E0\u6CD5\u89E3\u6790\u4E3A\u65E5\u671F\uFF0C\u5DF2\u8DF3\u8FC7\u8BE5\u5C5E\u6027\uFF1B\u8BF7\u4F7F\u7528 ISO 8601 \u683C\u5F0F\uFF08\u5982 2024-01-01T08:00:00+08:00\uFF09`
24
+ );
25
+ return null;
26
+ }
27
+ return date.toISOString();
28
+ }
29
+ function resolveImage(raw, base, hostname, file) {
30
+ const value = (raw ?? "").trim();
31
+ if (value === "") return null;
32
+ if (/^https?:\/\//i.test(value)) {
33
+ if (!/^https:\/\//i.test(value)) {
34
+ warnOnce(
35
+ file,
36
+ `\u56FE\u7247\u5730\u5740 "${value}" \u4E0D\u662F HTTPS \u534F\u8BAE\uFF0Cschema.org \u5EFA\u8BAE\uFF08Google \u8981\u6C42\uFF09\u4F7F\u7528 https:// \u7EDD\u5BF9 URL`
37
+ );
38
+ }
39
+ return value;
40
+ }
41
+ if (!hostname) {
42
+ warnOnce(
43
+ file,
44
+ `\u56FE\u7247\u5730\u5740 "${value}" \u662F\u76F8\u5BF9\u8DEF\u5F84\uFF0C\u4F46\u63D2\u4EF6\u672A\u914D\u7F6E hostname\uFF0C\u65E0\u6CD5\u8865\u5168\u4E3A HTTPS \u7EDD\u5BF9 URL\uFF0C\u5DF2\u8DF3\u8FC7 image \u5C5E\u6027\uFF1B\u8BF7\u5728\u63D2\u4EF6\u914D\u7F6E\u4E2D\u6DFB\u52A0 hostname\uFF08\u5982 'https://example.com'\uFF09\uFF0C\u6216\u76F4\u63A5\u4F7F\u7528 https:// \u5F00\u5934\u7684\u7EDD\u5BF9 URL`
45
+ );
46
+ return null;
47
+ }
48
+ return `${hostname}${trimSlash(base)}/${value.replace(/^\/+/, "")}`;
49
+ }
50
+ function toAbsoluteUrl(path, base, hostname) {
51
+ if (!hostname) return path;
52
+ const cleanPath = path.startsWith(base) ? path : `${trimSlash(base)}${path}`;
53
+ return `${hostname}${cleanPath.startsWith("/") ? cleanPath : `/${cleanPath}`}`;
54
+ }
55
+ function normalizeAuthorItem(raw, file, field) {
56
+ if (typeof raw === "string") {
57
+ return raw === "" ? null : { "@type": "Person", name: raw };
58
+ }
59
+ if (typeof raw === "object" && raw !== null && typeof raw.name === "string" && raw.name !== "") {
60
+ const node = { "@type": raw["@type"] ?? "Person", name: raw.name };
61
+ if (raw.url) node.url = raw.url;
62
+ return node;
63
+ }
64
+ warnOnce(file, `\u5B57\u6BB5\u300C${field}\u300D\u5B58\u5728\u65E0\u6CD5\u8BC6\u522B\u7684\u4F5C\u8005\u6761\u76EE\uFF08\u5E94\u4E3A\u5B57\u7B26\u4E32\u6216\u542B name \u7684\u5BF9\u8C61\uFF09\uFF0C\u8BE5\u6761\u76EE\u5DF2\u8DF3\u8FC7`);
65
+ return null;
66
+ }
67
+ function normalizeAuthors(raw, file, field) {
68
+ if (raw === void 0 || raw === null || raw === "") return null;
69
+ const list = Array.isArray(raw) ? raw : [raw];
70
+ const nodes = list.map((item) => normalizeAuthorItem(item, file, field)).filter((item) => item !== null);
71
+ if (nodes.length === 0) return null;
72
+ return nodes.length === 1 ? nodes[0] : nodes;
73
+ }
74
+ function assignIfDefined(node, key, value) {
75
+ if (value === void 0 || value === null || value === "") return;
76
+ node[key] = value;
77
+ }
78
+ function isHomePage(page, base) {
79
+ return page.frontmatter.home === true || page.path === base || page.path === "/";
80
+ }
81
+ function buildBreadcrumb(page, app, pages, base, hostname) {
82
+ if (typeof page.path !== "string" || page.path === "") return null;
83
+ const dirPath = page.path.slice(0, page.path.lastIndexOf("/") + 1);
84
+ const relativeDir = dirPath.startsWith(base) ? dirPath.slice(base.length) : dirPath;
85
+ const segments = relativeDir.split("/").filter(Boolean);
86
+ if (segments.length === 0) return null;
87
+ const siteName = app.options.title || page.title;
88
+ if (!siteName) return null;
89
+ const items = [
90
+ {
91
+ "@type": "ListItem",
92
+ position: 1,
93
+ name: siteName,
94
+ item: toAbsoluteUrl(base, base, hostname)
95
+ }
96
+ ];
97
+ let acc = "";
98
+ for (const segment of segments) {
99
+ acc += `${segment}/`;
100
+ const parentPath = `/${acc}`;
101
+ const parent = pages.find(
102
+ (p) => p.path === parentPath || p.path === `${base}${acc}` || p.path === `${parentPath}index.html` || p.path === `${base}${acc}index.html`
103
+ );
104
+ if (!parent) continue;
105
+ items.push({
106
+ "@type": "ListItem",
107
+ position: items.length + 1,
108
+ name: parent.title || segment,
109
+ item: toAbsoluteUrl(parent.path, base, hostname)
110
+ });
111
+ }
112
+ items.push({
113
+ "@type": "ListItem",
114
+ position: items.length + 1,
115
+ name: page.title || page.path,
116
+ item: toAbsoluteUrl(page.path, base, hostname)
117
+ });
118
+ return {
119
+ "@context": "https://schema.org",
120
+ "@type": "BreadcrumbList",
121
+ itemListElement: items
122
+ };
123
+ }
124
+ function buildFaqPage(page, file) {
125
+ const faq = page.frontmatter.faq;
126
+ if (!Array.isArray(faq) || faq.length === 0) return null;
127
+ const mainEntity = faq.map((entry) => {
128
+ const question = entry.question ?? entry.q;
129
+ const answer = entry.answer ?? entry.a;
130
+ if (!question || !answer) {
131
+ warnOnce(
132
+ file,
133
+ `frontmatter.faq \u4E2D\u5B58\u5728\u7F3A\u5C11 question \u6216 answer \u7684\u6761\u76EE\uFF08JSON.stringify: ${JSON.stringify(entry)}\uFF09\uFF0C\u5DF2\u8DF3\u8FC7\u8BE5\u6761\u76EE`
134
+ );
135
+ return null;
136
+ }
137
+ return {
138
+ "@type": "Question",
139
+ name: question,
140
+ acceptedAnswer: { "@type": "Answer", text: answer }
141
+ };
142
+ }).filter((item) => item !== null);
143
+ if (mainEntity.length === 0) return null;
144
+ return {
145
+ "@context": "https://schema.org",
146
+ "@type": "FAQPage",
147
+ mainEntity
148
+ };
149
+ }
150
+ function buildHomepageSchemas(page, app, base, hostname) {
151
+ const file = page.filePath ?? page.path;
152
+ const siteName = page.title || app.options.title;
153
+ const siteDescription = page.frontmatter.description || app.options.description;
154
+ if (!siteName) {
155
+ warnOnce(file, "\u9996\u9875\u7F3A\u5C11\u7AD9\u70B9\u540D\u79F0\uFF08frontmatter.title \u6216\u7AD9\u70B9 config.title\uFF09\uFF0C\u65E0\u6CD5\u751F\u6210 WebSite schema");
156
+ }
157
+ const website = {
158
+ "@context": "https://schema.org",
159
+ "@type": "WebSite",
160
+ name: siteName || "Untitled Site",
161
+ url: toAbsoluteUrl(base, base, hostname)
162
+ };
163
+ assignIfDefined(website, "description", siteDescription);
164
+ const schemas = [website];
165
+ if (siteName) {
166
+ const organization = {
167
+ "@context": "https://schema.org",
168
+ "@type": "Organization",
169
+ name: siteName,
170
+ url: toAbsoluteUrl(base, base, hostname)
171
+ };
172
+ const logo = page.frontmatter.logo;
173
+ if (typeof logo === "string") {
174
+ assignIfDefined(
175
+ organization,
176
+ "logo",
177
+ resolveImage(logo, base, hostname, file)
178
+ );
179
+ }
180
+ schemas.push(organization);
181
+ }
182
+ return schemas;
183
+ }
184
+ function buildArticleSchema(page, file, base, hostname, options) {
185
+ const fm = page.frontmatter;
186
+ if (!page.title) {
187
+ warnOnce(file, "\u7F3A\u5C11\u5FC5\u586B\u5B57\u6BB5 title\uFF08\u5BF9\u5E94 schema.org \u7684 headline\uFF09\uFF0C\u5DF2\u8DF3\u8FC7\u8BE5\u9875\u9762\u7684\u6587\u7AE0 schema");
188
+ return null;
189
+ }
190
+ const schemaType = options.type || "TechArticle";
191
+ const schema = {
192
+ "@context": "https://schema.org",
193
+ "@type": schemaType,
194
+ headline: page.title,
195
+ // 页面唯一标识,利于搜索引擎去重
196
+ mainEntityOfPage: {
197
+ "@type": "WebPage",
198
+ "@id": toAbsoluteUrl(page.path, base, hostname)
199
+ }
200
+ };
201
+ assignIfDefined(schema, "description", fm.description);
202
+ assignIfDefined(
203
+ schema,
204
+ "datePublished",
205
+ // frontmatter.date 优先;缺失时兜底使用 VuePress 从 git 提取的页面创建日期
206
+ // (无 git 环境时 page.date 为 '0000-00-00' 占位值,需过滤掉)
207
+ toIsoDate(fm.date, file, "date") ?? toIsoDate(
208
+ typeof page.date === "string" && page.date !== "" && page.date !== "0000-00-00" ? page.date : null,
209
+ file,
210
+ "page.date"
211
+ )
212
+ );
213
+ assignIfDefined(
214
+ schema,
215
+ "dateModified",
216
+ toIsoDate(fm.dateModified, file, "dateModified") ?? toIsoDate(fm.date, file, "date")
217
+ );
218
+ assignIfDefined(
219
+ schema,
220
+ "author",
221
+ normalizeAuthors(fm.author, file, "author") ?? normalizeAuthors(options.author, file, "options.author")
222
+ );
223
+ assignIfDefined(
224
+ schema,
225
+ "image",
226
+ resolveImage(fm.image ?? options.image, base, hostname, file)
227
+ );
228
+ const keywords = resolveKeywords(fm.tags);
229
+ if (keywords) schema.keywords = keywords;
230
+ return schema;
231
+ }
232
+ function resolveKeywords(raw) {
233
+ if (raw === void 0 || raw === null || raw === "") return null;
234
+ const list = Array.isArray(raw) ? raw : typeof raw === "string" ? raw.split(",") : [];
235
+ const cleaned = list.map((item) => typeof item === "string" ? item.trim() : "").filter((item) => item !== "");
236
+ return cleaned.length > 0 ? cleaned.join(", ") : null;
237
+ }
238
+ function pushJsonldHead(page, schema) {
239
+ page.frontmatter ??= {};
240
+ const head = page.frontmatter.head ??= [];
241
+ const payload = JSON.stringify(schema);
242
+ const duplicated = head.some(
243
+ (tag) => tag[0] === "script" && tag[1]?.type === "application/ld+json" && tag[2] === payload
244
+ );
245
+ if (!duplicated) {
246
+ head.push(["script", { type: "application/ld+json" }, payload]);
247
+ }
248
+ }
249
+ function jsonldPlugin(options = {}) {
250
+ if (options.hostname !== void 0 && !isHttpsUrl(trimSlash(options.hostname))) {
251
+ console.warn(
252
+ `[${PLUGIN_NAME}] \u8B66\u544A\uFF1A\u914D\u7F6E\u9879 hostname \u5E94\u4E3A https:// \u5F00\u5934\u7684\u4E0D\u5E26\u8DEF\u5F84\u57DF\u540D\uFF08\u5982 'https://example.com'\uFF09\uFF0C\u5F53\u524D\u503C\u4E3A "${options.hostname}"\uFF0C\u76F8\u5BF9\u8DEF\u5F84\u56FE\u7247\u5C06\u65E0\u6CD5\u6B63\u786E\u8865\u5168`
253
+ );
254
+ }
255
+ if (options.type !== void 0 && (typeof options.type !== "string" || options.type === "")) {
256
+ console.warn(
257
+ `[${PLUGIN_NAME}] \u8B66\u544A\uFF1A\u914D\u7F6E\u9879 type \u5E94\u4E3A\u975E\u7A7A\u5B57\u7B26\u4E32\u7684 schema.org \u7C7B\u578B\u540D\uFF08\u5982 'Article'\uFF09\uFF0C\u5F53\u524D\u503C\u5DF2\u5FFD\u7565\uFF0C\u5C06\u4F7F\u7528\u9ED8\u8BA4\u7684 TechArticle`
258
+ );
259
+ }
260
+ return {
261
+ name: PLUGIN_NAME,
262
+ /**
263
+ * extendsPage 在每个页面编译时逐页调用。
264
+ * 在这里往 page.frontmatter.head 追加 <script type="application/ld+json">,
265
+ * VuePress SSR 会把它渲染进首屏 HTML,无需任何客户端脚本。
266
+ *
267
+ * 注意:此阶段 app.pages 尚未收集完成,所以依赖全站页面的
268
+ * BreadcrumbList 延后到 onPrepared 钩子注入。
269
+ */
270
+ extendsPage(page, app) {
271
+ page.frontmatter ??= {};
272
+ const file = page.filePath ?? page.path;
273
+ if (page.frontmatter.jsonld === false) return;
274
+ const base = app.options.base ?? "/";
275
+ const hostname = options.hostname ? trimSlash(options.hostname) : "";
276
+ const schemas = [];
277
+ if (isHomePage(page, base)) {
278
+ schemas.push(...buildHomepageSchemas(page, app, base, hostname));
279
+ } else {
280
+ const article = buildArticleSchema(page, file, base, hostname, options);
281
+ if (article) schemas.push(article);
282
+ }
283
+ const faqPage = buildFaqPage(page, file);
284
+ if (faqPage) schemas.push(faqPage);
285
+ if (typeof options.additionalSchemas === "function") {
286
+ schemas.push(...options.additionalSchemas(page, app));
287
+ } else if (Array.isArray(options.additionalSchemas)) {
288
+ schemas.push(...options.additionalSchemas);
289
+ }
290
+ for (const schema of schemas) {
291
+ pushJsonldHead(page, schema);
292
+ }
293
+ },
294
+ /**
295
+ * onPrepared 在全部页面收集完成后调用一次。
296
+ * 此时 app.pages 可用,可以为存在目录层级的页面生成 BreadcrumbList。
297
+ */
298
+ onPrepared(app) {
299
+ const base = app.options.base ?? "/";
300
+ const hostname = options.hostname ? trimSlash(options.hostname) : "";
301
+ const pages = app.pages ?? [];
302
+ for (const page of pages) {
303
+ if (page.frontmatter?.jsonld === false) continue;
304
+ const breadcrumb = buildBreadcrumb(page, app, pages, base, hostname);
305
+ if (!breadcrumb) continue;
306
+ pushJsonldHead(page, breadcrumb);
307
+ }
308
+ }
309
+ };
310
+ }
311
+ var index_default = jsonldPlugin;
312
+ export {
313
+ index_default as default,
314
+ jsonldPlugin
315
+ };
316
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts"],"sourcesContent":["/**\n * Copyright 2026 科技酱 (TechSauce)\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/**\n * vuepress-plugin-jsonld\n *\n * VuePress 2 插件:构建时(SSR 阶段)向每个页面的 head 注入符合\n * schema.org 规范的 JSON-LD 结构化数据。\n *\n * 作者:科技酱 (TechSauce) https://docs.asoe.cn\n * 核心行为:\n * 1. 通过 extendsPage 钩子读取页面 frontmatter:\n * title / description / date / dateModified / author / image / tags\n * 2. 自动判断 schema 类型:\n * - 首页(frontmatter.home === true 或站点根路径)→ WebSite + Organization\n * - 普通文章 → TechArticle(可通过 options.type 覆盖)\n * - 存在父级目录页(与主题侧边栏一致的层级结构)→ 额外生成 BreadcrumbList\n * - frontmatter.faq → 额外生成 FAQPage\n * 3. 日期自动转为 ISO 8601;image 自动补全为基于站点 base 的 HTTPS 绝对 URL;\n * 缺失字段直接跳过该属性,绝不输出空值。\n * 4. 通过页面 head 配置注入 <script type=\"application/ld+json\"> —— 这是 SSR\n * 静态标签,首屏 HTML 直接携带,不依赖任何客户端动态插入;\n * 相同内容自动去重,不会因钩子多次触发而重复注入。\n * 5. 构建时校验:图片非绝对 HTTPS、日期非法、必填字段缺失时输出清晰的\n * 中文警告,并指出具体文件路径。\n */\nimport type { App, Page, Plugin } from 'vuepress/core'\nimport type {\n AuthorItem,\n AuthorInput,\n JsonldFrontmatter,\n JsonldPage,\n JsonldPluginOptions,\n SchemaNode,\n} from './types'\n\nexport type {\n AuthorInput,\n JsonldFrontmatter,\n JsonldPluginOptions,\n SchemaNode,\n} from './types'\n\n/** 插件名,也是所有警告的日志前缀 */\nconst PLUGIN_NAME = 'vuepress-plugin-jsonld'\n\n/** 已警告过的「文件 + 消息」集合,避免构建时同一问题重复刷屏 */\nconst warned = new Set<string>()\n\n/** 输出中文警告并附带具体文件路径(同一文件的同一问题只警告一次) */\nfunction warnOnce(file: string, message: string): void {\n const key = `${file}#${message}`\n if (warned.has(key)) return\n warned.add(key)\n console.warn(`[${PLUGIN_NAME}] 警告:${message}\\n[${PLUGIN_NAME}] 文件:${file}`)\n}\n\n/** 是否为 https:// 开头的绝对 URL */\nfunction isHttpsUrl(value: string): boolean {\n return /^https:\\/\\/[^\\s]+$/i.test(value)\n}\n\n/** 去掉末尾斜杠 */\nfunction trimSlash(value: string): string {\n return value.replace(/\\/+$/, '')\n}\n\n/**\n * 把任意日期输入(Date / ISO 字符串 / 时间戳)转为 ISO 8601 字符串。\n * 输入为空返回 null(上层直接跳过该属性);非法格式打印警告。\n */\nfunction toIsoDate(raw: unknown, file: string, field: string): string | null {\n if (raw === undefined || raw === null || raw === '') return null\n const date = raw instanceof Date ? raw : new Date(raw as string | number)\n if (Number.isNaN(date.getTime())) {\n warnOnce(\n file,\n `日期字段「${field}」的值 \"${String(raw)}\" 格式非法,无法解析为日期,已跳过该属性;请使用 ISO 8601 格式(如 2024-01-01T08:00:00+08:00)`,\n )\n return null\n }\n return date.toISOString()\n}\n\n/**\n * 图片地址解析:\n * - 已是 https:// 绝对 URL → 原样使用(http:// 触发警告,仍使用但不安全)\n * - 以 / 开头的站点内路径 → hostname + base + 路径 补全为绝对 URL\n * - 其他相对路径 → 同上按站点内路径处理\n * - 未配置 hostname 时打印警告并返回 null(跳过 image 属性)\n */\nfunction resolveImage(\n raw: string | undefined,\n base: string,\n hostname: string,\n file: string,\n): string | null {\n const value = (raw ?? '').trim()\n if (value === '') return null\n\n if (/^https?:\\/\\//i.test(value)) {\n if (!/^https:\\/\\//i.test(value)) {\n warnOnce(\n file,\n `图片地址 \"${value}\" 不是 HTTPS 协议,schema.org 建议(Google 要求)使用 https:// 绝对 URL`,\n )\n }\n return value\n }\n\n if (!hostname) {\n warnOnce(\n file,\n `图片地址 \"${value}\" 是相对路径,但插件未配置 hostname,无法补全为 HTTPS 绝对 URL,已跳过 image 属性;请在插件配置中添加 hostname(如 'https://example.com'),或直接使用 https:// 开头的绝对 URL`,\n )\n return null\n }\n\n // 站点内路径统一为:hostname + base + 去掉开头斜杠的路径\n return `${hostname}${trimSlash(base)}/${value.replace(/^\\/+/, '')}`\n}\n\n/** 把站点内路径补全为绝对 URL;没有 hostname 时保留原路径 */\nfunction toAbsoluteUrl(path: string, base: string, hostname: string): string {\n if (!hostname) return path\n const cleanPath = path.startsWith(base) ? path : `${trimSlash(base)}${path}`\n return `${hostname}${cleanPath.startsWith('/') ? cleanPath : `/${cleanPath}`}`\n}\n\n/** 规范化单个作者条目为 schema.org 节点;无法识别时警告并返回 null */\nfunction normalizeAuthorItem(raw: AuthorItem, file: string, field: string): SchemaNode | null {\n // 字符串:'张三' → Person 节点\n if (typeof raw === 'string') {\n return raw === '' ? null : { '@type': 'Person', name: raw }\n }\n // 对象:{ name, url?, '@type'? }\n if (typeof raw === 'object' && raw !== null && typeof raw.name === 'string' && raw.name !== '') {\n const node: SchemaNode = { '@type': raw['@type'] ?? 'Person', name: raw.name }\n if (raw.url) node.url = raw.url\n return node\n }\n warnOnce(file, `字段「${field}」存在无法识别的作者条目(应为字符串或含 name 的对象),该条目已跳过`)\n return null\n}\n\n/**\n * 规范化作者:支持单条或数组输入,统一为 schema.org 节点。\n * - 单条 → 输出单个 Person / Organization 对象\n * - 数组 → 输出节点数组(schema.org 支持 author 为数组)\n * 全部无法识别时返回 null(上层跳过 author 属性)\n */\nfunction normalizeAuthors(\n raw: AuthorInput | undefined,\n file: string,\n field: string,\n): SchemaNode | SchemaNode[] | null {\n if (raw === undefined || raw === null || raw === '') return null\n\n const list = Array.isArray(raw) ? raw : [raw]\n const nodes = list\n .map((item) => normalizeAuthorItem(item, file, field))\n .filter((item): item is SchemaNode => item !== null)\n\n if (nodes.length === 0) return null\n return nodes.length === 1 ? nodes[0] : nodes\n}\n\n/** 把「存在才写入」的属性合并进 schema,缺失字段直接跳过,不输出空值 */\nfunction assignIfDefined(node: SchemaNode, key: string, value: unknown): void {\n if (value === undefined || value === null || value === '') return\n node[key] = value\n}\n\n/** 判断是否为站点首页 */\nfunction isHomePage(page: JsonldPage, base: string): boolean {\n return page.frontmatter.home === true || page.path === base || page.path === '/'\n}\n\n/**\n * 判断页面是否存在侧边栏式目录层级(即处于某个父级目录之下),\n * 并基于父级目录的索引页生成 BreadcrumbList。\n *\n * 约定:每个目录层级通过其 index 页面(如 /guide/ → /guide/index.html)命名,\n * 这与 VuePress 主题默认侧边栏的目录结构一致。\n */\nfunction buildBreadcrumb(\n page: JsonldPage,\n app: App,\n pages: Page[],\n base: string,\n hostname: string,\n): SchemaNode | null {\n // 路径异常(空字符串等)直接跳过\n if (typeof page.path !== 'string' || page.path === '') return null\n // 取页面路径的目录部分,如 /guide/setup.html → /guide/\n // 注意:不同 VuePress 版本中 page.path 可能带或不带 base 前缀,这里做兼容\n const dirPath = page.path.slice(0, page.path.lastIndexOf('/') + 1)\n const relativeDir = dirPath.startsWith(base) ? dirPath.slice(base.length) : dirPath\n const segments = relativeDir.split('/').filter(Boolean)\n // 无层级(根下直接一层且无父目录页)不生成\n if (segments.length === 0) return null\n\n const siteName = app.options.title || page.title\n if (!siteName) return null\n\n const items: SchemaNode[] = [\n {\n '@type': 'ListItem',\n position: 1,\n name: siteName,\n item: toAbsoluteUrl(base, base, hostname),\n },\n ]\n\n // 逐级匹配父级目录页,匹配到的才加入面包屑\n // 兼容三种目录索引页路径形态:/guide/、/blog/guide/(带 base)、/guide/index.html\n let acc = ''\n for (const segment of segments) {\n acc += `${segment}/`\n const parentPath = `/${acc}`\n const parent = pages.find(\n (p) =>\n p.path === parentPath ||\n p.path === `${base}${acc}` ||\n p.path === `${parentPath}index.html` ||\n p.path === `${base}${acc}index.html`,\n )\n if (!parent) continue\n items.push({\n '@type': 'ListItem',\n position: items.length + 1,\n name: parent.title || segment,\n item: toAbsoluteUrl(parent.path, base, hostname),\n })\n }\n\n // 当前页面本身\n items.push({\n '@type': 'ListItem',\n position: items.length + 1,\n name: page.title || page.path,\n item: toAbsoluteUrl(page.path, base, hostname),\n })\n\n return {\n '@context': 'https://schema.org',\n '@type': 'BreadcrumbList',\n itemListElement: items,\n }\n}\n\n/** 基于 frontmatter.faq 生成 FAQPage schema */\nfunction buildFaqPage(page: JsonldPage, file: string): SchemaNode | null {\n const faq = page.frontmatter.faq\n if (!Array.isArray(faq) || faq.length === 0) return null\n\n const mainEntity = faq\n .map((entry): SchemaNode | null => {\n // 兼容 question/q 与 answer/a 两种字段命名\n const question = entry.question ?? entry.q\n const answer = entry.answer ?? entry.a\n if (!question || !answer) {\n warnOnce(\n file,\n `frontmatter.faq 中存在缺少 question 或 answer 的条目(JSON.stringify: ${JSON.stringify(entry)}),已跳过该条目`,\n )\n return null\n }\n return {\n '@type': 'Question',\n name: question,\n acceptedAnswer: { '@type': 'Answer', text: answer },\n }\n })\n .filter((item): item is SchemaNode => item !== null)\n\n if (mainEntity.length === 0) return null\n\n return {\n '@context': 'https://schema.org',\n '@type': 'FAQPage',\n mainEntity,\n }\n}\n\n/** 生成首页的 WebSite + Organization schema */\nfunction buildHomepageSchemas(\n page: JsonldPage,\n app: App,\n base: string,\n hostname: string,\n): SchemaNode[] {\n const file = page.filePath ?? page.path\n const siteName = page.title || app.options.title\n const siteDescription = page.frontmatter.description || app.options.description\n\n // WebSite 必填字段:name\n if (!siteName) {\n warnOnce(file, '首页缺少站点名称(frontmatter.title 或站点 config.title),无法生成 WebSite schema')\n }\n\n const website: SchemaNode = {\n '@context': 'https://schema.org',\n '@type': 'WebSite',\n name: siteName || 'Untitled Site',\n url: toAbsoluteUrl(base, base, hostname),\n }\n assignIfDefined(website, 'description', siteDescription)\n\n // Organization:有站点名才生成,避免输出空壳\n const schemas: SchemaNode[] = [website]\n if (siteName) {\n const organization: SchemaNode = {\n '@context': 'https://schema.org',\n '@type': 'Organization',\n name: siteName,\n url: toAbsoluteUrl(base, base, hostname),\n }\n // 首页若声明了 logo(frontmatter.logo),输出为 Organization.logo\n const logo = page.frontmatter.logo\n if (typeof logo === 'string') {\n assignIfDefined(\n organization,\n 'logo',\n resolveImage(logo, base, hostname, file),\n )\n }\n schemas.push(organization)\n }\n\n return schemas\n}\n\n/** 生成文章页的 TechArticle(或 options.type 覆盖的类型)schema */\nfunction buildArticleSchema(\n page: JsonldPage,\n file: string,\n base: string,\n hostname: string,\n options: JsonldPluginOptions,\n): SchemaNode | null {\n const fm = page.frontmatter\n\n // 必填字段校验:headline(页面标题)\n if (!page.title) {\n warnOnce(file, '缺少必填字段 title(对应 schema.org 的 headline),已跳过该页面的文章 schema')\n return null\n }\n\n const schemaType = options.type || 'TechArticle'\n const schema: SchemaNode = {\n '@context': 'https://schema.org',\n '@type': schemaType,\n headline: page.title,\n // 页面唯一标识,利于搜索引擎去重\n mainEntityOfPage: {\n '@type': 'WebPage',\n '@id': toAbsoluteUrl(page.path, base, hostname),\n },\n }\n\n // 存在才写入的属性:缺失字段直接跳过\n assignIfDefined(schema, 'description', fm.description)\n assignIfDefined(\n schema,\n 'datePublished',\n // frontmatter.date 优先;缺失时兜底使用 VuePress 从 git 提取的页面创建日期\n // (无 git 环境时 page.date 为 '0000-00-00' 占位值,需过滤掉)\n toIsoDate(fm.date, file, 'date') ??\n toIsoDate(\n typeof page.date === 'string' && page.date !== '' && page.date !== '0000-00-00'\n ? page.date\n : null,\n file,\n 'page.date',\n ),\n )\n assignIfDefined(\n schema,\n 'dateModified',\n toIsoDate(fm.dateModified, file, 'dateModified') ??\n toIsoDate(fm.date, file, 'date'),\n )\n assignIfDefined(\n schema,\n 'author',\n normalizeAuthors(fm.author, file, 'author') ??\n normalizeAuthors(options.author, file, 'options.author'),\n )\n assignIfDefined(\n schema,\n 'image',\n resolveImage(fm.image ?? options.image, base, hostname, file),\n )\n // tags → keywords(逗号分隔,符合 schema.org Text 规范)\n const keywords = resolveKeywords(fm.tags)\n if (keywords) schema.keywords = keywords\n\n return schema\n}\n\n/** tags → keywords:支持字符串数组或逗号分隔字符串;无效输入返回 null */\nfunction resolveKeywords(raw: JsonldFrontmatter['tags']): string | null {\n if (raw === undefined || raw === null || raw === '') return null\n const list = Array.isArray(raw)\n ? raw\n : typeof raw === 'string'\n ? raw.split(',')\n : []\n const cleaned = list\n .map((item) => (typeof item === 'string' ? item.trim() : ''))\n .filter((item) => item !== '')\n return cleaned.length > 0 ? cleaned.join(', ') : null\n}\n\n/**\n * 向页面 head 配置注入 ld+json 标签。\n * 相同内容自动去重,避免热更新 / 钩子多次触发导致的重复注入;\n * 用户自己在 frontmatter.head 中声明的 ld+json 不受影响。\n */\nfunction pushJsonldHead(page: JsonldPage, schema: SchemaNode): void {\n page.frontmatter ??= {}\n const head = (page.frontmatter.head ??= [])\n const payload = JSON.stringify(schema)\n const duplicated = head.some(\n (tag) =>\n tag[0] === 'script' &&\n (tag[1] as { type?: string } | undefined)?.type === 'application/ld+json' &&\n tag[2] === payload,\n )\n if (!duplicated) {\n head.push(['script', { type: 'application/ld+json' }, payload])\n }\n}\n\n/** 插件工厂:返回 VuePress 2 插件对象 */\nexport function jsonldPlugin(options: JsonldPluginOptions = {}): Plugin {\n // 配置项预校验:在插件注册阶段尽早发现配置错误\n if (options.hostname !== undefined && !isHttpsUrl(trimSlash(options.hostname))) {\n console.warn(\n `[${PLUGIN_NAME}] 警告:配置项 hostname 应为 https:// 开头的不带路径域名(如 'https://example.com'),当前值为 \"${options.hostname}\",相对路径图片将无法正确补全`,\n )\n }\n if (options.type !== undefined && (typeof options.type !== 'string' || options.type === '')) {\n console.warn(\n `[${PLUGIN_NAME}] 警告:配置项 type 应为非空字符串的 schema.org 类型名(如 'Article'),当前值已忽略,将使用默认的 TechArticle`,\n )\n }\n\n return {\n name: PLUGIN_NAME,\n\n /**\n * extendsPage 在每个页面编译时逐页调用。\n * 在这里往 page.frontmatter.head 追加 <script type=\"application/ld+json\">,\n * VuePress SSR 会把它渲染进首屏 HTML,无需任何客户端脚本。\n *\n * 注意:此阶段 app.pages 尚未收集完成,所以依赖全站页面的\n * BreadcrumbList 延后到 onPrepared 钩子注入。\n */\n extendsPage(page, app) {\n // frontmatter 极端情况下可能为空(虚拟页面等),兜底为空对象\n page.frontmatter ??= {}\n const file = page.filePath ?? page.path\n\n // 允许页面通过 frontmatter.jsonld: false 完全关闭注入\n if (page.frontmatter.jsonld === false) return\n\n const base = app.options.base ?? '/'\n const hostname = options.hostname ? trimSlash(options.hostname) : ''\n\n const schemas: SchemaNode[] = []\n\n // 1) 首页 → WebSite + Organization;2) 其他页面 → 文章 schema\n if (isHomePage(page, base)) {\n schemas.push(...buildHomepageSchemas(page, app, base, hostname))\n } else {\n const article = buildArticleSchema(page, file, base, hostname, options)\n if (article) schemas.push(article)\n }\n\n // 2) 识别到 FAQ 结构 → 额外生成 FAQPage\n const faqPage = buildFaqPage(page, file)\n if (faqPage) schemas.push(faqPage)\n\n // 3) 追加 additionalSchemas(静态数组或动态函数)\n if (typeof options.additionalSchemas === 'function') {\n schemas.push(...options.additionalSchemas(page, app))\n } else if (Array.isArray(options.additionalSchemas)) {\n schemas.push(...options.additionalSchemas)\n }\n\n // 注入 head:通过 frontmatter.head(VuePress 的 head 配置机制)追加\n // <script type=\"application/ld+json\">{...}</script>,\n // SSR 渲染时会静态写入首屏 HTML,不依赖客户端动态插入\n for (const schema of schemas) {\n pushJsonldHead(page, schema)\n }\n },\n\n /**\n * onPrepared 在全部页面收集完成后调用一次。\n * 此时 app.pages 可用,可以为存在目录层级的页面生成 BreadcrumbList。\n */\n onPrepared(app) {\n const base = app.options.base ?? '/'\n const hostname = options.hostname ? trimSlash(options.hostname) : ''\n const pages = app.pages ?? []\n\n for (const page of pages) {\n // 尊重页面级开关(可选链防御 frontmatter 缺失)\n if (page.frontmatter?.jsonld === false) continue\n\n const breadcrumb = buildBreadcrumb(page, app, pages, base, hostname)\n if (!breadcrumb) continue\n\n pushJsonldHead(page, breadcrumb)\n }\n },\n }\n}\n\nexport default jsonldPlugin\n"],"mappings":";AAyDA,IAAM,cAAc;AAGpB,IAAM,SAAS,oBAAI,IAAY;AAG/B,SAAS,SAAS,MAAc,SAAuB;AACrD,QAAM,MAAM,GAAG,IAAI,IAAI,OAAO;AAC9B,MAAI,OAAO,IAAI,GAAG,EAAG;AACrB,SAAO,IAAI,GAAG;AACd,UAAQ,KAAK,IAAI,WAAW,uBAAQ,OAAO;AAAA,GAAM,WAAW,uBAAQ,IAAI,EAAE;AAC5E;AAGA,SAAS,WAAW,OAAwB;AAC1C,SAAO,sBAAsB,KAAK,KAAK;AACzC;AAGA,SAAS,UAAU,OAAuB;AACxC,SAAO,MAAM,QAAQ,QAA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AA,MACjE,OAAO;AACL,cAAM,UAAU,mBAAmB,MAAM,MAAM,MAAM,UAAU,OAAO;AACtE,YAAI,QAAS,SAAQ,KAAK,OAAO;AAAA,MACnC;AAGA,YAAM,UAAU,aAAa,MAAM,IAAI;AACvC,UAAI,QAAS,SAAQ,KAAK,OAAO;AAGjC,UAAI,OAAO,QAAQ,sBAAsB,YAAY;AACnD,gBAAQ,KAAK,GAAG,QAAQ,kBAAkB,MAAM,GAAG,CAAC;AAAA,MACtD,WAAW,MAAM,QAAQ,QAAQ,iBAAiB,GAAG;AACnD,gBAAQ,KAAK,GAAG,QAAQ,iBAAiB;AAAA,MAC3C;AAKA,iBAAW,UAAU,SAAS;AAC5B,uBAAe,MAAM,MAAM;AAAA,MAC7B;AAAA,IACF;AAAA;AAAA;AAAA;AAAA;AAAA,IAMA,WAAW,KAAK;AACd,YAAM,OAAO,IAAI,QAAQ,QAAQ;AACjC,YAAM,WAAW,QAAQ,WAAW,UAAU,QAAQ,QAAQ,IAAI;AAClE,YAAM,QAAQ,IAAI,SAAS,CAAC;AAE5B,iBAAW,QAAQ,OAAO;AAExB,YAAI,KAAK,aAAa,WAAW,MAAO;AAExC,cAAM,aAAa,gBAAgB,MAAM,KAAK,OAAO,MAAM,QAAQ;AACnE,YAAI,CAAC,WAAY;AAEjB,uBAAe,MAAM,UAAU;AAAA,MACjC;AAAA,IACF;AAAA,EACF;AACF;AAEA,IAAO,gBAAQ;","names":[]}
package/package.json CHANGED
@@ -1,6 +1,68 @@
1
1
  {
2
2
  "name": "@techjiang/vuepress-plugin-jsonld",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "1.1.0",
4
+ "description": "VuePress 2 插件:构建时向每个页面的 head 注入符合 schema.org 规范的 JSON-LD 结构化数据(TechArticle / WebSite / Organization / BreadcrumbList / FAQPage),SSR 首屏静态输出",
5
+ "type": "module",
6
+ "keywords": [
7
+ "vuepress",
8
+ "vuepress2",
9
+ "vuepress-plugin",
10
+ "json-ld",
11
+ "jsonld",
12
+ "seo",
13
+ "schema.org",
14
+ "structured-data"
15
+ ],
16
+ "license": "Apache-2.0",
17
+ "author": "科技酱 TechSauce <official@tech.asoe.cn> (https://github.com/techjiang)",
18
+ "homepage": "https://docs.asoe.cn",
19
+ "repository": {
20
+ "type": "git",
21
+ "url": "git+https://github.com/techjiang/vuepress-plugin-jsonld.git"
22
+ },
23
+ "bugs": {
24
+ "url": "https://github.com/techjiang/vuepress-plugin-jsonld/issues"
25
+ },
26
+ "main": "./lib/index.js",
27
+ "module": "./lib/index.js",
28
+ "types": "./lib/index.d.ts",
29
+ "exports": {
30
+ ".": {
31
+ "types": "./lib/index.d.ts",
32
+ "import": "./lib/index.js"
33
+ },
34
+ "./package.json": "./package.json"
35
+ },
36
+ "files": [
37
+ "lib",
38
+ "README.md",
39
+ "LICENSE",
40
+ "CHANGELOG.md"
41
+ ],
42
+ "publishConfig": {
43
+ "access": "public"
44
+ },
45
+ "scripts": {
46
+ "build": "tsup",
47
+ "dev": "tsup --watch",
48
+ "test": "node tests/run.mjs",
49
+ "prepublishOnly": "npm run build && npm test",
50
+ "demo:dev": "vuepress dev demo",
51
+ "demo:build": "vuepress build demo"
52
+ },
53
+ "peerDependencies": {
54
+ "vuepress": ">=2.0.0-rc.0"
55
+ },
56
+ "devDependencies": {
57
+ "@types/node": "^22.10.1",
58
+ "@vuepress/bundler-vite": "^2.0.0-rc.33",
59
+ "@vuepress/theme-default": "^2.0.0-rc.142",
60
+ "tsup": "^8.3.5",
61
+ "typescript": "^5.7.2",
62
+ "vite": "^5.4.21",
63
+ "vuepress": "^2.0.0-rc.33"
64
+ },
65
+ "engines": {
66
+ "node": ">=18"
67
+ }
68
+ }