From 4899d2b71f8b68e3efcd7bfe9a6e1eae2c00c0c0 Mon Sep 17 00:00:00 2001 From: danpros Date: Thu, 22 Feb 2024 08:03:58 +0700 Subject: [PATCH] Cleanup TOC --- system/includes/functions.php | 24 ++++++++++++------------ system/resources/js/{toc.js => toc.generator.js} | 8 ++++---- 2 files changed, 16 insertions(+), 16 deletions(-) rename system/resources/js/{toc.js => toc.generator.js} (75%) diff --git a/system/includes/functions.php b/system/includes/functions.php index 24a2f57..2818e1b 100644 --- a/system/includes/functions.php +++ b/system/includes/functions.php @@ -522,7 +522,7 @@ function get_posts($posts, $page = 1, $perpage = 0) if (isset($toc['1'])) { $state = config('toc.state'); if ($state !== 'open') { - $state = 'close'; + $state = ''; } $label = config('toc.label'); if (empty($label)) { @@ -541,7 +541,7 @@ function get_posts($posts, $page = 1, $perpage = 0) }); EOF; - $post->body = $toc['0'] . $load . '' . $toc['1']; + $post->body = $toc['0'] . '' . $toc['1']; } // Convert image tags to figures @@ -612,7 +612,7 @@ function get_pages($pages, $page = 1, $perpage = 0) if (isset($toc['1'])) { $state = config('toc.state'); if ($state !== 'open') { - $state = 'close'; + $state = ''; } $label = config('toc.label'); if (empty($label)) { @@ -631,7 +631,7 @@ function get_pages($pages, $page = 1, $perpage = 0) }); EOF; - $post->body = $toc['0'] . $load . '' . $toc['1']; + $post->body = $toc['0'] . '' . $toc['1']; } if (config('views.counter') == 'true') { @@ -708,7 +708,7 @@ function get_subpages($sub_pages, $page = 1, $perpage = 0) if (isset($toc['1'])) { $state = config('toc.state'); if ($state !== 'open') { - $state = 'close'; + $state = ''; } $label = config('toc.label'); if (empty($label)) { @@ -727,7 +727,7 @@ function get_subpages($sub_pages, $page = 1, $perpage = 0) }); EOF; - $post->body = $toc['0'] . $load . '' . $toc['1']; + $post->body = $toc['0'] . '' . $toc['1']; } if (config('views.counter') == 'true') { @@ -1011,7 +1011,7 @@ function read_category_info($category) if (isset($toc['1'])) { $state = config('toc.state'); if ($state !== 'open') { - $state = 'close'; + $state = ''; } $label = config('toc.label'); if (empty($label)) { @@ -1030,7 +1030,7 @@ function read_category_info($category) }); EOF; - $desc->body = $toc['0'] . $load . '' . $toc['1']; + $desc->body = $toc['0'] . '' . $toc['1']; } $desc->description = get_content_tag("d", $content, get_description($desc->body)); @@ -1264,7 +1264,7 @@ function get_author($name) if (isset($toc['1'])) { $state = config('toc.state'); if ($state !== 'open') { - $state = 'close'; + $state = ''; } $label = config('toc.label'); if (empty($label)) { @@ -1283,7 +1283,7 @@ function get_author($name) }); EOF; - $author->about = $toc['0'] . $load . '' . $toc['1']; + $author->about = $toc['0'] . '' . $toc['1']; } $author->body = $author->about; @@ -1339,7 +1339,7 @@ function get_frontpage() if (isset($toc['1'])) { $state = config('toc.state'); if ($state !== 'open') { - $state = 'close'; + $state = ''; } $label = config('toc.label'); if (empty($label)) { @@ -1358,7 +1358,7 @@ function get_frontpage() }); EOF; - $front->body = $toc['0'] . $load . '' . $toc['1']; + $front->body = $toc['0'] . '' . $toc['1']; } } else { $front->title = 'Welcome'; diff --git a/system/resources/js/toc.js b/system/resources/js/toc.generator.js similarity index 75% rename from system/resources/js/toc.js rename to system/resources/js/toc.generator.js index 2b9169b..5e841d9 100644 --- a/system/resources/js/toc.js +++ b/system/resources/js/toc.generator.js @@ -32,16 +32,16 @@ function generateTOC (id) { var headings = [].slice.call(documentRef.body.querySelectorAll(selector)); if (headings && headings.length) { 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'); 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.innerHTML = ''; + anchor.innerHTML = ''; 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; var div = documentRef.createElement('div');