Add TOC settings

This commit is contained in:
danpros 2024-02-21 20:03:13 +07:00
commit 844e707452
4 changed files with 93 additions and 11 deletions

View file

@ -58,6 +58,34 @@
</div>
</div>
<br>
<h4>TOC (Table of Contents)</h4>
<hr>
<div class="form-group row">
<label for="toc.label" class="col-sm-2 col-form-label">TOC label</label>
<div class="col-sm-10">
<input type="text" name="-config-toc.label" class="form-control" id="toc.label" value="<?php echo valueMaker(config('toc.label'));?>" placeholder="Table of Contents">
</div>
</div>
<div class="form-group row">
<label class="col-sm-2 col-form-label">TOC initial state</label>
<div class="col-sm-10">
<div class="col-sm-10">
<div class="form-check">
<input class="form-check-input" type="radio" name="-config-toc.state" id="toc.state1" value="open" <?php if (config('toc.state') === 'open'):?>checked<?php endif;?>>
<label class="form-check-label" for="toc.state1">
Open
</label>
</div>
<div class="form-check">
<input class="form-check-input" type="radio" name="-config-toc.state" id="toc.state2" value="close" <?php if (config('toc.state') === 'close'):?>checked<?php endif;?>>
<label class="form-check-label" for="toc.state2">
Close
</label>
</div>
</div>
</div>
</div>
<br>
<h4><?php echo i18n('Comments');?></h4>
<hr>
<p><?php echo i18n('To_using_Disqus_or_Facebook_comment_you_need_to_provide_Disqus_shortname_or_Facebook_App_ID');?></p>

View file

