How to configure "application / ld + json" schema.org metadata in rails 4 applications

I want to configure schema.org metadata using json ld. for example, the following link uses a ghost and contains the metadata "application / ld + json". http://blog.ghost.org/distributed-team-tools/

I want to achieve a similar rails for my application. How to implement it. is there any stone for this, etc.

Thanks!

+9
source share
2 answers

There is a pearl of JSON-LD ( http://rubygems.org/gems/json-ld ), but this may not be exactly what you are looking for. Note that the JSON-LD point is that it is just JSON, in which case the schema.org context is used to interpret the values. Assuming your data is in ActiveRecord models, you'll need a way to make sure the record properties match the corresponding schema.org properties. If so, then just serializing your model for JSON (#to_json) will get you most of the way. It remains to add the fields @context , @id and @type in JSON.

For example, let's say you have a User model that is serialized like this:

 { "name": "Harry", "email": " Harry@example.org " } 

As the properties "name" and "email address" of http://schema.org/Person , you can get the part there by simply adding @context and @type as follows

 { "@context": "http://schema.org/", "@type": "Person", "name": "Harry", "email": " Harry@example.org " } 

Assuming you are creating a RESTful application, it is good practice to provide each @id object that matches the resource URL for that person. This may be as follows:

 { "@context": "http://schema.org/", "@id": "http://example.com/people/harry", "@type": "Person", "name": "Harry", "email": " Harry@example.org " } 

Now, if you get http://example.com/people/harry as JSON (or JSON-LD), you can return this view.

Another thing about JSON-LD is that it is for “Related Data”, so including links to other resources is useful so that you can find them, as you probably do in your HTML. The schema.org documentation includes numerous examples of how to create various types of markup, including JSON-LD, for most of the types that they define. See http://schema.org/Person for one example or http://schema.org/docs/full.html for their complete type hierarchy.

The JSON-LD driver comes in handy when you want to generate this data from other sources (usually in RDF format) or interpret the received data. You can experiment with this at http://json-ld.org/playground .

You can also include JSON-LD in HTML using a script tag with type = "application / ld + json", as your example does. If you want to see how your data looks, you can check it either in the Google Structured Data Testing Tool or at http://linter.structured-data.org/

+9
source
 %script{type: "application/ld+json"} :plain { "@context": "http://schema.org", "headline": "Headline", "@type": "Article", "alternativeHeadline": "Alternative Headline}" } 

Instead of using :javascript filter :javascript , http://haml.info/docs/yardoc/file.REFERENCE.html#filters , instead I used a %script tag that allows me to determine its type using an attribute method that defines enter as application/ld+json , http://haml.info/docs/yardoc/file.REFERENCE.html#attribute-methods

Filter :plain does not process filtered text. This is useful for large blocks of text without HTML tags, when you do not need lines starting with. or - for analysis see the document http://haml.info/docs/yardoc/file.REFERENCE.html#plain-filter

0
source

Source: https://habr.com/ru/post/980357/


All Articles