Repository navigation
Render product structured data from the theme #88
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
d2ed0fb
Render product structured data from the theme
next-devin 50dd3ae
Give each structured-data variant an image and description
next-devin 85109bd
Re-run Kilo Code Review
next-devin 5ac5ea6
Drop priceless offers and empty images from structured data
next-devin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,88 @@ | ||
| {# Spark Theme — PDP head metadata. Rendered from the seo block in templates/catalogue/product.html. #} | ||
| {# Replaces the platform {% seo %} output on product pages: meta and Open Graph tags plus schema.org JSON-LD. #} | ||
| {# Every string inside the JSON-LD goes through escapejs, so quotes, backslashes and </script> in merchant text stay valid JSON. #} | ||
| {# Identifiers come from product metadata when the store defines them: brand, gtin, mpn. Without brand, the store name is used. #} | ||
| {# gtin falls back to the UPC only when the UPC is 8, 12, 13 or 14 digits. The UPC is never emitted as mpn. #} | ||
| {% image_thumbnail product.get_meta_image "1200x630" upscale=True crop="center" as thumb %} | ||
| {% purchase_info_for_product request product as session %} | ||
|
|
||
| <meta name="title" content="{{ product.get_meta_title }}" /> | ||
| <meta name="description" content="{{ product.get_meta_description|striptags|slice:160 }}" /> | ||
| {% if not product.is_public %} | ||
| <meta name="robots" content="noindex, nofollow" /> | ||
|
next-devin marked this conversation as resolved.
Resolved
|
||
| {% endif %} | ||
| <meta property="og:title" content="{{ product.get_meta_title }}" /> | ||
| <meta property="og:type" content="product" /> | ||
| <meta property="og:description" content="{{ product.get_meta_description|striptags|slice:160 }}" /> | ||
| <meta property="og:url" content="{{ product.get_primary_url }}" /> | ||
|
next-devin marked this conversation as resolved.
Resolved
|
||
| <meta property="og:image" content="{{ thumb.url }}" /> | ||
|
next-devin marked this conversation as resolved.
Resolved
|
||
| <meta property="product:brand" content="{% if product.metadata.brand %}{{ product.metadata.brand }}{% else %}{{ shop_name }}{% endif %}" /> | ||
|
next-devin marked this conversation as resolved.
Resolved
|
||
| <meta property="product:availability" content="{% if session.availability.is_available_to_buy %}instock{% else %}outofstock{% endif %}" /> | ||
| {% if session.price.exists %} | ||
| <meta property="product:price:amount" content="{{ session.price.price|stringformat:'s' }}" /> | ||
| <meta property="product:price:currency" content="{{ session.price.currency }}" /> | ||
| {% endif %} | ||
| <meta property="product:retailer_item_id" content="{{ product.id }}" /> | ||
|
|
||
| <script type="application/ld+json"> | ||
| { | ||
| "@context": "https://schema.org", | ||
| "@type": "{% if product.is_parent %}ProductGroup{% else %}Product{% endif %}", | ||
|
next-devin marked this conversation as resolved.
Resolved
|
||
| "name": "{{ product.get_title|escapejs }}", | ||
| "description": "{% if product.description %}{{ product.description|striptags|escapejs }}{% else %}{{ product.get_meta_description|striptags|escapejs }}{% endif %}", | ||
| "url": "{{ product.get_primary_url|escapejs }}", | ||
| {% with images=product.get_all_images %}{% if images %}"image": [{% for image in images|slice:':3' %}{% image_thumbnail image.original "1200x1200" upscale=False as image_thumb %}"{{ image_thumb.url|escapejs }}"{% if not forloop.last %}, {% endif %}{% endfor %}],{% elif thumb.url %}"image": "{{ thumb.url|escapejs }}",{% endif %}{% endwith %} | ||
| "brand": { | ||
| "@type": "Brand", | ||
| "name": "{% if product.metadata.brand %}{{ product.metadata.brand|escapejs }}{% else %}{{ shop_name|escapejs }}{% endif %}" | ||
|
next-devin marked this conversation as resolved.
Resolved
|
||
| }, | ||
| {% if product.metadata.mpn %}"mpn": "{{ product.metadata.mpn|escapejs }}",{% endif %} | ||
| {% if settings.product_reviews and product.rating and product.num_approved_reviews %} | ||
| "aggregateRating": { | ||
| "@type": "AggregateRating", | ||
| "ratingValue": "{{ product.rating|stringformat:'s' }}", | ||
| "reviewCount": "{{ product.num_approved_reviews }}" | ||
| }, | ||
| {% endif %} | ||
| {% if product.is_parent %} | ||
| "hasVariant": [ | ||
| {% for child in product.children.all %} | ||
|
next-devin marked this conversation as resolved.
Resolved
|
||
| {% purchase_info_for_product request child as child_session %} | ||
| { | ||
| "@type": "Product", | ||
| "name": "{{ child.get_title|escapejs }}", | ||
| "description": "{% if product.description %}{{ product.description|striptags|escapejs }}{% else %}{{ product.get_meta_description|striptags|escapejs }}{% endif %}", | ||
| {% with child_images=child.get_all_images %}{% if child_images %}{% image_thumbnail child_images.0.original "1200x1200" upscale=False as child_thumb %}"image": "{{ child_thumb.url|escapejs }}",{% elif thumb.url %}"image": "{{ thumb.url|escapejs }}",{% endif %}{% endwith %} | ||
| {% if child.sku %}"sku": "{{ child.sku|escapejs }}",{% endif %} | ||
| {% if child.metadata.gtin %}"gtin": "{{ child.metadata.gtin|escapejs }}",{% elif child.upc and child.upc.isdigit and child.upc|length|stringformat:'s' in '8,12,13,14'|split:',' %}"gtin": "{{ child.upc|escapejs }}",{% endif %} | ||
| {% if child.metadata.mpn %}"mpn": "{{ child.metadata.mpn|escapejs }}",{% endif %} | ||
| {% if child_session.price.exists %} | ||
| "offers": { | ||
| "@type": "Offer", | ||
| "price": "{{ child_session.price.price|stringformat:'s' }}", | ||
| "priceCurrency": "{{ child_session.price.currency }}", | ||
| "availability": "{% if child_session.availability.is_available_to_buy %}https://schema.org/InStock{% else %}https://schema.org/OutOfStock{% endif %}", | ||
| "url": "{{ product.get_primary_url|escapejs }}" | ||
| }, | ||
| {% endif %} | ||
| "productID": "{{ child.id }}" | ||
| }{% if not forloop.last %},{% endif %} | ||
| {% endfor %} | ||
| ], | ||
| "productGroupID": "{{ product.id }}" | ||
| {% else %} | ||
| {% if product.sku %}"sku": "{{ product.sku|escapejs }}",{% endif %} | ||
| {% if product.metadata.gtin %}"gtin": "{{ product.metadata.gtin|escapejs }}",{% elif product.upc and product.upc.isdigit and product.upc|length|stringformat:'s' in '8,12,13,14'|split:',' %}"gtin": "{{ product.upc|escapejs }}",{% endif %} | ||
| {% if session.price.exists %} | ||
| "offers": { | ||
| "@type": "Offer", | ||
| "price": "{{ session.price.price|stringformat:'s' }}", | ||
| "priceCurrency": "{{ session.price.currency }}", | ||
| "availability": "{% if session.availability.is_available_to_buy %}https://schema.org/InStock{% else %}https://schema.org/OutOfStock{% endif %}", | ||
| "url": "{{ product.get_primary_url|escapejs }}" | ||
| }, | ||
| {% endif %} | ||
| "productID": "{{ product.id }}" | ||
| {% endif %} | ||
| } | ||
| </script> | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.