eloquence / lib.reviews

A free/libre code and information platform for reviews of anything
Creative Commons Zero v1.0 Universal
171 stars 13 forks source link

Add schema.org markup to single reviews #275

Closed nortix closed 2 years ago

nortix commented 2 years ago

Adding the schema.org/Review markup to lib.reviews/views/partials/reviews.hbs for better visibility in search results at the end of the file. Google recommends the use of JSON-LD

<!-- JSON for the review, see https://schema.org/Review -->
<script type="application/ld+json">
{
  "@context": "https://schema.org",
  "@type": "Product",
  "name": "{{{mlString review.thing.label}}}",
  "description": "{{{mlString thing.description}}}",
  {{#if socialImage}} "image": "{{{qualifiedURL}}}static/uploads/{{{socialImage}}}", {{/if}}
  "review": [
    {
      "@type": "Review",
      "author": "{{{review.creator}}}",
      "datePublished": "{{{review.createdOn}}}",
      "reviewBody": "{{{summarize (mlString review.html false) 250}}}",
      "name": "{{{mlString review.title}}}",
      "reviewRating": {
        "@type": "Rating",
        "bestRating": "5",
        "ratingValue": "1",
        "worstRating": "1"
      }
    }
  ]
}
</script>
eloquence commented 2 years ago

I've started to look at this a bit. A couple of notes:

I'll take a stab at expressing the above in microdata and running it against a few validators and testing some edge cases.

nortix commented 2 years ago

Thank you.

I think I have expressed myself in a misleading way. My markup was meant for individual reviews, e.g. https://lib.reviews/review/fb830f7a-70af-48ae-a7e5-5f3744d6d218, and was meant to complement the summary page, https://lib.reviews/twitter. I saw it as an extension for the individual reviews.

I prefer JSON-LD because it bloats the HTML code less and combines all markup data in one block. But I can also respect the decision for Mirodata. I would be happy with either way.