Skip to content

Commit ff90459

Browse files
Digidaiclaude
andcommitted
fix: 修复 JSON-LD ItemList 逗号处理问题
使用 jsonify 过滤器和数组 join 方法确保 JSON 语法正确 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <[email protected]>
1 parent 756683c commit ff90459

File tree

2 files changed

+8
-23
lines changed

2 files changed

+8
-23
lines changed

_layouts/tag_page.html

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -39,19 +39,12 @@
3939
"mainEntity": {
4040
"@type": "ItemList",
4141
"itemListElement": [
42+
{% assign items_json = "" | split: "" %}
4243
{% for product in product_items limit: 10 %}
43-
{
44-
"@type": "ListItem",
45-
"position": {{ forloop.index }},
46-
"item": {
47-
"@type": "SoftwareApplication",
48-
"name": "{{ product.name | escape }}",
49-
"description": "{{ product.description | escape }}",
50-
"url": "{{ product.url | escape }}",
51-
"applicationCategory": "BusinessApplication"
52-
}
53-
}{% unless forloop.last %},{% endunless %}
44+
{% capture item_json %}{"@type": "ListItem", "position": {{ forloop.index }}, "item": {"@type": "SoftwareApplication", "name": {{ product.name | jsonify }}, "description": {{ product.description | jsonify }}, "url": {{ product.url | jsonify }}, "applicationCategory": "BusinessApplication"}}{% endcapture %}
45+
{% assign items_json = items_json | push: item_json %}
5446
{% endfor %}
47+
{{ items_json | join: ", " }}
5548
]
5649
}
5750
}

product-directory.md

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -33,25 +33,17 @@ permalink: /product-directory/
3333
"numberOfItems": {{ total_products }},
3434
"itemListElement": [
3535
{% assign position = 0 %}
36+
{% assign items_json = "" | split: "" %}
3637
{% for category in site.data.products %}
3738
{% for product in category.products limit: 5 %}
3839
{% assign position = position | plus: 1 %}
3940
{% if position <= 20 %}
40-
{
41-
"@type": "ListItem",
42-
"position": {{ position }},
43-
"item": {
44-
"@type": "SoftwareApplication",
45-
"name": "{{ product.name | escape }}",
46-
"description": "{{ product.description | escape }}",
47-
"url": "{{ product.url | escape }}",
48-
"applicationCategory": "BusinessApplication",
49-
"operatingSystem": "Web"
50-
}
51-
}{% if position < 20 %},{% endif %}
41+
{% capture item_json %}{"@type": "ListItem", "position": {{ position }}, "item": {"@type": "SoftwareApplication", "name": {{ product.name | jsonify }}, "description": {{ product.description | jsonify }}, "url": {{ product.url | jsonify }}, "applicationCategory": "BusinessApplication", "operatingSystem": "Web"}}{% endcapture %}
42+
{% assign items_json = items_json | push: item_json %}
5243
{% endif %}
5344
{% endfor %}
5445
{% endfor %}
46+
{{ items_json | join: ", " }}
5547
]
5648
}
5749
}

0 commit comments

Comments
 (0)