我正在尝试使用Schema.org中的SiteNavigationElement
类型。 HTML是动态生成的,因此我无法对其进行编辑。因此,JSON-LD是我唯一的选择。
我希望所有导航元素都在单个SiteNavigationElement
对象下。
我已将所需的输出作为屏幕快照附加:
最佳答案
方法如下:
<script type="application/ld+json">
{
"@context": "https://schema.org",
"@graph":
[
{
"@context": "https://schema.org",
"@type":"SiteNavigationElement",
"@id":"#table-of-contents",
"name": "Section 1",
"url": "https://www.example.com/page#toc-1"
},
{
"@context": "https://schema.org",
"@type":"SiteNavigationElement",
"@id":"#table-of-contents",
"name": "Section 2",
"url": "https://www.example.com/page#toc-2"
},
{
"@context": "https://schema.org",
"@type":"SiteNavigationElement",
"@id":"#table-of-contents",
"name": "Section 3",
"url": "https://www.example.com/page#toc-3"
},
{
"@context": "https://schema.org",
"@type":"SiteNavigationElement",
"@id":"#pagination",
"name": "Previous page",
"url": "https://www.example.com/page1"
},
{
"@context": "https://schema.org",
"@type":"SiteNavigationElement",
"@id":"#pagination",
"name": "Next page",
"url": "https://www.example.com/page2"
}
]
}
</script>
该代码将如this example中所示出现。