fix(single): align author-bar publish time with the reference
The publish time under the author name diverged from the reference in four ways: it rendered a leading bullet from `.icon-circle`, its tooltip opened above instead of below, its wording was "2 天发布" (WordPress' human_time_diff has no 前 and keeps spaces), and it ignored the 「时间显示数据源」 setting entirely. - markup: drop `.icon-circle` from the time span and the description fallback; add `data-placement="bottom"` so the tooltip opens below like the reference - wording: use jio_time_ago() (which already ends in 前) and append only 发布 / 更新, yielding "2天前发布" - branches: mirror zib_get_post_time_tooltip exactly (date source → publish time; unpublished → modified time; published-with-update → modified time labelled 更新 while the tooltip keeps the publish time; otherwise publish) - the setting is read from post_time_source via get_post_list_style_settings() Tests: new author-bar-time suite drives the real template through a stub harness across all four branches (4/4); widget suite 833/834 with the pre-existing frontend-lifecycle failure. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
f14e6bd88d
commit
f6fde18857
3 files changed
+208
-11
No files matched your search
@@ -0,0 +1,69 @@
|
||||
'use strict';
|
||||
/**
|
||||
* 文章页作者栏「发布时间」契约(对齐参考主题 zib_get_post_time_tooltip):
|
||||
* 纯文本相对时间 + data-placement="bottom" 的 tooltip,不渲染列表圆点前缀,
|
||||
* 且按参考的四个分支决定显示发布时间还是更新时间。
|
||||
*/
|
||||
const assert = require('node:assert/strict');
|
||||
const fs = require('node:fs');
|
||||
const path = require('node:path');
|
||||
const test = require('node:test');
|
||||
const { spawnSync } = require('node:child_process');
|
||||
|
||||
const root = path.resolve(__dirname, '..', '..');
|
||||
const read = (file) => fs.readFileSync(path.join(root, file), 'utf8');
|
||||
const authorBar = read('templates/parts/single-author-bar.php');
|
||||
|
||||
test('作者栏时间与参考主题同构:tooltip 在下方、无 icon-circle 圆点', () => {
|
||||
assert.match(
|
||||
authorBar,
|
||||
/<span data-toggle="tooltip" data-placement="bottom" title="<\?php echo esc_attr\(\$abs_fmt\); \?>"><\?php echo esc_html\(\$time_text\); \?><\/span>/,
|
||||
'时间必须是无前缀圆点的 <span>,tooltip 置于下方'
|
||||
);
|
||||
assert.doesNotMatch(authorBar, /<span class="icon-circle"[^>]*data-toggle="tooltip"/, '作者栏时间不得再带 icon-circle 圆点');
|
||||
assert.doesNotMatch(authorBar, /<span class="icon-circle">/, '隐藏时间后的作者简介同样不应带圆点');
|
||||
});
|
||||
|
||||
test('相对时间文案不重复「前」,与参考一致', () => {
|
||||
assert.match(authorBar, /\$time_text = \$time_ago \. \$rel_label;/, '时间文案应为「相对时间 + 发布/更新」');
|
||||
assert.match(authorBar, /function_exists\('jio_time_ago'\)[\s\S]{0,160}: human_time_diff\(/, '缺少 jio_time_ago 时才回退 human_time_diff');
|
||||
assert.doesNotMatch(
|
||||
authorBar,
|
||||
/human_time_diff\(\$rel_base, \(int\) current_time\('timestamp'\)\) \. \$rel_label/,
|
||||
'不得再用裸 human_time_diff 拼接,会少「前」字'
|
||||
);
|
||||
});
|
||||
|
||||
test('时间分支复刻参考:数据源 / 非发布 / 有更新 三种判定', () => {
|
||||
assert.match(authorBar, /get_post_list_style_settings\(\)/, '时间源应读取列表风格设置');
|
||||
assert.match(authorBar, /\$has_update = \(int\) strtotime\(\$modified_mysql\) > \(int\) strtotime\(\$published_mysql\);/, '以时间戳比较判断是否更新过');
|
||||
|
||||
const dateBranch = authorBar.match(/if \(\$time_source === 'date'\) \{[\s\S]*?\n\}/);
|
||||
assert.ok(dateBranch, '缺少 date 数据源分支');
|
||||
assert.match(dateBranch[0], /\$time_mysql = \$published_mysql;/, 'date 源固定用发布时间');
|
||||
assert.match(dateBranch[0], /\$abs_fmt = \$published_title;/, 'date 源 tooltip 标注发布');
|
||||
|
||||
const unpublished = authorBar.match(/\} elseif \(!\$is_published\) \{[\s\S]*?\n\}/);
|
||||
assert.ok(unpublished, '缺少非发布状态分支');
|
||||
assert.match(unpublished[0], /\$time_mysql = \$modified_mysql;/, '非发布状态用更新时间');
|
||||
assert.match(unpublished[0], /\$abs_fmt = \$modified_title;/, '非发布状态 tooltip 标注更新');
|
||||
|
||||
const updated = authorBar.match(/\} elseif \(\$has_update\) \{[\s\S]*?\n\}/);
|
||||
assert.ok(updated, '缺少「有更新」分支');
|
||||
assert.match(updated[0], /\$time_mysql = \$modified_mysql;/, '有更新时展示更新时间的相对值');
|
||||
// 参考主题此分支的 tooltip 仍标注发布时间,保持逐字一致。
|
||||
assert.match(updated[0], /\$abs_fmt = \$published_title;/, '有更新的已发布文章 tooltip 仍标注发布时间');
|
||||
assert.doesNotMatch(updated[0], /\$modified_title/, '该分支不应在 tooltip 标注更新');
|
||||
});
|
||||
|
||||
test('作者栏时间渲染:四分支输出与参考组合一致', () => {
|
||||
const harness = path.join(__dirname, 'author-bar-time-harness.php');
|
||||
const result = spawnSync(process.env.PHP_BINARY || 'php', [harness], { cwd: root, encoding: 'utf8' });
|
||||
assert.equal(result.status, 0, result.stderr || result.stdout);
|
||||
const cases = JSON.parse(result.stdout);
|
||||
|
||||
assert.deepEqual(cases['date_updated'], { text: '5天前发布', title: '2026年10月29日 08:00发布' });
|
||||
assert.deepEqual(cases['modified_clean'], { text: '5天前发布', title: '2026年10月29日 08:00发布' });
|
||||
assert.deepEqual(cases['modified_updated'], { text: '1天前更新', title: '2026年10月29日 08:00发布' });
|
||||
assert.deepEqual(cases['draft'], { text: '1天前更新', title: '2026年11月02日 09:00更新' });
|
||||
});
|
||||
Reference in new issue
Block a user