Json-LD > Define a “person” for easy reuse as valu

2020-07-22 19:31发布

问题:

I am trying to use json-ld on my website using schema.org as the lanquage.

The reason is to assist search engine's crawlers to understand my site.

Schema.org offers many key/value attribute pairs for Types of Items.

Sometimes the values for those keys are themselves an Item with their own Type and have their own set of key/value pairs.

In practice, the same Item is appropriate answer for several different keys, and it is desirous/necessary to give that Item's key/value set.

In my case, for example, I am marking up a web pages on a website with schema.org's "WebPage" type.

I want to give the same person as the answer for various keys on the WebPage type: author, creator, copyrightHolder, etc.

I think I can do this repeating the values each time with something like:

<script type="application/ld+json">
{
    "@context": "http://schema.org",
    "@type" : "WebPage",
    "name" : "The Name of the Webpage",
    "author" : 
        {
        "@type" : "Person",
        "name" : "Tim"
        }
    "creator": 
        {
        "@type" : "Person",
        "name" : "Tim"
        }
    "copyrightHolder" :
        {
        "@type" : "Person"
        "name" : "Tim",
        }
}
</script>

However, that is repetitive and verbose to me.

I would rather assign/define the person once, and then reference him (me) using a keyword as needed.

I don't know much about json-ld or coding/programming, and as a lay person I have found the information (spec + jsonld.org + here) a bit confusing.

I understand that @context can be expanded for the document (here a webpage) to define 'things' in addition to declaring the relevant 'language' as being schema.or, and that json-ld also seems to support referencing specific items using 'IRIs' as an ID.

So it seems like I might be able to define the Person once as desired with something similar to the following:

<script type="application/ld+json">
{
    "@context": 
        ["http://schema.org",
            {
              "Tim" : 
                {
                "@type" : "Person",
                "@id" : "https://www.example.com/tim#tim"
                "name" : "Tim"
                }
            }],
    "@type" : "WebPage",
    "name" : "The Name of the Webpage",
    "author" : "Tim",
    "creator": "Tim"
}
</script>

So my questions are:

  1. Can we do this and, if so, how?

  2. In a lot of documentation, IRI's appear to be URLs with #value tacked on the end. Is the #value simply a declaration to differentiate it from the page URL (which may be a value unto itself for some other keys), or is the #value referencing a div on the page such as a div with an id="value" or perhaps some other protocol?

  3. If I do this, will say Google's crawler simply cache the IRI for referencing later of the associated URL or div, or will it likely assign the values defined? Ideally, I would like the expanded values to be returned for each use.

I have looked a lot on this site for answers to these questions. I have seen similar questions and answers, and which may have answered these questions but in a way I could not understand. For example, I do not know what a "node" or an "object" is.

Please excuse my lack of knowledge. Any use of simple plain language would be appreciated. Actually, any help would be much appreciated!

Thank you.

回答1:

Your example is almost right. You need to assign an @id to the person object that you reuse elsewhere:

<script type="application/ld+json">
{
    "@context": "http://schema.org",
    "@type" : "WebPage",
    "name" : "The Name of the Webpage",
    "author" : {
      "@type" : "Person",
      "@id": "#tim",
      "name" : "Tim"
    },
    "creator": {
      "@id": "#tim"
    },
    "copyrightHolder": {
      "@id": "#tim"
    }
}
</script>


标签: json-ld