Files
wordpress-kratos-yang/assets/css/toc.css
T
laoyang cbe0f2dc59 3.2.18: 清明按节气换算、主题内 [TOC] 目录、重建评论区替代 wpDiscuz
三项功能:

1. 清明不再用固定 04-04
   清明是节气,日期在 4/4~4/6 之间浮动。硬编码 04-04 实测 1900-2100
   共 201 年里只有 76 年是对的(约 38%)。改为内嵌逐年表换算真实日期,
   超出 1900-2100 返回 null 明确放弃,不退化成近似值。
   兼容 3.2.17 及以前勾过的 '04-04' 键,升级后勾选不会被静默丢弃。

2. 主题内实现 [TOC]
   文章里写 [TOC],该位置输出本文目录,点击跳到对应标题。
   在 the_content 优先级 9 处理(早于 wpautop 10 / do_shortcode 11),
   保证"补 id"与"扫目录"用的是同一份文本,href 与 id 必然对得上。
   嵌套用深度归一化,h1→h3 跳级不会算错层级。
   scroll-margin-top 声明式让位,原生锚点/外部 #hash/后退全都生效。

3. 重建评论区
   旧实现的问题:列表渲染与 AJAX 渲染各写一份 HTML,已经分叉
   (AJAX 返回的新评论没有回复按钮);<li> 被 <div> 包着,嵌套回复错位。
   现在统一到 yang_comment_html() 单一渲染函数,列表与 AJAX 只差一个
   is-new 类。同时修掉三处真实缺陷:
     · 评论项用 flex 会把 <ol class="yang-children"> 当成第三个 flex 项,
       子评论跑到父评论右侧、正文被挤到 156px、页面横向溢出 75px —— 改 grid
     · 成功提示在 exitReplyMode() 之前设置,被其末尾的 setStatus('','')
       擦掉,用户提交成功却看不到反馈 —— 调整顺序
     · 窄屏媒体查询打不过深层选择器(媒体查询不增加特异性),
       嵌套头像反向变大 —— 补深层覆盖

   与 wpDiscuz 解耦:邮件模块不再无条件 return false(那等于永久关掉
   notify_postauthor 且不报错);插件在场时不加载主题评论资源,
   避免双份表单互抢。

验证:PHP 语法 73/73;_static_qingming 36、_test_toc 53、
_test_comments 62、_test_comments_falsify 17、
_toc_geometry 121、_toc_geometry_falsify 9、
_comments_geometry 98、_comments_geometry_falsify 23,全部 0 失败。
线上端到端 29/0(真实文章渲染目录 + 真实评论数据渲染)。
2026-10-24 01:03:36 +08:00

