fix: 修复侧边栏目录和TODO溢出问题,增强序号识别
- 修复 part2 和 part3 高度自适应,避免内容溢出窗口 - part2 和 part3 动态分配可用空间(part2 占 60%,part3 占 40%) - 增强序号识别:支持第一、第二、(1)、[1]、I. II. 等格式 - 移除 todo-list-scroll 固定高度限制,改为动态计算
This commit is contained in:
@@ -524,8 +524,35 @@ $(document).on("change" , ".search-filter" , function(e){
|
|||||||
leftbarPart2.classList.add('sticky');
|
leftbarPart2.classList.add('sticky');
|
||||||
if (leftbarPart3) {
|
if (leftbarPart3) {
|
||||||
leftbarPart3.classList.add('sticky');
|
leftbarPart3.classList.add('sticky');
|
||||||
// 动态设置 part2 高度变量
|
// 计算可用空间并分配给 part2 和 part3
|
||||||
|
let viewportHeight = window.innerHeight;
|
||||||
|
let topOffset = argonConfig.headroom !== 'absolute' ? 90 : 20;
|
||||||
|
let availableHeight = viewportHeight - topOffset - 20; // 20px 底部边距
|
||||||
|
|
||||||
|
// 获取 part3 的自然高度(不受限制时的高度)
|
||||||
|
leftbarPart3.style.maxHeight = 'none';
|
||||||
|
let part3NaturalHeight = leftbarPart3.scrollHeight;
|
||||||
|
leftbarPart3.style.maxHeight = '';
|
||||||
|
|
||||||
|
// 最小高度限制
|
||||||
|
let minPart2Height = 150;
|
||||||
|
let minPart3Height = 100;
|
||||||
|
|
||||||
|
// 计算分配
|
||||||
|
let part2Height, part3MaxHeight;
|
||||||
|
if (part3NaturalHeight + minPart2Height <= availableHeight) {
|
||||||
|
// part3 可以完全显示
|
||||||
|
part3MaxHeight = part3NaturalHeight;
|
||||||
|
part2Height = availableHeight - part3NaturalHeight - 10;
|
||||||
|
} else {
|
||||||
|
// 需要按比例分配,part2 占 60%,part3 占 40%
|
||||||
|
part2Height = Math.max(minPart2Height, availableHeight * 0.6);
|
||||||
|
part3MaxHeight = Math.max(minPart3Height, availableHeight - part2Height - 10);
|
||||||
|
}
|
||||||
|
|
||||||
document.documentElement.style.setProperty('--leftbar-part2-height', leftbarPart2.offsetHeight + 10 + 'px');
|
document.documentElement.style.setProperty('--leftbar-part2-height', leftbarPart2.offsetHeight + 10 + 'px');
|
||||||
|
document.documentElement.style.setProperty('--leftbar-part3-height', part3MaxHeight + 'px');
|
||||||
|
document.documentElement.style.setProperty('--leftbar-part3-max-height', part3MaxHeight + 'px');
|
||||||
}
|
}
|
||||||
}else{
|
}else{
|
||||||
//滚动条在顶部 不浮动状态
|
//滚动条在顶部 不浮动状态
|
||||||
|
|||||||
@@ -558,9 +558,9 @@ $author_desc = get_option('argon_sidebar_author_description');
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 检测是否有标题已经带序号(如 "1. xxx" 或 "1.1 xxx")
|
// 检测是否有标题已经带序号
|
||||||
var numberPattern = /^[\d一二三四五六七八九十]+[.、.]\s*/;
|
// 支持格式:1. 1.1 一、二、第一、第二、(1) (一) [1] 等
|
||||||
var hasNumberedHeadings = false;
|
var numberPattern = /^([\d一二三四五六七八九十百千]+[.、.::]\s*|第[一二三四五六七八九十百千\d]+[章节部分条款、]\s*|[(\(【\[]\s*[\d一二三四五六七八九十]+\s*[)\)】\]]\s*|[IVXLCDM]+[.、.]\s*)/;
|
||||||
var numberedCount = 0;
|
var numberedCount = 0;
|
||||||
|
|
||||||
items.forEach(function(item) {
|
items.forEach(function(item) {
|
||||||
@@ -571,7 +571,7 @@ $author_desc = get_option('argon_sidebar_author_description');
|
|||||||
});
|
});
|
||||||
|
|
||||||
// 如果超过一半的标题已有序号,认为文章自带编号
|
// 如果超过一半的标题已有序号,认为文章自带编号
|
||||||
hasNumberedHeadings = numberedCount > items.length / 2;
|
var hasNumberedHeadings = numberedCount > items.length / 2;
|
||||||
|
|
||||||
if (!hasNumberedHeadings) {
|
if (!hasNumberedHeadings) {
|
||||||
// 添加 CSS 计数器样式
|
// 添加 CSS 计数器样式
|
||||||
|
|||||||
18
style.css
18
style.css
@@ -2531,13 +2531,9 @@ html.navbar-absolute #leftbar_part2.sticky {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#leftbar_part2_inner {
|
#leftbar_part2_inner {
|
||||||
|
max-height: calc(100vh - 110px - var(--leftbar-part3-height, 0px));
|
||||||
max-height: calc(100vh - 110px);
|
|
||||||
|
|
||||||
overflow-y: auto;
|
overflow-y: auto;
|
||||||
|
|
||||||
padding: 10px;
|
padding: 10px;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#leftbar_part2_inner::-webkit-scrollbar {
|
#leftbar_part2_inner::-webkit-scrollbar {
|
||||||
@@ -12607,6 +12603,16 @@ article .post-content .huhua a:before {
|
|||||||
position: fixed;
|
position: fixed;
|
||||||
top: calc(80px + var(--leftbar-part2-height, 300px));
|
top: calc(80px + var(--leftbar-part2-height, 300px));
|
||||||
width: 240px;
|
width: 240px;
|
||||||
|
max-height: var(--leftbar-part3-max-height, 50vh);
|
||||||
|
overflow: hidden;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
}
|
||||||
|
|
||||||
|
#leftbar_part3.sticky .card-body {
|
||||||
|
overflow-y: auto;
|
||||||
|
flex: 1;
|
||||||
|
min-height: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
body.leftbar-can-headroom.headroom---unpinned #leftbar_part3.sticky {
|
body.leftbar-can-headroom.headroom---unpinned #leftbar_part3.sticky {
|
||||||
@@ -12706,7 +12712,7 @@ html.navbar-absolute #leftbar_part3.sticky {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.todo-list-scroll {
|
.todo-list-scroll {
|
||||||
max-height: 240px;
|
max-height: none;
|
||||||
overflow-y: auto;
|
overflow-y: auto;
|
||||||
padding-right: 5px;
|
padding-right: 5px;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user