3 Commits
Author SHA1 Message Date
gouki 241a04496b fix(term): 清理百度百科摘要的截断结尾
Build and Publish Server / build (push) Successful in 2m6s
Publish Mini Program Dev Version / publish (push) Successful in 3m3s
百度百科 BaikeLemmaCardApi 摘要以 ... 硬截断,出现半截话。
新增 trimTruncatedTail:去掉结尾省略号后,若末句不完整则
回退到最后一个完整句标点(。!?),避免「唐宋时期,冬至...」
这类戛然而止的结尾。仅依赖百度百科,不引入维基,线上可用。
2026-08-18 00:09:12 +00:00
gouki bff792a974 fix(home): 首页排版细节优化
- 宜忌弹窗字体 44→32rpx、收紧间距,20+ 条可完整显示
- 历史上的今天内页年份加粗、文字稍小,修正层级
- 节日速查外页3条/内页10条,佛历开启时并入排序
- 统一「更多」箭头为 >>
2026-08-18 00:08:54 +00:00
gouki 5a5388234a feat(mini): 节气详情排版优化 + 本地开发连线上数据
Publish Mini Program Dev Version / publish (push) Successful in 1m2s
- wiki 页节气详情排版:配图圆角阴影、涵义引言(米黄渐变+红竖条)、
  简介两端对齐、结构化字段列表(红点标签)分块展示