303 lines
7.1 KiB
CSS
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/*!
* 文章目录(TOC)样式
* Yongquan Yang <yangyq.net>
*
* ── 设计原则 ────────────────────────────────────────────────
* 1. **不抢正文的视觉**:目录是辅助导航,不是内容。所以用浅灰背景、
* 细边框、小字号,让它在页面上"退后一步"。
* 2. **用主题主色**:强调色统一为 #00a2ff,与主题其他强调元素一致。
* 注意主题**没有**定义 CSS 变量(主色是各处硬编码的),所以这里
* 直接写字面值,不要臆造 var(--kratos-primary) 之类的变量 —— 那会
* 静默失效,目录永远是默认灰色,且看不出是哪里错了。
* 3. **移动端友好**:窄屏下缩进减小、字号略小,但不折叠成下拉 ——
* 目录本来就是给长文用的,手机上更需要它。
*/
.yang-toc {
margin: 24px 0;
border: 1px solid #ebeef5;
border-left: 3px solid #00a2ff;
border-radius: 3px;
background-color: #fafbfc;
font-size: 14px;
line-height: 1.6;
}
/* <details> 的默认三角标记去掉,用自己的图标 */
.yang-toc > summary {
list-style: none;
cursor: pointer;
user-select: none;
}
.yang-toc > summary::-webkit-details-marker {
display: none;
}
.yang-toc > summary::marker {
content: "";
}
.yang-toc-head {
display: flex;
align-items: center;
padding: 11px 16px;
color: #303133;
font-weight: 600;
font-size: 15px;
transition: color 0.15s ease;
}
.yang-toc-head:hover {
color: #00a2ff;
}
/* 折叠箭头:用 CSS 画的三角,不依赖图标字体或 SVG 文件 */
.yang-toc > summary .yang-toc-title::before {
content: "";
display: inline-block;
width: 0;
height: 0;
margin-right: 8px;
border-top: 5px solid transparent;
border-bottom: 5px solid transparent;
border-left: 6px solid currentColor;
vertical-align: middle;
transition: transform 0.18s ease;
}
/* 展开时箭头朝下(旋转 90°) */
.yang-toc[open] > summary .yang-toc-title::before {
transform: rotate(90deg);
}
/* 不可折叠时(toggle=0)不显示箭头 */
.yang-toc:not(details) .yang-toc-head .yang-toc-title::before {
display: none;
}
.yang-toc-title {
flex: 0 0 auto;
}
/* 条目数徽标 */
.yang-toc-count {
flex: 0 0 auto;
margin-left: 8px;
padding: 1px 7px;
border-radius: 9px;
background-color: #eef1f6;
color: #909399;
font-weight: 400;
font-size: 12px;
line-height: 1.5;
}
.yang-toc-body {
padding: 0 16px 12px;
}
.yang-toc-list {
margin: 0;
padding-left: 0;
list-style: none;
}
/* 二级以上的列表缩进,并加一条引导线 */
.yang-toc-list .yang-toc-list {
margin-left: 9px;
padding-left: 14px;
border-left: 1px dashed #e2e6ee;
}
.yang-toc-item {
margin: 0;
padding: 0;
list-style: none;
}
.yang-toc-link {
display: flex;
align-items: baseline;
padding: 4px 6px;
border-radius: 3px;
color: #4a4f57;
text-decoration: none;
transition: color 0.15s ease, background-color 0.15s ease;
}
.yang-toc-link:hover,
.yang-toc-link:focus {
background-color: #eef4ff;
color: #00a2ff;
text-decoration: none;
}
/* 序号 */
.yang-toc-num {
flex: 0 0 auto;
min-width: 1.9em;
margin-right: 5px;
color: #a8abb2;
font-variant-numeric: tabular-nums;
font-size: 13px;
}
.yang-toc-text {
flex: 1 1 auto;
overflow: hidden;
text-overflow: ellipsis;
}
/* 层级视觉差异:越深越淡、字号越小 */
.yang-toc-lv3 > .yang-toc-link {
color: #6b7280;
font-size: 13.5px;
}
.yang-toc-lv4 > .yang-toc-link,
.yang-toc-lv5 > .yang-toc-link,
.yang-toc-lv6 > .yang-toc-link {
color: #8b9099;
font-size: 13px;
}
/* 当前阅读位置的条目高亮(JS 加 .is-active) */
.yang-toc-link.is-active {
background-color: #eef4ff;
color: #00a2ff;
font-weight: 600;
}
/* ── 标题锚点:点击跳转后被固定导航栏挡住的问题 ────────────────
* 主题的 .k-nav 是 fixed-top,滚动后固定约 67px 高。
* 纯 CSS 方案是给目标元素加 scroll-margin-top —— 浏览器原生支持,
* 且不依赖 JS(用 #anchor 直接访问、前进后退、外部链接进来都生效)。
*
* 为什么不用 JS 算偏移:JS 方案只在"点了目录"的情况下有效,
* 从外部带 #hash 进来、或按浏览器后退回到锚点时都不会触发。
* scroll-margin-top 是声明式的,所有情况自动生效。
*
* 67px 是导航栏高度;再加 16px 呼吸空间。管理工具栏(admin bar)
* 存在时再往上加,否则锚点会被工具栏盖住。
*/
.yang-toc-target,
.k-main .details .content h1[id],
.k-main .details .content h2[id],
.k-main .details .content h3[id],
.k-main .details .content h4[id],
.k-main .details .content h5[id],
.k-main .details .content h6[id] {
scroll-margin-top: 84px;
}
body.admin-bar .k-main .details .content h1[id],
body.admin-bar .k-main .details .content h2[id],
body.admin-bar .k-main .details .content h3[id],
body.admin-bar .k-main .details .content h4[id],
body.admin-bar .k-main .details .content h5[id],
body.admin-bar .k-main .details .content h6[id] {
scroll-margin-top: 116px;
}
/* 滚动到锚点时轻微闪一下,让用户确认"跳到这里了" */
@keyframes yang-toc-flash {
0%,
100% {
background-color: transparent;
}
30% {
background-color: #fffbe6;
}
}
.yang-toc-flash {
animation: yang-toc-flash 1.1s ease;
}
/* ── 窄屏 ── */
@media screen and (max-width: 768px) {
.yang-toc {
margin: 18px 0;
font-size: 13.5px;
}
.yang-toc-head {
padding: 10px 13px;
font-size: 14px;
}
.yang-toc-body {
padding: 0 10px 10px;
}
.yang-toc-list .yang-toc-list {
margin-left: 4px;
padding-left: 10px;
}
.yang-toc-link {
padding: 5px 5px;
}
.yang-toc-lv3 > .yang-toc-link {
font-size: 13px;
}
}
/* ── 打印:目录展开、去背景、不折行 ────────────────────────── */
@media print {
.yang-toc {
border: 1px solid #ccc;
background: none;
page-break-inside: avoid;
}
.yang-toc-count {
display: none;
}
.yang-toc-link {
color: #000;
}
}
/* ── 暗色主题适配 ──────────────────────────────────────────
* 主题没有内置暗色模式,但用户可能在「自定义 CSS」里加
* prefers-color-scheme。这里跟随同一个媒体查询,避免目录
* 在暗色下变成一块刺眼的白板。
*/
@media (prefers-color-scheme: dark) {
html.yang-dark .yang-toc {
border-color: #303640;
border-left-color: #00a2ff;
background-color: #1d2026;
}
html.yang-dark .yang-toc-head {
color: #d5d9e0;
}
html.yang-dark .yang-toc-count {
background-color: #2a2f38;
color: #8b929d;
}
html.yang-dark .yang-toc-link {
color: #b6bcc6;
}
html.yang-dark .yang-toc-link:hover,
html.yang-dark .yang-toc-link.is-active {
background-color: #252b34;
color: #00a2ff;
}
html.yang-dark .yang-toc-list .yang-toc-list {
border-left-color: #333944;
}
html.yang-dark .yang-toc-num {
color: #767d88;
}
}