Files
maupassant-hugo/layouts/partials/toc.html
T
Harukawa Sayaka ffbc4c07a0 feat: 自动隐藏文章目录/站点副标题为空时隐藏竖线 (#144)
* format code, hide post-toc when it's empty

* 当subtitle为空时去掉title后面的竖线
2022-02-09 10:19:33 +08:00

100 lines
2.7 KiB
HTML

{{ if or .Params.toc (and .Site.Params.toc (ne .Params.toc false)) -}}
<style type="text/css">
.post-toc {
position: fixed;
width: 200px;
margin-left: -210px;
padding: 5px 10px;
font-family: Athelas, STHeiti, Microsoft Yahei, serif;
font-size: 12px;
border: 1px solid rgba(0, 0, 0, .07);
border-radius: 5px;
background-color: rgba(255, 255, 255, 0.98);
background-clip: padding-box;
-webkit-box-shadow: 1px 1px 2px rgba(0, 0, 0, .125);
box-shadow: 1px 1px 2px rgba(0, 0, 0, .125);
word-wrap: break-word;
white-space: nowrap;
-webkit-box-sizing: border-box;
box-sizing: border-box;
z-index: 999;
cursor: pointer;
max-height: 70%;
overflow-y: auto;
overflow-x: hidden;
}
.post-toc .post-toc-title {
width: 100%;
margin: 0 auto;
font-size: 20px;
font-weight: 400;
text-transform: uppercase;
text-align: center;
}
.post-toc .post-toc-content {
font-size: 15px;
}
.post-toc .post-toc-content>nav>ul {
margin: 10px 0;
}
.post-toc .post-toc-content ul {
padding-left: 20px;
list-style: square;
margin: 0.5em;
line-height: 1.8em;
}
.post-toc .post-toc-content ul ul {
padding-left: 15px;
display: none;
}
@media print,
screen and (max-width:1057px) {
.post-toc {
display: none;
}
}
</style>
<div class="post-toc" style="position: absolute; top: 188px;">
<h2 class="post-toc-title">文章目录</h2>
<div class="post-toc-content">
{{.TableOfContents}}
</div>
</div>
<script type="text/javascript">
$(document).ready(function () {
var postToc = $(".post-toc");
if (postToc.length) {
var leftPos = $("#main").offset().left;
if (leftPos < 220) {
postToc.css({ "width": leftPos - 10, "margin-left": (0 - leftPos) })
}
var t = postToc.offset().top - 20,
a = {
start: {
position: "absolute",
top: t
},
process: {
position: "fixed",
top: 20
},
};
$(window).scroll(function () {
var e = $(window).scrollTop();
e < t ? postToc.css(a.start) : postToc.css(a.process)
})
}
if ($("#TableOfContents").children().length < 1) {
$(".post-toc").remove();
}
})
</script>
{{- end }}