@id 与用于链接 JSON-LD 节点的 URL [英] @id vs. URL for linking JSON-LD nodes

查看:45
本文介绍了@id 与用于链接 JSON-LD 节点的 URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在主页上定义的 WebSite 节点上定义了发布者 Organization,现在我想从其他页面上的文章链接到该发布者.但是,我也想链接到 WebSite,如果我遵循使用 URL 作为 @ 的建议,它们自然会共享相同的 @idid.

I have defined the publisher Organization on the WebSite node defined on the home page, and I now want to link to that publisher from articles on other pages. However, I also want to link to the WebSite as well, and they naturally share the same @id if I follow the advice of using the URL as the @id.

{
    "@context": "http://schema.org",
    "@type": "WebSite",
    "@id": "http://www.example.com/",
    "url": "http://www.example.com/",
    ...
    "publisher": {
        "@type": "Organization",
        "@id": "http://www.example.com/",  <-- duplicated
        "url": "http://www.example.com/"
    }
}

{
    "@context": "http://schema.org",
    "@type": "WebPage",
    "@id": "http://www.example.com/news",
    "url": "http://www.example.com/news",
    "isPartOf": {
        "@id": "http://www.example.com/"  <-- site or publisher?
    }
    ...
    "publisher": {
        "@id": "http://www.example.com/"  <-- site or publisher?
    }
}

我假设每个节点的 ID 必须是唯一的,那么是否有统一 ID 的最佳实践,例如添加哈希?

I assume IDs must be unique to each node, so is there a best practice for uniquifying IDs such as adding a hash?

{
    "@id": "http://www.example.com/#site",
    ...
    "publisher": {
        "@id": "http://www.example.com/#publisher",
    }
}

如果可行,处理器 (Google) 会加载 @id 以查找节点的其余属性吗?

If that works, will processors (Google) load the @id to find the rest of the node's properties?

与此相关的是,在许多节点类型中找到的 url 属性是否被假定为 @id 如果缺失?对于大多数节点,我最终将页面的完整 URL 复制为 @idurl.这是常态吗?

Related to this, is the url property found in many node types assumed to be the @id if missing? I'm ending up duplicating the full URL of the page as the @id and url for most nodes. Is that the norm?

推荐答案

@id (JSON-LD)

(微数据中的 itemid 和 RDFa 中的 resource 也是如此)

@id (JSON-LD)

(and the same goes for itemid in Microdata, and resource in RDFa)

每件事都应该有一个不同的 URI,如果多个节点是关于同一件事的,那么理想情况下,它们应该重用这个 URI.请注意,这些不一定是 URL,而且它们通常不应用作 Schema.org 的 url 属性的值(请参阅下面的部分).

Each thing should get a different URI, and if multiple nodes are about the same thing, they should ideally reuse this URI. Note that these don’t have to be URLs, and they should often not be used as values for Schema.org’s url property (see section below).

使用 URI 片段是实现此目的的常见且最简单的方法.有关示例(和其他方式),请参阅我对这些问题的回答:

Using URI fragments is a common and the most simple way to achieve this. For examples (and other ways), see my answers to these questions:

对于您的示例案例,组织的网站,根 URL (http://www.example.com/) 通常代表"三件事:

For your example case, an organization’s website, the root URL (http://www.example.com/) typically "stands for" three things:

  • 主页
  • 整个网站
  • 组织

由于主页是被检索的资源,它应该获得 URI http://www.example.com/.网站和组织应该有自己的碎片;由您来选择哪些,例如:http://www.example.com/#site 用于网站,http://www.example.com/#organization 用于组织(FWIW,Apple 似乎使用 #organization,也是.)

As the home page is the resource that gets retrieved, it should get the URI http://www.example.com/. The site and the organization should get their own fragments; it’s up to you to choose which ones, e.g.: http://www.example.com/#site for the site, and http://www.example.com/#organization for the organization (FWIW, Apple seems to use #organization, too.)

  • 主页:
    http://www.example.com/

整个网站:
http://www.example.com/#site

组织:
http://www.example.com/#organization

(通常只涉及两个不同的东西:文档和文档描述的东西.然后东西经常得到像#this这样的片段,在人的情况下,#i,但这只是一个约定.)

(Often only two different things are involved: the document, and the thing described by the document. Then the thing often gets a fragment like #this, and in case of persons, #i, but this is just a convention.)

如果可行,处理器 (Google) 会加载 @id 以查找节点的其余属性吗?

If that works, will processors (Google) load the @id to find the rest of the node's properties?

Google 不会记录他们是否尝试加载这些 URI.

Google doesn’t document if they try to load those URIs.

请注意,不要求这些 URI 实际指向文档.您可以使用提供 404 答案的 HTTP URI,或者您可以使用不允许检索文档开头的 URI 方案(例如,urntag、...).

Note that there is no requirement that these URIs actually point to a document. You could use HTTP URIs that give 404 answers, or you could use a URI scheme that doesn’t allow retrieval of documents to begin with (e.g., urn, tag, …).

Schema.org 的 url 属性应该用于指向页面的 URL可以参观的.它不是提供 ID 的一种方式,因此它不一定与 @id 中提供的 URI 相同.

Schema.org’s url property should be used for the URLs that lead to pages that can be visited. It’s not intended as a way to provide an ID, so it’s not necessarily the same URI as provided in @id.

在您的示例中,您可能会对所有三件事使用相同的 url 值:

In your example case, you would probably use the same url value for all three things:

  • 主页:
    @id:http://www.example.com/
    url:http://www.example.com/

整个网站:
@id:http://www.example.com/#site
url:http://www.example.com/

组织:
@id:http://www.example.com/#organization
url:http://www.example.com/

这篇关于@id 与用于链接 JSON-LD 节点的 URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