Better Toc and add gotop link

This commit is contained in:
Knah Tsaeb 2020-10-13 17:20:49 +02:00
parent 47f0f2e90c
commit e47a6e4795
3 changed files with 16 additions and 8 deletions

View File

@ -1,6 +1,6 @@
{ {
"require": { "require": {
"erusev/parsedown": "^1.7", "erusev/parsedown": "^1.7",
"keinos/parsedown-toc": "dev-master" "hoegh/parsedown-toc": "^1.3"
} }
} }

View File

@ -8,16 +8,20 @@
"menu main toc" "menu main toc"
"footer footer footer"; "footer footer footer";
} }
.toc>* {
position: fixed;
} }
html {
scroll-behavior: smooth;
} }
body { body {
max-width: 1000px; max-width: 1000px;
} }
.backTop {
content: "test";
}
.menu { .menu {
grid-area: menu; grid-area: menu;
font-size: .9rem; font-size: .9rem;
@ -30,6 +34,7 @@ body {
.toc { .toc {
grid-area: toc; grid-area: toc;
font-size: .9rem; font-size: .9rem;
overflow: scroll;
} }
.toc ul { .toc ul {

View File

@ -26,13 +26,16 @@ if (empty($file) || !file_exists('content/' . urldecode($dir) . '/' . urldecode(
$Parsedown = new ParsedownToc(); $Parsedown = new ParsedownToc();
$content = file_get_contents('content/' . urldecode($dir) . '/' . urldecode($file) . '.md'); $content = file_get_contents('content/' . urldecode($dir) . '/' . urldecode($file) . '.md');
$options = array('selectors' => array('h2', 'h3'));
$Parsedown = new ParsedownToc(); $Parsedown = new ParsedownToc($options);
$body = $Parsedown->text($content); $body = $Parsedown->text($content);
$toc = $Parsedown->contentsList(); $toc = $Parsedown->contentsList();
$body = str_replace("[ ]", '<input type="checkbox" disabled>', $body); $body = str_replace("[ ]", '<input type="checkbox" disabled>', $body);
$body = str_replace("[x]", '<input type="checkbox" checked disabled>', $body); $body = str_replace("[x]", '<input type="checkbox" checked disabled>', $body);
$body = str_replace("</h2>", ' <a href="#" class="backTop">⬆️</a></h2>', $body);
$body = str_replace("</h3>", ' <a href="#" class="backTop">⬆️</a></h3>', $body);
require 'tpl/header.html'; require 'tpl/header.html';
require 'tpl/aside.html'; require 'tpl/aside.html';