Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 07f8973477 | |||
| 3b02a848c0 | |||
| bde2d35756 | |||
| 4ac5adac3e | |||
| 8c2dcf49a8 | |||
| f400459497 |
@@ -5,6 +5,38 @@ 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.47] - 2026-06-15
|
||||
|
||||
### 修复
|
||||
- 微信分享卡片描述补充度数/系列信息,不再只显示规格
|
||||
|
||||
## [1.0.46] - 2026-06-15
|
||||
|
||||
### 修复
|
||||
- 微信内打开商品页时顶部标题栏显示商品名称,不再显示"岩美"
|
||||
|
||||
## [1.0.45] - 2026-06-15
|
||||
|
||||
### 修复
|
||||
- 修复微信分享卡片标题仍显示"岩美"的问题(HTML 缩进导致字符串匹配失败)
|
||||
- 微信分享卡片描述去掉"扫码验真"后缀
|
||||
|
||||
## [1.0.44] - 2026-06-15
|
||||
|
||||
### 改进
|
||||
- 微信分享卡片标题改为商品名称(之前仍显示"岩美")
|
||||
- 微信分享卡片描述去掉"扫码验真"后缀
|
||||
|
||||
## [1.0.43] - 2026-06-15
|
||||
|
||||
### 修复
|
||||
- 修复微信/飞书分享商品链接时卡片只显示"岩美"而不显示商品名称和图片的问题
|
||||
|
||||
## [1.0.42] - 2026-06-15
|
||||
|
||||
### 修复
|
||||
- 修复商品二维码扫码页报"index.html not found"的错误
|
||||
|
||||
## [1.0.41] - 2026-06-15
|
||||
|
||||
### 改进
|
||||
|
||||
@@ -80,7 +80,7 @@ func Load() {
|
||||
viper.SetDefault("storage.upload_dir", "./uploads/images")
|
||||
viper.SetDefault("storage.base_url", "http://localhost:8080/images")
|
||||
viper.SetDefault("storage.public_url", "http://localhost:8081")
|
||||
viper.SetDefault("storage.web_dir", "./client/build/web")
|
||||
viper.SetDefault("storage.web_dir", "./web")
|
||||
|
||||
if err := viper.ReadInConfig(); err != nil {
|
||||
log.Println("[config] no config file found, using defaults and env vars")
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"html"
|
||||
"net/http"
|
||||
"os"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
@@ -313,15 +314,19 @@ func (h *PublicHandler) ProductPage(c *gin.Context) {
|
||||
|
||||
// 构造 OG 标签并注入 </head> 前
|
||||
ogTags := buildProductOG(product, shopName, config.C.Storage.PublicURL)
|
||||
out := strings.Replace(idxHTML, "</head>", ogTags+"</head>", 1)
|
||||
ogTitle := buildOGTitle(product)
|
||||
// 同时替换 <title> 标签,微信/飞书等平台有时优先读 <title> 而非 og:title
|
||||
// 用正则替换避免缩进空格导致字符串不匹配
|
||||
titleRe := regexp.MustCompile(`<title>[^<]*</title>`)
|
||||
out := titleRe.ReplaceAllString(idxHTML, "<title>"+html.EscapeString(ogTitle)+"</title>")
|
||||
out = strings.Replace(out, "</head>", ogTags+"</head>", 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,10 +334,25 @@ func buildProductOG(product model.Product, shopName, publicURL string) string {
|
||||
if product.Series != "" {
|
||||
title = title + "(" + product.Series + ")"
|
||||
}
|
||||
return title
|
||||
}
|
||||
|
||||
// og:description:规格(度数/香型/容量)| 门店名正品 · 扫码验真
|
||||
desc := product.Spec
|
||||
suffix := "正品 · 扫码验真"
|
||||
// buildProductOG 构造基础 Open Graph meta 标签字符串。
|
||||
// 所有值经 html.EscapeString 转义,防止 XSS 或破坏 HTML 结构。
|
||||
// 无图片时不输出 og:image 行。
|
||||
func buildProductOG(product model.Product, shopName, publicURL string) string {
|
||||
title := buildOGTitle(product)
|
||||
|
||||
// og:description:系列(度数/香型)· 规格(容量/单位)| 门店名正品
|
||||
var specParts []string
|
||||
if product.Series != "" {
|
||||
specParts = append(specParts, product.Series)
|
||||
}
|
||||
if product.Spec != "" {
|
||||
specParts = append(specParts, product.Spec)
|
||||
}
|
||||
desc := strings.Join(specParts, " · ")
|
||||
suffix := "正品"
|
||||
if shopName != "" {
|
||||
suffix = shopName + suffix
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ import 'dart:math' as math;
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:flutter/gestures.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:url_launcher/url_launcher.dart';
|
||||
import '../../core/config/app_config.dart';
|
||||
@@ -54,6 +55,13 @@ class _PublicProductScreenState extends State<PublicProductScreen> {
|
||||
);
|
||||
final data = (resp.data as Map<String, dynamic>)['data'] as Map<String, dynamic>;
|
||||
setState(() { _data = data; _loading = false; });
|
||||
// 更新浏览器标签标题(Flutter Web 会写 document.title)
|
||||
final name = data['name'] as String? ?? '';
|
||||
if (name.isNotEmpty) {
|
||||
SystemChrome.setApplicationSwitcherDescription(
|
||||
ApplicationSwitcherDescription(label: name, primaryColor: 0xFF8B2331),
|
||||
);
|
||||
}
|
||||
} catch (e) {
|
||||
setState(() { _error = e.toString(); _loading = false; });
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user