@ -519,7 +519,15 @@ function get_posts($posts, $page = 1, $perpage = 0)
// Get the contents and convert it to HTML
$post->body = MarkdownExtra::defaultTransform(remove_html_comments($content));
$toc = explode('<!--toc-->', $post->body);
if (isset($toc['1'])) {
if (isset($toc['1'])) {
$state = config('toc.state');
if ($state !== 'open') {
$state = 'close';
}
$label = config('toc.label');
if (empty($label)) {
$label = 'Table of Contents';
}
$load = <<<EOF
<script>
document.addEventListener("DOMContentLoaded", function() {
@ -533,7 +541,7 @@ function get_posts($posts, $page = 1, $perpage = 0)
});
</script>
EOF;
$post->body = $toc['0'] . $load . '<div class="toc-wrapper" id="toc-wrapper.post-'.$post->date.'" style="display:none;" ><details><summary title="TOC"><span class="details">Table of Contents</span></summary><div class="inner"><div class="toc" id="toc.post-'.$post->date.'"></div></div></details></div><script src="'. site_url().'system/resources/js/toc.js"></script>' . $toc['1'];
$post->body = $toc['0'] . $load . '<div class="toc-wrapper" id="toc-wrapper.post-'.$post->date.'" style="display:none;" ><details '. $state .'><summary title="TOC"><span class="details">'. $label .'</span></summary><div class="inner"><div class="toc" id="toc.post-'.$post->date.'"></div></div></details></div><script src="'. site_url().'system/resources/js/toc.js"></script>' . $toc['1'];
}
// Convert image tags to figures
@ -601,7 +609,15 @@ function get_pages($pages, $page = 1, $perpage = 0)
$post->body = MarkdownExtra::defaultTransform(remove_html_comments($content));
$toc = explode('<!--toc-->', $post->body);
if (isset($toc['1'])) {
if (isset($toc['1'])) {
$state = config('toc.state');
if ($state !== 'open') {
$state = 'close';
}
$label = config('toc.label');
if (empty($label)) {
$label = 'Table of Contents';
}
$load = <<<EOF
<script>
document.addEventListener("DOMContentLoaded", function() {
@ -615,7 +631,7 @@ function get_pages($pages, $page = 1, $perpage = 0)
});
</script>
EOF;
$post->body = $toc['0'] . $load . '<div class="toc-wrapper" id="toc-wrapper.page-'.$post->slug.'" style="display:none;" ><details><summary title="TOC"><span class="details">Table of Contents</span></summary><div class="inner"><div class="toc" id="toc.page-'.$post->slug.'"></div></div></details></div><script src="'. site_url().'system/resources/js/toc.js"></script>' . $toc['1'];
$post->body = $toc['0'] . $load . '<div class="toc-wrapper" id="toc-wrapper.page-'.$post->slug.'" style="display:none;" ><details '. $state .'><summary title="TOC"><span class="details">'. $label .'</span></summary><div class="inner"><div class="toc" id="toc.page-'.$post->slug.'"></div></div></details></div><script src="'. site_url().'system/resources/js/toc.js"></script>' . $toc['1'];
}
if (config('views.counter') == 'true') {
@ -690,6 +706,14 @@ function get_subpages($sub_pages, $page = 1, $perpage = 0)
$toc = explode('<!--toc-->', $post->body);
if (isset($toc['1'])) {
$state = config('toc.state');
if ($state !== 'open') {
$state = 'close';
}
$label = config('toc.label');
if (empty($label)) {
$label = 'Table of Contents';
}
$load = <<<EOF
<script>
document.addEventListener("DOMContentLoaded", function() {
@ -703,7 +727,7 @@ function get_subpages($sub_pages, $page = 1, $perpage = 0)
});
</script>
EOF;
$post->body = $toc['0'] . $load . '<div class="toc-wrapper" id="toc-wrapper.subpage-'.$post->slug.'" style="display:none;" ><details><summary title="TOC"><span class="details">Table of Contents</span></summary><div class="inner"><div class="toc" id="toc.subpage-'.$post->slug.'"></div></div></details></div><script src="'. site_url().'system/resources/js/toc.js"></script>' . $toc['1'];
$post->body = $toc['0'] . $load . '<div class="toc-wrapper" id="toc-wrapper.subpage-'.$post->slug.'" style="display:none;" ><details '. $state .'><summary title="TOC"><span class="details">'. $label .'</span></summary><div class="inner"><div class="toc" id="toc.subpage-'.$post->slug.'"></div></div></details></div><script src="'. site_url().'system/resources/js/toc.js"></script>' . $toc['1'];
}
if (config('views.counter') == 'true') {
@ -984,7 +1008,15 @@ function read_category_info($category)
$desc->body = MarkdownExtra::defaultTransform(remove_html_comments($content));
$toc = explode('<!--toc-->', $desc->body);
if (isset($toc['1'])) {
if (isset($toc['1'])) {
$state = config('toc.state');
if ($state !== 'open') {
$state = 'close';
}
$label = config('toc.label');
if (empty($label)) {
$label = 'Table of Contents';
}
$load = <<<EOF
<script>
document.addEventListener("DOMContentLoaded", function() {
@ -998,7 +1030,7 @@ function read_category_info($category)
});
</script>
EOF;
$desc->body = $toc['0'] . $load . '<div class="toc-wrapper" id="toc-wrapper.taxonomy-'.$desc->slug.'" style="display:none;" ><details><summary title="TOC"><span class="details">Table of Contents</span></summary><div class="inner"><div class="toc" id="toc.taxonomy-'.$desc->slug.'"></div></div></details></div><script src="'. site_url().'system/resources/js/toc.js"></script>' . $toc['1'];
$desc->body = $toc['0'] . $load . '<div class="toc-wrapper" id="toc-wrapper.taxonomy-'.$desc->slug.'" style="display:none;" ><details '. $state .'><summary title="TOC"><span class="details">'. $label .'</span></summary><div class="inner"><div class="toc" id="toc.taxonomy-'.$desc->slug.'"></div></div></details></div><script src="'. site_url().'system/resources/js/toc.js"></script>' . $toc['1'];
}
$desc->description = get_content_tag("d", $content, get_description($desc->body));
@ -1230,6 +1262,14 @@ function get_author($name)
$toc = explode('<!--toc-->', $author->about);
if (isset($toc['1'])) {
$state = config('toc.state');
if ($state !== 'open') {
$state = 'close';
}
$label = config('toc.label');
if (empty($label)) {
$label = 'Table of Contents';
}
$load = <<<EOF
<script>
document.addEventListener("DOMContentLoaded", function() {
@ -1243,7 +1283,7 @@ function get_author($name)
});
</script>
EOF;
$author->about = $toc['0'] . $load . '<div class="toc-wrapper" id="toc-wrapper.profile-'.$author->slug.'" style="display:none;" ><details><summary title="TOC"><span class="details">Table of Contents</span></summary><div class="inner"><div class="toc" id="toc.profile-'.$author->slug.'"></div></div></details></div><script src="'. site_url().'system/resources/js/toc.js"></script>' . $toc['1'];
$author->about = $toc['0'] . $load . '<div class="toc-wrapper" id="toc-wrapper.profile-'.$author->slug.'" style="display:none;" ><details '. $state .'><summary title="TOC"><span class="details">'. $label .'</span></summary><div class="inner"><div class="toc" id="toc.profile-'.$author->slug.'"></div></div></details></div><script src="'. site_url().'system/resources/js/toc.js"></script>' . $toc['1'];
}
$author->body = $author->about;
@ -1296,7 +1336,15 @@ function get_frontpage()
// Get the contents and convert it to HTML
$front->body = MarkdownExtra::defaultTransform(remove_html_comments($content));
$toc = explode('<!--toc-->', $front->body);
if (isset($toc['1'])) {
if (isset($toc['1'])) {
$state = config('toc.state');
if ($state !== 'open') {
$state = 'close';
}
$label = config('toc.label');
if (empty($label)) {
$label = 'Table of Contents';
}
$load = <<<EOF
<script>
document.addEventListener("DOMContentLoaded", function() {
@ -1310,7 +1358,7 @@ function get_frontpage()
});
</script>
EOF;
$front->body = $toc['0'] . $load . '<div class="toc-wrapper" id="toc-wrapper.page-front" style="display:none;" ><details><summary title="TOC"><span class="details">Table of Contents</span></summary><div class="inner"><div class="toc" id="toc.page-front"></div></div></details></div><script src="'. site_url().'system/resources/js/toc.js"></script>' . $toc['1'];
$front->body = $toc['0'] . $load . '<div class="toc-wrapper" id="toc-wrapper.page-front" style="display:none;" ><details '. $state .'><summary title="TOC"><span class="details">'. $label .'</span></summary><div class="inner"><div class="toc" id="toc.page-front"></div></div></details></div><script src="'. site_url().'system/resources/js/toc.js"></script>' . $toc['1'];
}
} else {
$front->title = 'Welcome';