- wiki.js 提取 meaning 单独展示,extraList 排除避免重复
- request.js develop 环境指向线上(本地 8080 被占用且 localhost 受域名校验限制)
- project.config.json 关闭 urlCheck 便于本地开发连线上调试
2026-08-13 23:37:12 +00:00
11 changed files with 194 additions and 33 deletions
+5 -2
View File
@@ -47,6 +47,7 @@ Page({
zoomTitle: '',
zoomType: '',
zoomData: null,
zoomScrollTop: 0,
// 设置
showBuddhist: false,
highlightLunar: true
@@ -97,7 +98,8 @@ Page({
const termTime = dayInfo.solarTerm ? (SOLAR_TERM_TIMES[dayInfo.solarTerm] || '') : '';
const isFirstOrFifteen = this.data.highlightLunar && (dayInfo.lunarDay === 1 || dayInfo.lunarDay === 15);
const nextBuddhist = this.data.showBuddhist ? getNextBuddhistFestival(y, m, d) : null;
const upcoming = getUpcomingFestivals(10, y, m, d);
// 外页只显示最近3条(佛历开启时并入排序);内页弹窗见 openZoom 取10条
const upcoming = getUpcomingFestivals(3, y, m, d, this.data.showBuddhist);
return {
key: fmt(y, m, d),
dayInfo, almanac, legalHoliday, workday, termTime,
@@ -429,7 +431,8 @@ Page({
};
} else if (type === 'fest') {
zoomTitle = '近期节日';
zoomData = { upcoming: dayItem.upcoming };
// 内页显示最近10条(佛历开启时并入排序)
zoomData = { upcoming: getUpcomingFestivals(10, dayInfo.solarYear, dayInfo.solarMonth, dayInfo.solarDay, this.data.showBuddhist) };
} else if (type === 'fest-year') {
zoomTitle = `${dayInfo.solarYear}年节日`;
zoomData = { yearFestivals: getYearFestivals(dayInfo.solarYear) };
+7 -2
View File
@@ -156,7 +156,7 @@
</view>
<view class="otd-foot">
<text class="otd-source">来源:中文维基百科</text>
<text class="otd-more" bindtap="openZoom" data-type="otd" data-date="{{dayItem.key}}">查看完整 </text>
<text class="otd-more" bindtap="openZoom" data-type="otd" data-date="{{dayItem.key}}">查看完整 >></text>
</view>
</view>
<view class="card placeholder-card" wx:elif="{{dayItem.otdLoading}}">
@@ -236,6 +236,7 @@
<text class="zoom-yiji-item ji" wx:for="{{zoomData.avoids}}" wx:key="*this">{{item}}</text>
</view>
</view>
<view class="zoom-end-pad" />
</scroll-view>
<!-- 详情放大 -->
@@ -280,6 +281,7 @@
<text class="zoom-detail-label">彭祖百忌</text>
<text class="zoom-detail-value">{{zoomData.pengZu}}</text>
</view>
<view class="zoom-end-pad" />
</scroll-view>
<!-- 节日放大 -->
@@ -289,15 +291,17 @@
<text class="zoom-fest-date">{{item.solarDate}}</text>
<text class="zoom-fest-left {{item.daysLeft === 0 ? 'is-today' : ''}}">{{item.daysLeft === 0 ? '今天' : '还有' + item.daysLeft + '天'}}</text>
</view>
<view class="zoom-end-pad" />
</scroll-view>
<!-- 今年节日(字体稍小,避免溢出) -->
<scroll-view scroll-y class="zoom-body" wx:if="{{zoomType === 'fest-year' && zoomData}}">
<scroll-view scroll-y class="zoom-body" scroll-top="{{zoomScrollTop}}" wx:if="{{zoomType === 'fest-year' && zoomData}}">
<view class="zoom-fest-year-row" wx:for="{{zoomData.yearFestivals}}" wx:key="name" bindtap="goFestival" data-date="{{item.solarDate}}">
<text class="zoom-fest-year-name">{{item.name}}</text>
<text class="zoom-fest-year-date">{{item.solarMonth}}月{{item.solarDay}}日</text>
<text class="zoom-fest-year-type {{item.type === 'lunar' ? 'lunar' : 'solar'}}">{{item.type === 'lunar' ? '农历' : '公历'}}</text>
</view>
<view class="zoom-end-pad" />
</scroll-view>
<!-- 历史上的今天放大 -->
@@ -330,6 +334,7 @@
</view>
</block>
<view class="zoom-otd-source">数据来源:中文维基百科(CC BY-SA 4.0</view>
<view class="zoom-end-pad" />
</scroll-view>
</view>
</view>
+27 -11
View File
@@ -434,19 +434,23 @@
.zoom-fest-year-name {
font-size: 32rpx;
font-weight: 600;
min-width: 140rpx;
width: 160rpx;
flex-shrink: 0;
}
.zoom-fest-year-date {
font-size: 28rpx;
color: #9E8E7E;
flex: 1;
min-width: 0;
}
.zoom-fest-year-type {
font-size: 22rpx;
padding: 4rpx 16rpx;
border-radius: 999rpx;
flex-shrink: 0;
white-space: nowrap;
}
.zoom-fest-year-type.lunar {
@@ -668,10 +672,18 @@
}
.zoom-body {
width: 100%;
box-sizing: border-box;
padding: 32rpx 28rpx;
max-height: 70vh;
}
/* scroll-view 底部占位:padding-bottom 不计入滚动高度,用真实元素保证最后一项完整显示 */
.zoom-end-pad {
height: 32rpx;
}
/* 宜忌放大 */
.zoom-yiji-block {
margin-bottom: 40rpx;
@@ -695,13 +707,13 @@
.zoom-yiji-items {
display: flex;
flex-wrap: wrap;
gap: 20rpx;
gap: 14rpx;
}
.zoom-yiji-item {
font-size: 44rpx;
padding: 16rpx 32rpx;
border-radius: 16rpx;
font-size: 32rpx;
padding: 12rpx 24rpx;
border-radius: 12rpx;
font-weight: 500;
}
@@ -744,21 +756,24 @@
}
.zoom-fest-name {
font-size: 44rpx;
font-size: 40rpx;
font-weight: 600;
min-width: 200rpx;
flex-shrink: 0;
}
.zoom-fest-date {
font-size: 36rpx;
font-size: 32rpx;
color: #9E8E7E;
flex: 1;
min-width: 0;
}
.zoom-fest-left {
font-size: 36rpx;
font-size: 32rpx;
color: #C41E3A;
font-weight: 500;
flex-shrink: 0;
white-space: nowrap;
}
.zoom-fest-left.is-today {
@@ -874,12 +889,13 @@
}
.zoom-otd-item .otd-year {
font-size: 30rpx;
font-size: 28rpx;
font-weight: 600;
min-width: 120rpx;
}
.zoom-otd-item .otd-text {
font-size: 32rpx;
font-size: 28rpx;
-webkit-line-clamp: unset;
overflow: visible;
}
+12 -1
View File
@@ -56,19 +56,29 @@ const EXTRA_LABELS = [
{ key: 'flower', name: '花信' }
];
// buildExtraList 把服务端 extra JSON 字符串解析为 [{name, value}] 展示列表(仅保留非空项,按定义顺序)
// buildExtraList 把服务端 extra JSON 字符串解析为 [{name, value}] 展示列表(仅保留非空项,按定义顺序meaning 单独展示故排除
function buildExtraList(extraStr) {
if (!extraStr) return [];
let obj = {};
try { obj = JSON.parse(extraStr); } catch (e) { return []; }
const list = [];
EXTRA_LABELS.forEach(f => {
if (f.key === 'meaning') return; // 涵义在引言区单独突出显示
const v = (obj[f.key] || '').trim();
if (v) list.push({ name: f.name, value: v });
});
return list;
}
// extractMeaning 从 extra JSON 中提取涵义(用于引言区突出显示)
function extractMeaning(extraStr) {
if (!extraStr) return '';
try {
const obj = JSON.parse(extraStr);
return (obj.meaning || '').trim();
} catch (e) { return ''; }
}
function buildEntries() {
const entries = [];
@@ -168,6 +178,7 @@ Page({
brief: s.brief,
content: s.content,
image: s.image || '',
meaning: extractMeaning(s.extra),
extraList: buildExtraList(s.extra),
open: false
};
+12 -2
View File
@@ -25,15 +25,25 @@
<text class="badge badge-outline">{{item.catName}}</text>
</view>
<view class="text-sm text-muted mt-1" wx:if="{{!item.open}}">{{item.brief}}</view>
<view class="entry-detail mt-2" wx:if="{{item.open}}">
<view class="entry-detail" wx:if="{{item.open}}">
<!-- 配图(仅服务端条目有图时显示) -->
<image wx:if="{{item.image}}" class="entry-image" src="{{item.image}}" mode="widthFix" lazy-load/>
<!-- 涵义引言(节气有 meaning 时突出显示) -->
<view class="entry-meaning" wx:if="{{item.meaning}}">
<text class="meaning-text">{{item.meaning}}</text>
</view>
<!-- 详细简介 -->
<text class="text-base entry-content">{{item.content}}</text>
<!-- 结构化扩展字段(节气:物候/习俗/养生等) -->
<view class="extra-list" wx:if="{{item.extraList && item.extraList.length > 0}}">
<view class="extra-item" wx:for="{{item.extraList}}" wx:key="name" wx:for-item="field">
<text class="extra-name">{{field.name}}</text>
<view class="extra-name">
<text class="extra-dot"></text>
<text>{{field.name}}</text>
</view>
<text class="extra-value">{{field.value}}</text>
</view>
</view>
+48 -10
View File
@@ -47,35 +47,59 @@
.entry-detail {
border-top: 1rpx solid #F0E6DA;
padding-top: 16rpx;
line-height: 1.7;
margin-top: 16rpx;
padding-top: 20rpx;
}
/* 节气配图 */
.entry-image {
width: 100%;
border-radius: 12rpx;
margin-bottom: 16rpx;
border-radius: 16rpx;
margin-bottom: 20rpx;
background: #F5F0EA;
box-shadow: 0 4rpx 16rpx rgba(74, 64, 54, 0.08);
}
/* 涵义引言(突出显示) */
.entry-meaning {
position: relative;
background: linear-gradient(135deg, #FBF3EC 0%, #F7ECE2 100%);
border-left: 6rpx solid #C41E3A;
border-radius: 8rpx;
padding: 20rpx 24rpx;
margin-bottom: 20rpx;
}
.meaning-text {
font-size: 28rpx;
color: #8C6D4F;
line-height: 1.6;
font-weight: 500;
letter-spacing: 1rpx;
}
/* 详细简介 */
.entry-content {
display: block;
color: #4A4036;
font-size: 28rpx;
line-height: 1.9;
text-align: justify;
letter-spacing: 0.5rpx;
}
/* 结构化扩展字段列表 */
.extra-list {
margin-top: 16rpx;
margin-top: 24rpx;
background: #FBF7F1;
border-radius: 12rpx;
padding: 8rpx 20rpx;
border-radius: 16rpx;
padding: 8rpx 24rpx;
}
.extra-item {
display: flex;
padding: 12rpx 0;
align-items: flex-start;
padding: 16rpx 0;
border-bottom: 1rpx solid #F0E6DA;
}
@@ -85,17 +109,31 @@
.extra-name {
flex-shrink: 0;
width: 140rpx;
width: 150rpx;
display: flex;
align-items: center;
font-size: 26rpx;
color: #A08B76;
font-weight: 500;
padding-top: 2rpx;
}
/* 标签前的小圆点装饰 */
.extra-dot {
display: inline-block;
width: 8rpx;
height: 8rpx;
border-radius: 50%;
background: #C41E3A;
margin-right: 12rpx;
flex-shrink: 0;
}
.extra-value {
flex: 1;
font-size: 26rpx;
color: #4A4036;
line-height: 1.6;
line-height: 1.7;
}
.empty-tip {
+1 -1
View File
@@ -7,7 +7,7 @@
"setting": {
"bundle": false,
"userConfirmedBundleSwitch": false,
"urlCheck": true,
"urlCheck": false,
"scopeDataCheck": false,
"coverView": true,
"es6": true,
+27 -1
View File
@@ -1228,8 +1228,9 @@ function daysBetween(fromY, fromM, fromD, toY, toM, toD) {
/** 获取即将到来的 N 个节日(含基准日之后的)
* baseYear/baseMonth/baseDay 可选,默认今天
* includeBuddhist 为 true 时,把佛教节日也并入一起按倒计时排序
*/
function getUpcomingFestivals(count = 6, baseYear, baseMonth, baseDay) {
function getUpcomingFestivals(count = 6, baseYear, baseMonth, baseDay, includeBuddhist = false) {
const now = new Date();
const y = baseYear || now.getFullYear();
const m = baseMonth || (now.getMonth() + 1);
@@ -1245,6 +1246,7 @@ function getUpcomingFestivals(count = 6, baseYear, baseMonth, baseDay) {
if (diff >= 0) {
list.push({
name: fest.name,
type: fest.type,
solarDate: `${solar.year}-${String(solar.month).padStart(2, '0')}-${String(solar.day).padStart(2, '0')}`,
solarYear: solar.year,
solarMonth: solar.month,
@@ -1256,6 +1258,30 @@ function getUpcomingFestivals(count = 6, baseYear, baseMonth, baseDay) {
}
}
// 佛历节日(开启后并入,统一按倒计时排序)
if (includeBuddhist) {
for (const [key, name] of Object.entries(BUDDHIST_FESTIVALS)) {
const [lm, ld] = key.split('-').map(Number);
for (const tryYear of [y, y + 1]) {
const solar = lunarFestivalToSolar(tryYear, lm, ld);
if (!solar) continue;
const diff = daysBetween(y, m, d, solar.year, solar.month, solar.day);
if (diff >= 0) {
list.push({
name,
type: 'buddhist',
solarDate: `${solar.year}-${String(solar.month).padStart(2, '0')}-${String(solar.day).padStart(2, '0')}`,
solarYear: solar.year,
solarMonth: solar.month,
solarDay: solar.day,
daysLeft: diff
});
break;
}
}
}
}
list.sort((a, b) => a.daysLeft - b.daysLeft);
return list.slice(0, count);
}
+2 -2
View File
@@ -1,9 +1,9 @@
// 网络请求封装
// 按小程序运行环境自动切换后端地址:
// - develop(开发者工具):本地开发服务
// - develop(开发者工具):连线上数据(本地 8080 被其他服务占用,且 localhost 受域名校验限制)
// - trial/release(体验版/正式版):生产域名(需在微信公众平台配置为 request 合法域名)
const API_HOSTS = {
develop: 'http://localhost:8080',
develop: 'https://lunar.neatcn.com',
trial: 'https://lunar.neatcn.com',
release: 'https://lunar.neatcn.com',
};
+32 -1
View File
@@ -247,7 +247,7 @@ func (s *BaikeTermSyncService) syncOneTerm(name string) error {
}
extraJSON, _ := json.Marshal(extra)
content := cleanTermHTML(lemma.Abstract)
content := trimTruncatedTail(cleanTermHTML(lemma.Abstract))
brief := extra["meaning"]
if brief == "" {
brief = firstSentence(content)
@@ -365,3 +365,34 @@ func cleanTermHTML(s string) string {
s = reTermSpace.ReplaceAllString(s, " ")
return strings.TrimSpace(s)
}
// trimTruncatedTail 清理百度百科摘要的截断结尾:
// 摘要以「...」「…」等结尾说明被接口截断,先去掉省略号;
// 若去掉后末句不是完整句(不以 。!? 结尾),回退到最后一个完整句标点,避免半截话
func trimTruncatedTail(s string) string {
// 去掉结尾的省略号(英文 ... / 中文 … / 多个点)
s = strings.TrimRight(s, ".… ")
if s == "" {
return s
}
// 末字符已是完整句标点则无需回退
last := []rune(s)
if len(last) == 0 {
return s
}
if strings.ContainsRune("。!?", last[len(last)-1]) {
return s
}
// 回退到最后一个完整句标点(LastIndex 未找到返回 -1,需先判断 j >= 0
idx := -1
for _, sep := range []string{"。", "", ""} {
if j := strings.LastIndex(s, sep); j >= 0 && j+len(sep) > idx {
idx = j + len(sep)
}
}
if idx > 0 {
return s[:idx]
}
// 没有完整句标点则保留原文(避免清空)
return s
}
@@ -128,3 +128,24 @@ func TestTermSort(t *testing.T) {
t.Errorf("termSort(不存在) = %d, want 0", termSort("不存在"))
}
}
func TestTrimTruncatedTail(t *testing.T) {
cases := []struct {
name string
in string
want string
}{
{"完整句号结尾不动", "夏至后人们普遍食用清补凉汤来避暑。", "夏至后人们普遍食用清补凉汤来避暑。"},
{"英文省略号回退", "表达感谢的心情。唐宋时期,冬至...", "表达感谢的心情。"},
{"中文省略号回退", "表达感谢的心情。唐宋时期,冬至…", "表达感谢的心情。"},
{"无句号半截话保留", "可明显感觉到早春的气...", "可明显感觉到早春的气"},
{"多点省略号", "农事谚语....", "农事谚语"},
{"结尾空白加省略号", "冬至大如年。 ...", "冬至大如年。"},
{"空字符串", "", ""},
}
for _, c := range cases {
if got := trimTruncatedTail(c.in); got != c.want {
t.Errorf("%s: trimTruncatedTail(%q) = %q, want %q", c.name, c.in, got, c.want)
}
}
}