duqing2026 commited on
Commit
eb9bbc6
·
0 Parent(s):

Initial commit

Browse files
Files changed (4) hide show
  1. Dockerfile +11 -0
  2. README.md +39 -0
  3. app.py +15 -0
  4. templates/index.html +531 -0
Dockerfile ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM python:3.9-slim
2
+
3
+ WORKDIR /app
4
+
5
+ COPY . /app
6
+
7
+ RUN pip install flask
8
+
9
+ EXPOSE 7860
10
+
11
+ CMD ["python", "app.py"]
README.md ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ title: SEO 结构化数据工坊
3
+ emoji: 🔍
4
+ colorFrom: blue
5
+ colorTo: indigo
6
+ sdk: docker
7
+ app_port: 7860
8
+ short_description: 专业的 JSON-LD 结构化数据生成工具,助力网站 SEO 排名。
9
+ ---
10
+
11
+ # SEO 结构化数据工坊 (SEO Schema Studio)
12
+
13
+ 这是一个简单而强大的工具,帮助站长、SEO 专员和开发者快速生成符合 Google 标准的 JSON-LD 结构化数据(Schema Markup)。
14
+
15
+ ## 功能特点
16
+
17
+ - **多类型支持**:支持文章(Article)、产品(Product)、常见问题(FAQPage)、面包屑(BreadcrumbList)、活动(Event)等核心 Schema 类型。
18
+ - **可视化编辑**:无需编写代码,通过直观的表单输入信息。
19
+ - **实时预览**:输入时实时生成 JSON-LD 代码。
20
+ - **一键复制**:快速复制生成的代码到剪贴板。
21
+ - **验证链接**:提供 Google Rich Results Test 验证入口。
22
+ - **完全本地化**:中文界面,贴合国内用户习惯。
23
+
24
+ ## 如何使用
25
+
26
+ 1. 选择左侧的 Schema 类型。
27
+ 2. 在表单中填写相应的信息(如标题、日期、价格等)。
28
+ 3. 右侧会自动生成 JSON-LD 代码。
29
+ 4. 点击“复制”按钮,将代码粘贴到您网站的 HTML `<head>` 或 `<body>` 部分。
30
+
31
+ ## 技术栈
32
+
33
+ - **Backend**: Flask (Python)
34
+ - **Frontend**: Vue 3, Tailwind CSS
35
+ - **Deployment**: Docker, Hugging Face Spaces
36
+
37
+ ## 许可证
38
+
39
+ MIT License
app.py ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from flask import Flask, render_template, send_from_directory
2
+ import os
3
+
4
+ app = Flask(__name__)
5
+
6
+ @app.route('/')
7
+ def index():
8
+ return render_template('index.html')
9
+
10
+ @app.route('/static/<path:path>')
11
+ def send_static(path):
12
+ return send_from_directory('static', path)
13
+
14
+ if __name__ == '__main__':
15
+ app.run(host='0.0.0.0', port=7860)
templates/index.html ADDED
@@ -0,0 +1,531 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!DOCTYPE html>
2
+ <html lang="zh-CN">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>SEO 结构化数据工坊 (Schema Studio)</title>
7
+ <script src="https://unpkg.com/vue@3/dist/vue.global.js"></script>
8
+ <script src="https://cdn.tailwindcss.com"></script>
9
+ <link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css" rel="stylesheet">
10
+ <style>
11
+ @import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');
12
+ body { font-family: 'Inter', sans-serif; }
13
+ .code-preview { font-family: 'Menlo', 'Monaco', 'Courier New', monospace; }
14
+ /* Custom scrollbar */
15
+ ::-webkit-scrollbar { width: 8px; height: 8px; }
16
+ ::-webkit-scrollbar-track { background: #f1f1f1; }
17
+ ::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 4px; }
18
+ ::-webkit-scrollbar-thumb:hover { background: #94a3b8; }
19
+ </style>
20
+ <script>
21
+ tailwind.config = {
22
+ theme: {
23
+ extend: {
24
+ colors: {
25
+ brand: {
26
+ 50: '#f0f9ff',
27
+ 100: '#e0f2fe',
28
+ 500: '#0ea5e9',
29
+ 600: '#0284c7',
30
+ 700: '#0369a1',
31
+ }
32
+ }
33
+ }
34
+ }
35
+ }
36
+ </script>
37
+ </head>
38
+ <body class="bg-slate-50 text-slate-800 min-h-screen flex flex-col">
39
+ {% raw %}
40
+ <div id="app" class="flex-grow flex flex-col">
41
+ <!-- Navbar -->
42
+ <nav class="bg-white border-b border-slate-200 sticky top-0 z-50">
43
+ <div class="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8">
44
+ <div class="flex justify-between h-16">
45
+ <div class="flex items-center gap-3">
46
+ <div class="bg-brand-500 text-white w-8 h-8 rounded-lg flex items-center justify-center font-bold text-lg">
47
+ <i class="fa-solid fa-code"></i>
48
+ </div>
49
+ <span class="font-bold text-xl tracking-tight">SEO 结构化数据工坊</span>
50
+ </div>
51
+ <div class="flex items-center gap-4">
52
+ <a href="https://github.com/duqing2026" target="_blank" class="text-slate-500 hover:text-brand-600 transition">
53
+ <i class="fa-brands fa-github text-xl"></i>
54
+ </a>
55
+ </div>
56
+ </div>
57
+ </div>
58
+ </nav>
59
+
60
+ <!-- Main Content -->
61
+ <main class="flex-grow max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 py-8 w-full">
62
+
63
+ <div class="grid grid-cols-1 lg:grid-cols-12 gap-8">
64
+
65
+ <!-- Sidebar / Selector -->
66
+ <div class="lg:col-span-3 space-y-6">
67
+ <div class="bg-white rounded-xl shadow-sm border border-slate-200 overflow-hidden">
68
+ <div class="p-4 bg-slate-50 border-b border-slate-200 font-semibold text-slate-700">
69
+ 选择 Schema 类型
70
+ </div>
71
+ <div class="p-2 space-y-1">
72
+ <button v-for="type in schemaTypes" :key="type.id"
73
+ @click="currentType = type.id"
74
+ :class="['w-full text-left px-4 py-3 rounded-lg flex items-center gap-3 transition-colors',
75
+ currentType === type.id ? 'bg-brand-50 text-brand-700 font-medium' : 'hover:bg-slate-50 text-slate-600']">
76
+ <i :class="['fa-fw', type.icon]"></i>
77
+ {{ type.name }}
78
+ </button>
79
+ </div>
80
+ </div>
81
+
82
+ <div class="bg-gradient-to-br from-brand-500 to-indigo-600 rounded-xl p-6 text-white shadow-lg">
83
+ <h3 class="font-bold text-lg mb-2">为什么需要 Schema?</h3>
84
+ <p class="text-brand-100 text-sm leading-relaxed">
85
+ Schema 标记(JSON-LD)帮助搜索引擎更好地理解您的内容,从而在搜索结果中展示富媒体摘要(如星级评分、价格、FAQ),显著提高点击率(CTR)。
86
+ </p>
87
+ </div>
88
+ </div>
89
+
90
+ <!-- Form Area -->
91
+ <div class="lg:col-span-5 space-y-6">
92
+ <div class="bg-white rounded-xl shadow-sm border border-slate-200">
93
+ <div class="p-6 border-b border-slate-200 flex justify-between items-center">
94
+ <h2 class="text-xl font-bold text-slate-800">
95
+ {{ getSchemaName(currentType) }} 配置
96
+ </h2>
97
+ <button @click="resetForm" class="text-sm text-slate-500 hover:text-red-500 transition">
98
+ <i class="fa-solid fa-rotate-right mr-1"></i> 重置
99
+ </button>
100
+ </div>
101
+
102
+ <div class="p-6 space-y-6">
103
+ <!-- Dynamic Forms -->
104
+
105
+ <!-- Article Form -->
106
+ <div v-if="currentType === 'Article'" class="space-y-4">
107
+ <form-input label="文章标题 (Headline)" v-model="forms.article.headline" placeholder="例如:2024年最值得购买的智能手机"></form-input>
108
+ <form-input label="封面图片 URL" v-model="forms.article.image" placeholder="https://example.com/image.jpg"></form-input>
109
+ <div class="grid grid-cols-2 gap-4">
110
+ <form-input label="作者姓名" v-model="forms.article.authorName" placeholder="张三"></form-input>
111
+ <form-input label="发布组织" v-model="forms.article.publisherName" placeholder="科技日报"></form-input>
112
+ </div>
113
+ <div class="grid grid-cols-2 gap-4">
114
+ <form-input type="date" label="发布日期" v-model="forms.article.datePublished"></form-input>
115
+ <form-input type="date" label="修改日期" v-model="forms.article.dateModified"></form-input>
116
+ </div>
117
+ <form-textarea label="文章摘要" v-model="forms.article.description" placeholder="文章的简短描述..."></form-textarea>
118
+ </div>
119
+
120
+ <!-- Product Form -->
121
+ <div v-if="currentType === 'Product'" class="space-y-4">
122
+ <form-input label="产品名称" v-model="forms.product.name" placeholder="iPhone 15 Pro"></form-input>
123
+ <form-input label="产品图片 URL" v-model="forms.product.image" placeholder="https://..."></form-input>
124
+ <form-textarea label="产品描述" v-model="forms.product.description"></form-textarea>
125
+ <div class="grid grid-cols-2 gap-4">
126
+ <form-input label="品牌" v-model="forms.product.brand" placeholder="Apple"></form-input>
127
+ <form-input label="SKU" v-model="forms.product.sku" placeholder="IP15P-256"></form-input>
128
+ </div>
129
+ <div class="p-4 bg-slate-50 rounded-lg border border-slate-200 space-y-4">
130
+ <h4 class="font-medium text-sm text-slate-500 uppercase tracking-wider">价格信息</h4>
131
+ <div class="grid grid-cols-3 gap-4">
132
+ <form-input label="价格" type="number" v-model="forms.product.price" placeholder="9999"></form-input>
133
+ <form-input label="货币代码" v-model="forms.product.priceCurrency" placeholder="CNY"></form-input>
134
+ <div class="flex flex-col gap-1">
135
+ <label class="block text-sm font-medium text-slate-700">库存状态</label>
136
+ <select v-model="forms.product.availability" class="w-full rounded-lg border-slate-300 shadow-sm focus:border-brand-500 focus:ring-brand-500 py-2.5 px-3 border bg-white">
137
+ <option value="InStock">有货</option>
138
+ <option value="OutOfStock">缺货</option>
139
+ <option value="PreOrder">预售</option>
140
+ </select>
141
+ </div>
142
+ </div>
143
+ </div>
144
+ <div class="p-4 bg-slate-50 rounded-lg border border-slate-200 space-y-4">
145
+ <h4 class="font-medium text-sm text-slate-500 uppercase tracking-wider">评分 (可选)</h4>
146
+ <div class="grid grid-cols-2 gap-4">
147
+ <form-input label="平均评分 (0-5)" type="number" step="0.1" v-model="forms.product.ratingValue" placeholder="4.8"></form-input>
148
+ <form-input label="评论数量" type="number" v-model="forms.product.reviewCount" placeholder="1024"></form-input>
149
+ </div>
150
+ </div>
151
+ </div>
152
+
153
+ <!-- FAQ Form -->
154
+ <div v-if="currentType === 'FAQPage'" class="space-y-4">
155
+ <div v-for="(item, index) in forms.faq.questions" :key="index" class="p-4 bg-slate-50 rounded-lg border border-slate-200 relative group">
156
+ <button @click="removeFaqItem(index)" class="absolute top-2 right-2 text-slate-400 hover:text-red-500 p-1 opacity-0 group-hover:opacity-100 transition">
157
+ <i class="fa-solid fa-trash"></i>
158
+ </button>
159
+ <div class="space-y-3">
160
+ <form-input :label="'问题 #' + (index + 1)" v-model="item.question" placeholder="如何退款?"></form-input>
161
+ <form-textarea label="回答" v-model="item.answer" placeholder="您可以在订单页面点击申请退款..."></form-textarea>
162
+ </div>
163
+ </div>
164
+ <button @click="addFaqItem" class="w-full py-3 border-2 border-dashed border-brand-200 text-brand-600 rounded-lg hover:bg-brand-50 hover:border-brand-300 transition font-medium">
165
+ <i class="fa-solid fa-plus mr-2"></i> 添加问答
166
+ </button>
167
+ </div>
168
+
169
+ <!-- Breadcrumb Form -->
170
+ <div v-if="currentType === 'BreadcrumbList'" class="space-y-4">
171
+ <div v-for="(item, index) in forms.breadcrumb.items" :key="index" class="flex items-end gap-3 p-3 bg-slate-50 rounded-lg border border-slate-200">
172
+ <div class="flex-grow space-y-3">
173
+ <div class="grid grid-cols-2 gap-3">
174
+ <form-input label="名称" v-model="item.name" placeholder="首页"></form-input>
175
+ <form-input label="URL" v-model="item.item" placeholder="https://example.com"></form-input>
176
+ </div>
177
+ </div>
178
+ <button @click="removeBreadcrumbItem(index)" class="mb-3 text-slate-400 hover:text-red-500 p-2" title="删除">
179
+ <i class="fa-solid fa-trash"></i>
180
+ </button>
181
+ </div>
182
+ <button @click="addBreadcrumbItem" class="w-full py-3 border-2 border-dashed border-brand-200 text-brand-600 rounded-lg hover:bg-brand-50 hover:border-brand-300 transition font-medium">
183
+ <i class="fa-solid fa-plus mr-2"></i> 添加层级
184
+ </button>
185
+ </div>
186
+
187
+ <!-- Event Form -->
188
+ <div v-if="currentType === 'Event'" class="space-y-4">
189
+ <form-input label="活动名称" v-model="forms.event.name" placeholder="2024 开发者大会"></form-input>
190
+ <div class="grid grid-cols-2 gap-4">
191
+ <form-input type="datetime-local" label="开始时间" v-model="forms.event.startDate"></form-input>
192
+ <form-input type="datetime-local" label="结束时间" v-model="forms.event.endDate"></form-input>
193
+ </div>
194
+ <div class="p-4 bg-slate-50 rounded-lg border border-slate-200 space-y-4">
195
+ <h4 class="font-medium text-sm text-slate-500 uppercase tracking-wider">地点信息</h4>
196
+ <form-input label="地点名称" v-model="forms.event.locationName" placeholder="国际会展中心"></form-input>
197
+ <form-input label="详细地址" v-model="forms.event.address" placeholder="北京市朝阳区..."></form-input>
198
+ </div>
199
+ <form-input label="活动图片 URL" v-model="forms.event.image" placeholder="https://..."></form-input>
200
+ <form-textarea label="活动描述" v-model="forms.event.description"></form-textarea>
201
+ <div class="p-4 bg-slate-50 rounded-lg border border-slate-200 space-y-4">
202
+ <h4 class="font-medium text-sm text-slate-500 uppercase tracking-wider">票务信息 (可选)</h4>
203
+ <div class="grid grid-cols-2 gap-4">
204
+ <form-input label="价格" type="number" v-model="forms.event.price" placeholder="299"></form-input>
205
+ <form-input label="货币" v-model="forms.event.priceCurrency" placeholder="CNY"></form-input>
206
+ </div>
207
+ <form-input label="购票链接" v-model="forms.event.url" placeholder="https://..."></form-input>
208
+ </div>
209
+ </div>
210
+
211
+ </div>
212
+ </div>
213
+ </div>
214
+
215
+ <!-- Preview Area -->
216
+ <div class="lg:col-span-4 space-y-6">
217
+ <div class="bg-slate-900 rounded-xl shadow-lg overflow-hidden flex flex-col h-[600px] sticky top-24">
218
+ <div class="bg-slate-800 px-4 py-3 flex justify-between items-center border-b border-slate-700">
219
+ <span class="text-slate-300 text-sm font-mono"><i class="fa-solid fa-code mr-2"></i>JSON-LD 预览</span>
220
+ <div class="flex gap-2">
221
+ <button @click="copyCode" class="text-xs bg-slate-700 hover:bg-slate-600 text-white px-3 py-1.5 rounded transition">
222
+ <i class="fa-regular fa-copy mr-1"></i> {{ copyBtnText }}
223
+ </button>
224
+ </div>
225
+ </div>
226
+ <div class="flex-grow p-4 overflow-auto bg-slate-900 custom-scrollbar">
227
+ <pre class="code-preview text-sm text-green-400 whitespace-pre-wrap break-all">{{ generatedJson }}</pre>
228
+ </div>
229
+ <div class="bg-slate-800 p-4 border-t border-slate-700">
230
+ <a :href="googleTestUrl" target="_blank" class="block w-full text-center bg-brand-600 hover:bg-brand-500 text-white font-medium py-3 rounded-lg transition shadow-lg shadow-brand-500/20">
231
+ <i class="fa-brands fa-google mr-2"></i> 在 Google 中验证
232
+ </a>
233
+ <p class="text-slate-500 text-xs text-center mt-2">
234
+ 将代码粘贴到 &lt;head&gt; 或 &lt;body&gt; 标签中
235
+ </p>
236
+ </div>
237
+ </div>
238
+ </div>
239
+ </div>
240
+ </main>
241
+ </div>
242
+
243
+ <!-- Reusable Input Component Template -->
244
+ <template id="form-input-template">
245
+ <div class="flex flex-col gap-1">
246
+ <label v-if="label" class="block text-sm font-medium text-slate-700">{{ label }}</label>
247
+ <input
248
+ :value="modelValue"
249
+ @input="$emit('update:modelValue', $event.target.value)"
250
+ v-bind="$attrs"
251
+ class="w-full rounded-lg border-slate-300 shadow-sm focus:border-brand-500 focus:ring-brand-500 py-2.5 px-3 border transition-colors"
252
+ >
253
+ </div>
254
+ </template>
255
+
256
+ <template id="form-textarea-template">
257
+ <div class="flex flex-col gap-1">
258
+ <label v-if="label" class="block text-sm font-medium text-slate-700">{{ label }}</label>
259
+ <textarea
260
+ :value="modelValue"
261
+ @input="$emit('update:modelValue', $event.target.value)"
262
+ v-bind="$attrs"
263
+ rows="3"
264
+ class="w-full rounded-lg border-slate-300 shadow-sm focus:border-brand-500 focus:ring-brand-500 py-2.5 px-3 border transition-colors"
265
+ ></textarea>
266
+ </div>
267
+ </template>
268
+
269
+ <script>
270
+ const { createApp, ref, computed, reactive } = Vue;
271
+
272
+ // Input Component
273
+ const FormInput = {
274
+ template: '#form-input-template',
275
+ props: ['label', 'modelValue'],
276
+ emits: ['update:modelValue']
277
+ }
278
+
279
+ // Textarea Component
280
+ const FormTextarea = {
281
+ template: '#form-textarea-template',
282
+ props: ['label', 'modelValue'],
283
+ emits: ['update:modelValue']
284
+ }
285
+
286
+ createApp({
287
+ components: {
288
+ 'form-input': FormInput,
289
+ 'form-textarea': FormTextarea
290
+ },
291
+ setup() {
292
+ const currentType = ref('Article');
293
+ const copyBtnText = ref('复制');
294
+
295
+ const schemaTypes = [
296
+ { id: 'Article', name: '文章 (Article)', icon: 'fa-regular fa-newspaper' },
297
+ { id: 'Product', name: '产品 (Product)', icon: 'fa-solid fa-box-open' },
298
+ { id: 'FAQPage', name: '常见问题 (FAQ)', icon: 'fa-solid fa-circle-question' },
299
+ { id: 'BreadcrumbList', name: '面包屑 (Breadcrumb)', icon: 'fa-solid fa-route' },
300
+ { id: 'Event', name: '活动 (Event)', icon: 'fa-regular fa-calendar-days' },
301
+ ];
302
+
303
+ // Form Data States
304
+ const forms = reactive({
305
+ article: {
306
+ headline: '',
307
+ image: '',
308
+ authorName: '',
309
+ publisherName: '',
310
+ datePublished: '',
311
+ dateModified: '',
312
+ description: ''
313
+ },
314
+ product: {
315
+ name: '',
316
+ image: '',
317
+ description: '',
318
+ brand: '',
319
+ sku: '',
320
+ price: '',
321
+ priceCurrency: 'CNY',
322
+ availability: 'InStock',
323
+ ratingValue: '',
324
+ reviewCount: ''
325
+ },
326
+ faq: {
327
+ questions: [
328
+ { question: '', answer: '' }
329
+ ]
330
+ },
331
+ breadcrumb: {
332
+ items: [
333
+ { name: '首页', item: 'https://example.com' },
334
+ { name: '分类', item: 'https://example.com/category' }
335
+ ]
336
+ },
337
+ event: {
338
+ name: '',
339
+ startDate: '',
340
+ endDate: '',
341
+ locationName: '',
342
+ address: '',
343
+ image: '',
344
+ description: '',
345
+ price: '',
346
+ priceCurrency: 'CNY',
347
+ url: ''
348
+ }
349
+ });
350
+
351
+ // Computed JSON Generation
352
+ const generatedJson = computed(() => {
353
+ let schema = {
354
+ "@context": "https://schema.org",
355
+ "@type": currentType.value
356
+ };
357
+
358
+ if (currentType.value === 'Article') {
359
+ const f = forms.article;
360
+ if (f.headline) schema.headline = f.headline;
361
+ if (f.image) schema.image = [f.image];
362
+ if (f.authorName) {
363
+ schema.author = {
364
+ "@type": "Person",
365
+ "name": f.authorName
366
+ };
367
+ }
368
+ if (f.publisherName) {
369
+ schema.publisher = {
370
+ "@type": "Organization",
371
+ "name": f.publisherName
372
+ };
373
+ }
374
+ if (f.datePublished) schema.datePublished = f.datePublished;
375
+ if (f.dateModified) schema.dateModified = f.dateModified;
376
+ if (f.description) schema.description = f.description;
377
+ }
378
+
379
+ else if (currentType.value === 'Product') {
380
+ const f = forms.product;
381
+ if (f.name) schema.name = f.name;
382
+ if (f.image) schema.image = [f.image];
383
+ if (f.description) schema.description = f.description;
384
+ if (f.brand) schema.brand = { "@type": "Brand", "name": f.brand };
385
+ if (f.sku) schema.sku = f.sku;
386
+
387
+ if (f.price) {
388
+ schema.offers = {
389
+ "@type": "Offer",
390
+ "url": "https://example.com/product", // Placeholder
391
+ "priceCurrency": f.priceCurrency,
392
+ "price": f.price,
393
+ "availability": `https://schema.org/${f.availability}`
394
+ };
395
+ }
396
+
397
+ if (f.ratingValue) {
398
+ schema.aggregateRating = {
399
+ "@type": "AggregateRating",
400
+ "ratingValue": f.ratingValue,
401
+ "reviewCount": f.reviewCount || "1"
402
+ };
403
+ }
404
+ }
405
+
406
+ else if (currentType.value === 'FAQPage') {
407
+ schema.mainEntity = forms.faq.questions
408
+ .filter(q => q.question && q.answer)
409
+ .map(q => ({
410
+ "@type": "Question",
411
+ "name": q.question,
412
+ "acceptedAnswer": {
413
+ "@type": "Answer",
414
+ "text": q.answer
415
+ }
416
+ }));
417
+ }
418
+
419
+ else if (currentType.value === 'BreadcrumbList') {
420
+ schema.itemListElement = forms.breadcrumb.items
421
+ .filter(item => item.name && item.item)
422
+ .map((item, index) => ({
423
+ "@type": "ListItem",
424
+ "position": index + 1,
425
+ "name": item.name,
426
+ "item": item.item
427
+ }));
428
+ }
429
+
430
+ else if (currentType.value === 'Event') {
431
+ const f = forms.event;
432
+ if (f.name) schema.name = f.name;
433
+ if (f.startDate) schema.startDate = f.startDate;
434
+ if (f.endDate) schema.endDate = f.endDate;
435
+ if (f.image) schema.image = [f.image];
436
+ if (f.description) schema.description = f.description;
437
+
438
+ if (f.locationName || f.address) {
439
+ schema.location = {
440
+ "@type": "Place",
441
+ "name": f.locationName,
442
+ "address": {
443
+ "@type": "PostalAddress",
444
+ "streetAddress": f.address
445
+ }
446
+ };
447
+ }
448
+
449
+ if (f.price) {
450
+ schema.offers = {
451
+ "@type": "Offer",
452
+ "url": f.url,
453
+ "price": f.price,
454
+ "priceCurrency": f.priceCurrency,
455
+ "availability": "https://schema.org/InStock"
456
+ };
457
+ }
458
+ }
459
+
460
+ return JSON.stringify(schema, null, 2);
461
+ });
462
+
463
+ const googleTestUrl = computed(() => {
464
+ // Google Rich Results Test URL with code snippet (Base64 encoded)
465
+ // Actually Google supports `code` param but it's tricky with length.
466
+ // Better to just link to the test page, but we can't pre-fill it easily via URL GET param for code snippets (only URLs).
467
+ // But there is a hack: `https://search.google.com/test/rich-results?code=...` is deprecated or doesn't work well.
468
+ // Let's just link to the tool.
469
+ return "https://search.google.com/test/rich-results";
470
+ });
471
+
472
+ // Methods
473
+ const getSchemaName = (id) => {
474
+ return schemaTypes.find(t => t.id === id)?.name;
475
+ };
476
+
477
+ const addFaqItem = () => {
478
+ forms.faq.questions.push({ question: '', answer: '' });
479
+ };
480
+
481
+ const removeFaqItem = (index) => {
482
+ if (forms.faq.questions.length > 1) {
483
+ forms.faq.questions.splice(index, 1);
484
+ }
485
+ };
486
+
487
+ const addBreadcrumbItem = () => {
488
+ forms.breadcrumb.items.push({ name: '', item: '' });
489
+ };
490
+
491
+ const removeBreadcrumbItem = (index) => {
492
+ if (forms.breadcrumb.items.length > 1) {
493
+ forms.breadcrumb.items.splice(index, 1);
494
+ }
495
+ };
496
+
497
+ const copyCode = () => {
498
+ navigator.clipboard.writeText(generatedJson.value).then(() => {
499
+ copyBtnText.value = '已复制!';
500
+ setTimeout(() => copyBtnText.value = '复制', 2000);
501
+ });
502
+ };
503
+
504
+ const resetForm = () => {
505
+ // Simple reload or reset state manually. Reload is easiest for MVP.
506
+ if(confirm('确定要重置所有内容吗?')) {
507
+ location.reload();
508
+ }
509
+ }
510
+
511
+ return {
512
+ currentType,
513
+ schemaTypes,
514
+ forms,
515
+ generatedJson,
516
+ googleTestUrl,
517
+ getSchemaName,
518
+ addFaqItem,
519
+ removeFaqItem,
520
+ addBreadcrumbItem,
521
+ removeBreadcrumbItem,
522
+ copyCode,
523
+ copyBtnText,
524
+ resetForm
525
+ };
526
+ }
527
+ }).mount('#app');
528
+ </script>
529
+ {% endraw %}
530
+ </body>
531
+ </html>