Browse Source

Cleanup TOC

pull/680/head
danpros 1 year ago
parent
commit
4899d2b71f
2 changed files with 16 additions and 16 deletions
  1. +12
    -12
      system/includes/functions.php
  2. +4
    -4
      system/resources/js/toc.generator.js

+ 12
- 12
system/includes/functions.php View File

@ -522,7 +522,7 @@ function get_posts($posts, $page = 1, $perpage = 0)
if (isset($toc['1'])) { if (isset($toc['1'])) {
$state = config('toc.state'); $state = config('toc.state');
if ($state !== 'open') { if ($state !== 'open') {
$state = 'close';
$state = '';
} }
$label = config('toc.label'); $label = config('toc.label');
if (empty($label)) { if (empty($label)) {
@ -541,7 +541,7 @@ function get_posts($posts, $page = 1, $perpage = 0)
}); });
</script> </script>
EOF; EOF;
$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'];
$post->body = $toc['0'] . '<div class="toc-wrapper" id="toc-wrapper.post-'.$post->date.'" style="display:none;" >'. $load .'<details '. $state .'><summary title="'. $label .'"><span class="details">'. $label .'</span></summary><div class="inner"><div class="toc" id="toc.post-'.$post->date.'"></div></div></details><script src="'. site_url().'system/resources/js/toc.generator.js"></script></div>' . $toc['1'];
} }
// Convert image tags to figures // Convert image tags to figures
@ -612,7 +612,7 @@ function get_pages($pages, $page = 1, $perpage = 0)
if (isset($toc['1'])) { if (isset($toc['1'])) {
$state = config('toc.state'); $state = config('toc.state');
if ($state !== 'open') { if ($state !== 'open') {
$state = 'close';
$state = '';
} }
$label = config('toc.label'); $label = config('toc.label');
if (empty($label)) { if (empty($label)) {
@ -631,7 +631,7 @@ function get_pages($pages, $page = 1, $perpage = 0)
}); });
</script> </script>
EOF; EOF;
$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'];
$post->body = $toc['0'] . '<div class="toc-wrapper" id="toc-wrapper.page-'.$post->slug.'" style="display:none;" >'. $load .'<details '. $state .'><summary title="'. $label .'"><span class="details">'. $label .'</span></summary><div class="inner"><div class="toc" id="toc.page-'.$post->slug.'"></div></div></details><script src="'. site_url().'system/resources/js/toc.generator.js"></script></div>' . $toc['1'];
} }
if (config('views.counter') == 'true') { if (config('views.counter') == 'true') {
@ -708,7 +708,7 @@ function get_subpages($sub_pages, $page = 1, $perpage = 0)
if (isset($toc['1'])) { if (isset($toc['1'])) {
$state = config('toc.state'); $state = config('toc.state');
if ($state !== 'open') { if ($state !== 'open') {
$state = 'close';
$state = '';
} }
$label = config('toc.label'); $label = config('toc.label');
if (empty($label)) { if (empty($label)) {
@ -727,7 +727,7 @@ function get_subpages($sub_pages, $page = 1, $perpage = 0)
}); });
</script> </script>
EOF; EOF;
$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'];
$post->body = $toc['0'] . '<div class="toc-wrapper" id="toc-wrapper.subpage-'.$post->slug.'" style="display:none;" >'. $load .'<details '. $state .'><summary title="'. $label .'"><span class="details">'. $label .'</span></summary><div class="inner"><div class="toc" id="toc.subpage-'.$post->slug.'"></div></div></details><script src="'. site_url().'system/resources/js/toc.generator.js"></script></div>' . $toc['1'];
} }
if (config('views.counter') == 'true') { if (config('views.counter') == 'true') {
@ -1011,7 +1011,7 @@ function read_category_info($category)
if (isset($toc['1'])) { if (isset($toc['1'])) {
$state = config('toc.state'); $state = config('toc.state');
if ($state !== 'open') { if ($state !== 'open') {
$state = 'close';
$state = '';
} }
$label = config('toc.label'); $label = config('toc.label');
if (empty($label)) { if (empty($label)) {
@ -1030,7 +1030,7 @@ function read_category_info($category)
}); });
</script> </script>
EOF; EOF;
$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->body = $toc['0'] . '<div class="toc-wrapper" id="toc-wrapper.taxonomy-'.$desc->slug.'" style="display:none;" >'. $load .'<details '. $state .'><summary title="'. $label .'"><span class="details">'. $label .'</span></summary><div class="inner"><div class="toc" id="toc.taxonomy-'.$desc->slug.'"></div></div></details><script src="'. site_url().'system/resources/js/toc.generator.js"></script></div>' . $toc['1'];
} }
$desc->description = get_content_tag("d", $content, get_description($desc->body)); $desc->description = get_content_tag("d", $content, get_description($desc->body));
@ -1264,7 +1264,7 @@ function get_author($name)
if (isset($toc['1'])) { if (isset($toc['1'])) {
$state = config('toc.state'); $state = config('toc.state');
if ($state !== 'open') { if ($state !== 'open') {
$state = 'close';
$state = '';
} }
$label = config('toc.label'); $label = config('toc.label');
if (empty($label)) { if (empty($label)) {
@ -1283,7 +1283,7 @@ function get_author($name)
}); });
</script> </script>
EOF; EOF;
$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->about = $toc['0'] . '<div class="toc-wrapper" id="toc-wrapper.profile-'.$author->slug.'" style="display:none;" >'. $load .'<details '. $state .'><summary title="'. $label .'"><span class="details">'. $label .'</span></summary><div class="inner"><div class="toc" id="toc.profile-'.$author->slug.'"></div></div></details><script src="'. site_url().'system/resources/js/toc.generator.js"></script></div>' . $toc['1'];
} }
$author->body = $author->about; $author->body = $author->about;
@ -1339,7 +1339,7 @@ function get_frontpage()
if (isset($toc['1'])) { if (isset($toc['1'])) {
$state = config('toc.state'); $state = config('toc.state');
if ($state !== 'open') { if ($state !== 'open') {
$state = 'close';
$state = '';
} }
$label = config('toc.label'); $label = config('toc.label');
if (empty($label)) { if (empty($label)) {
@ -1358,7 +1358,7 @@ function get_frontpage()
}); });
</script> </script>
EOF; EOF;
$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'];
$front->body = $toc['0'] . '<div class="toc-wrapper" id="toc-wrapper.page-front" style="display:none;" >'. $load .'<details '. $state .'><summary title="'. $label .'"><span class="details">'. $label .'</span></summary><div class="inner"><div class="toc" id="toc.page-front"></div></div></details><script src="'. site_url().'system/resources/js/toc.generator.js"></script></div>' . $toc['1'];
} }
} else { } else {
$front->title = 'Welcome'; $front->title = 'Welcome';


system/resources/js/toc.js → system/resources/js/toc.generator.js View File

@ -32,16 +32,16 @@ function generateTOC (id) {
var headings = [].slice.call(documentRef.body.querySelectorAll(selector)); var headings = [].slice.call(documentRef.body.querySelectorAll(selector));
if (headings && headings.length) { if (headings && headings.length) {
headings.forEach(function (heading, index) { headings.forEach(function (heading, index) {
heading.setAttribute('id', 'toc-' + heading.textContent.replace(/\s+/g, '-').toLowerCase());
heading.setAttribute('id', heading.textContent.replace(/\s+/g, '-').toLowerCase() + id);
heading.setAttribute('class', 'toc-link'); heading.setAttribute('class', 'toc-link');
var anchor = documentRef.createElement('a'); var anchor = documentRef.createElement('a');
anchor.setAttribute('href', '#toc-' + heading.textContent.replace(/\s+/g, '-').toLowerCase());
anchor.setAttribute('href', '#' + heading.textContent.replace(/\s+/g, '-').toLowerCase() + id);
anchor.setAttribute('class', 'anchor'); anchor.setAttribute('class', 'anchor');
anchor.innerHTML = '<svg fill="currentColor" viewBox="0 0 24 24" height="20" xmlns="http://www.w3.org/2000/svg"><path d="M0 0h24v24H0z" fill="none"></path><path d="M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z"></path></svg>';
anchor.innerHTML = '<svg fill="currentColor" class="toc-icon" viewBox="0 0 24 24" height="20" xmlns="http://www.w3.org/2000/svg"><path d="M0 0h24v24H0z" fill="none"></path><path d="M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z"></path></svg>';
var link = documentRef.createElement('a'); var link = documentRef.createElement('a');
link.setAttribute('href', '#toc-' + heading.textContent.replace(/\s+/g, '-').toLowerCase());
link.setAttribute('href', '#' + heading.textContent.replace(/\s+/g, '-').toLowerCase() + id);
link.textContent = heading.textContent; link.textContent = heading.textContent;
var div = documentRef.createElement('div'); var div = documentRef.createElement('div');

Loading…
Cancel
Save