diff --git a/CHANGELOG.md b/CHANGELOG.md index dcdd75a..5685421 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,11 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [1.0.43] - 2026-06-15 + +### 修复 +- 修复微信/飞书分享商品链接时卡片只显示"岩美"而不显示商品名称和图片的问题 + ## [1.0.42] - 2026-06-15 ### 修复 diff --git a/backend/internal/handler/public.go b/backend/internal/handler/public.go index 3073b3e..78a516a 100644 --- a/backend/internal/handler/public.go +++ b/backend/internal/handler/public.go @@ -313,15 +313,17 @@ func (h *PublicHandler) ProductPage(c *gin.Context) { // 构造 OG 标签并注入 前 ogTags := buildProductOG(product, shopName, config.C.Storage.PublicURL) - out := strings.Replace(idxHTML, "", ogTags+"", 1) + ogTitle := buildOGTitle(product) + // 同时替换 标签,微信/飞书等平台有时优先读 <title> 而非 og:title + out := strings.Replace(idxHTML, "<title>岩美", ""+html.EscapeString(ogTitle)+"", 1) + out = strings.Replace(out, "", ogTags+"", 1) + // 禁止缓存,确保爬虫每次都能拿到最新 OG 标签 + c.Header("Cache-Control", "no-store") c.Data(http.StatusOK, "text/html; charset=utf-8", []byte(out)) } -// buildProductOG 构造基础 Open Graph meta 标签字符串。 -// 所有值经 html.EscapeString 转义,防止 XSS 或破坏 HTML 结构。 -// 无图片时不输出 og:image 行。 -func buildProductOG(product model.Product, shopName, publicURL string) string { - // og:title:品牌 + 商品名(品牌已含在名字中时不重复)+ 系列 +// buildOGTitle 生成商品的分享标题:品牌 + 商品名(品牌已含在名字中时不重复)+ 系列。 +func buildOGTitle(product model.Product) string { title := product.Name if product.Brand != "" && !strings.Contains(product.Name, product.Brand) { title = product.Brand + title @@ -329,6 +331,14 @@ func buildProductOG(product model.Product, shopName, publicURL string) string { if product.Series != "" { title = title + "(" + product.Series + ")" } + return title +} + +// buildProductOG 构造基础 Open Graph meta 标签字符串。 +// 所有值经 html.EscapeString 转义,防止 XSS 或破坏 HTML 结构。 +// 无图片时不输出 og:image 行。 +func buildProductOG(product model.Product, shopName, publicURL string) string { + title := buildOGTitle(product) // og:description:规格(度数/香型/容量)| 门店名正品 · 扫码验真 desc := product.Spec