diff --git a/assets/style.css b/assets/style.css index d7463e7..196e6b5 100644 --- a/assets/style.css +++ b/assets/style.css @@ -71,4 +71,8 @@ code { .friend { height: 80px; +} + +html{ + scroll-behavior: smooth; } \ No newline at end of file diff --git a/functions.php b/functions.php index 5e58aa8..8729b67 100644 --- a/functions.php +++ b/functions.php @@ -136,6 +136,32 @@ function exContent($content){ // $2'; // $content = preg_replace($pattern, $replacement, $content); + // 文章 TOC 功能 + // [0]: 完整的匹配

conTent

+ // [1]: 匹配中的数字 2 + // [2]: 匹配中的内容 conTent + if (preg_match_all('/(.*)<\/h\d>/isU', $content, $outarr)){ + $toc_out = ""; + $minlevel = 6; + for ($key=0; $key{$outarr[2][$key]}". substr($ta, strlen($outarr[0][$key])+$tb); + $content = substr($ta, 0, $tb). "". substr($ta, $tb); + // 用伪锚点实现链接偏移。Safari 居然不支持!! + if ($level > $curlevel) $toc_out.=str_repeat("
    \n", $level-$curlevel); + elseif ($level < $curlevel) $toc_out.=str_repeat("
\n", $curlevel-$level); + $curlevel = $level; + $toc_out .= "
  • {$outarr[2][$key]}
  • \n"; + } + + $content = "
    {$toc_out}
    ". $content; + } + return $content; }