Pular para o conteúdo principal

O componente (Scriban)

Arquivo Components/utils/konfidency_reviews.html. Copie como está — ele já traz o container de montagem do widget, o escape do texto das avaliações e o espaçamento que evita o salto de layout quando o widget substitui o conteúdo.

Volte ao roteiro de instalação para os outros três passos.

Por que copiar em vez de escrever o seu

Três detalhes aqui não são estéticos: o texto das avaliações passa por html.escape (é conteúdo de consumidor), o min-height reserva o espaço que o widget vai ocupar, e a marcação não emite dados estruturados próprios — quem faz isso é o componente de JSON-LD do tema, para não haver dois aggregateRating na mesma página.

Components/utils/konfidency_reviews.html
{{ ##
Description: Bloco de avaliações da Konfidency renderizado no servidor,
a partir do documento do produto lido do Document Wake na query da página.
Params:
- reviews_data: o documento do produto (konfidency_data)
- product: o produto da página
Usage:
konfidency_reviews reviews_data: konfidency_data product: product

Renderiza dentro de `div.konfidency-reviews-details`, o ponto de montagem do
SDK: ao carregar, ele limpa o container e monta o widget por cima. Por isso o
container sai sempre, mesmo sem dados, e a marcação espelha a UI do widget —
para a troca não causar salto de layout.
## }}
{{~
estrela_svg = '<svg viewBox="0 0 2494.2 2388.56" width="21" height="21" aria-hidden="true" focusable="false"><polygon fill="COR" points="1247.09 1827.77 2016.15 2388.56 1725.15 1474.67 2494.2 934.65 1558.88 934.65 1247.09 0 935.32 934.65 0 934.65 769.04 1474.67 478.05 2388.56 1247.09 1827.77"/></svg>'
estrela_cheia = estrela_svg | string.replace "COR" "#fbb832"
estrela_vazia = estrela_svg | string.replace "COR" "#dbdbdb"
estrela_meia = '<svg viewBox="0 0 2494.2 2388.56" width="21" height="21" aria-hidden="true" focusable="false"><defs><linearGradient id="kfy-meia-estrela"><stop offset="50%" stop-color="#fbb832"/><stop offset="50%" stop-color="#dbdbdb"/></linearGradient></defs><polygon fill="url(#kfy-meia-estrela)" points="1247.09 1827.77 2016.15 2388.56 1725.15 1474.67 2494.2 934.65 1558.88 934.65 1247.09 0 935.32 934.65 0 934.65 769.04 1474.67 478.05 2388.56 1247.09 1827.77"/></svg>'

tem_dados = reviews_data && reviews_data.product_id == (product.product_id | string.downcase) && reviews_data.rating_count > 0
~}}
<div class="konfidency-reviews-details" data-konfidency-ssr>
{{~ if tem_dados ~}}
{{~
total = reviews_data.rating_count
nota = reviews_data.rating_average
nota_inteira = math.floor nota
resto = nota - nota_inteira
~}}
<style>
.kfy-ssr { font-size: 16px; line-height: 24px; color: #3e3e3e; }
.kfy-ssr__title { font-size: 18px; font-weight: 600; line-height: 28px; text-transform: uppercase; margin: 0 0 16px; }
.kfy-ssr__summary { display: flex; align-items: flex-start; flex-wrap: wrap; gap: 20px 40px; }
.kfy-ssr__aggregate { font-size: 30px; font-weight: 700; line-height: 45px; margin-right: 20px; }
.kfy-ssr__stars { line-height: 0; }
.kfy-ssr__stars svg { display: inline-block; vertical-align: middle; }
.kfy-ssr__stars--summary { margin-top: 6px; }
.kfy-ssr__attributes { min-width: 280px; }
.kfy-ssr__attribute { display: flex; align-items: center; gap: 12px; margin-bottom: 6px; }
.kfy-ssr__attribute-name { font-size: 15px; font-weight: 700; line-height: 22.5px; }
.kfy-ssr__bar { flex: 1; min-width: 120px; height: 8px; border-radius: 4px; background: #e8e8e8; }
.kfy-ssr__progress { height: 8px; border-radius: 4px; background: #009ee2; }
.kfy-ssr__rate { font-size: 15px; line-height: 22.5px; white-space: nowrap; }
.kfy-ssr__details-header { display: flex; align-items: baseline; flex-wrap: wrap; gap: 12px; margin-top: 30px; }
.kfy-ssr__aggregate--small { font-size: 20px; font-weight: 700; }
.kfy-ssr__showing { font-size: 13px; color: #787878; }
/* min-height reserva o espaço da coluna de votos do widget: sem ela a lista encolhe ao montar */
.kfy-ssr__review { display: flex; flex-wrap: wrap; align-items: center; align-content: flex-start; margin: 20px 0 10px; padding-bottom: 15px; border-bottom: 1px solid #f3f3f3; min-height: 79px; }
.kfy-ssr__review .kfy-ssr__stars { min-height: 34px; display: flex; align-items: center; }
.kfy-ssr__review .kfy-ssr__stars { margin-right: 30px; }
.kfy-ssr__name { font-size: 16px; font-weight: 600; margin-right: 30px; }
.kfy-ssr__date { font-size: 13px; line-height: 19.5px; color: #787878; margin-right: 30px; }
.kfy-ssr__verified { font-size: 12px; }
.kfy-ssr__text { width: 100%; margin-top: 15px; padding-bottom: 8px; }
</style>

<section id="konfidency-reviews" class="kfy-ssr container-custom py-8">
<h2 class="kfy-ssr__title">Avaliações</h2>

<div class="kfy-ssr__summary">
<div class="kfy-ssr__aggregate">{{ math.round nota 1 }}</div>

<div>
<div class="kfy-ssr__stars kfy-ssr__stars--summary" role="img" aria-label="{{ math.round nota 1 }} de 5 estrelas">
{{~ for posicao in 1..5 ~}}
{{~ if posicao <= nota_inteira ~}}{{ estrela_cheia }}
{{~ else if posicao == nota_inteira + 1 && resto >= 0.75 ~}}{{ estrela_cheia }}
{{~ else if posicao == nota_inteira + 1 && resto >= 0.25 ~}}{{ estrela_meia }}
{{~ else ~}}{{ estrela_vazia }}
{{~ end ~}}
{{~ end ~}}
</div>
<div class="kfy-ssr__review-count"><span>{{ total }}</span> avaliaç{{ total > 1 ? "ões" : "ão" }}</div>
{{~ if reviews_data.recommended_percent > 0 ~}}
<div class="kfy-ssr__recommended">{{ math.round reviews_data.recommended_percent }}% dos avaliadores recomendam o produto</div>
{{~ end ~}}
</div>

{{~ if reviews_data.attributes && reviews_data.attributes.size > 0 ~}}
<div class="kfy-ssr__attributes">
{{~ for atributo in reviews_data.attributes ~}}
<div class="kfy-ssr__attribute">
<div class="kfy-ssr__attribute-name">{{ atributo.title | html.escape }}</div>
<div class="kfy-ssr__bar">
<div class="kfy-ssr__progress" style="width: {{ atributo.average * 100 / atributo.scale_max }}%"></div>
</div>
<div class="kfy-ssr__rate">{{ math.round atributo.average 1 }}/{{ atributo.scale_max }}</div>
</div>
{{~ end ~}}
</div>
{{~ end ~}}
</div>

<div class="kfy-ssr__details-header">
<div class="kfy-ssr__aggregate--small">{{ math.round nota 1 }}</div>
<div>{{ total }} avaliaç{{ total > 1 ? "ões" : "ão" }}</div>
<div class="kfy-ssr__showing">mostrando {{ reviews_data.reviews.size }} de {{ total }} avaliaç{{ total > 1 ? "ões" : "ão" }}</div>
</div>

<div class="kfy-ssr__reviews">
{{~ for review in reviews_data.reviews ~}}
<div class="kfy-ssr__review">
<div class="kfy-ssr__stars" role="img" aria-label="{{ review.rating }} de 5 estrelas">
{{~ for posicao in 1..5 ~}}{{ posicao <= review.rating ? estrela_cheia : estrela_vazia }}{{~ end ~}}
</div>
<div class="kfy-ssr__name">{{ review.name | html.escape }}</div>
<div class="kfy-ssr__date">{{ (review.date | string.slice 8 2) }}/{{ (review.date | string.slice 5 2) }}/{{ (review.date | string.slice 0 4) }}</div>
{{~ if review.verified ~}}
<div class="kfy-ssr__verified">comprador verificado</div>
{{~ end ~}}

{{~ if review.text | string.strip | string.size > 0 ~}}
<div class="kfy-ssr__text">{{ review.text | html.escape }}</div>
{{~ end ~}}
</div>
{{~ end ~}}
</div>
</section>
{{~ end ~}}
</div>