From dc63d9892594be06e80666f9cd3558b0624585e4 Mon Sep 17 00:00:00 2001
From: Starbeamrainbowlabs <sbrl@starbeamrainbowlabs.com>
Date: Sat, 24 Aug 2019 20:05:06 +0100
Subject: [PATCH] Add table of contents to help page

---
 Changelog.md          |  1 +
 module_index.json     |  4 ++--
 modules/page-help.php | 19 +++++++++++--------
 3 files changed, 14 insertions(+), 10 deletions(-)

diff --git a/Changelog.md b/Changelog.md
index 0411230..4c50a2f 100644
--- a/Changelog.md
+++ b/Changelog.md
@@ -7,6 +7,7 @@ This file holds the changelog for Pepperminty Wiki. This is the master list of t
 ### Fixed
  - Fixed a bug in the search query performance metrics
  - Fill out the statistics help text
+ - Added table of contents to help page
 
 ### Changed
  - Made `build.sh` build script more robust, especially when generating the documentation.
diff --git a/module_index.json b/module_index.json
index f2d4bc6..dc49371 100755
--- a/module_index.json
+++ b/module_index.json
@@ -135,7 +135,7 @@
         "version": "0.10",
         "author": "Starbeamrainbowlabs",
         "description": "Adds proper search functionality to Pepperminty Wiki using an inverted index to provide a full text search engine. If pages don't show up, then you might have hit a stop word. If not, try requesting the `invindex-rebuild` action to rebuild the inverted index from scratch.",
-        "lastupdate": 1566672916,
+        "lastupdate": 1566672942,
         "optional": false,
         "extra_data": []
     },
@@ -237,7 +237,7 @@
         "version": "0.9.4",
         "author": "Starbeamrainbowlabs",
         "description": "Adds a rather useful help page. Access through the 'help' action. This module also exposes help content added to Pepperminty Wiki's inbuilt invisible help section system.",
-        "lastupdate": 1566498566,
+        "lastupdate": 1566673434,
         "optional": false,
         "extra_data": []
     },
diff --git a/modules/page-help.php b/modules/page-help.php
index 57a72d3..61a12b3 100644
--- a/modules/page-help.php
+++ b/modules/page-help.php
@@ -31,8 +31,7 @@ register_module([
 			// Sort the help sections by key
 			ksort($help_sections, SORT_NATURAL);
 			
-			if(isset($_GET["dev"]) and $_GET["dev"] == "yes")
-			{
+			if(isset($_GET["dev"]) and $_GET["dev"] == "yes") {
 				$title = "Developers Help - $settings->sitename";
 				$content = "<p>$settings->sitename runs on Pepperminty Wiki, an entire wiki packed into a single file. This page contains some information that developers may find useful.</p>
 				<p>A full guide to developing a Pepperminty Wiki module can be found <a href='//github.com/sbrl/Pepperminty-Wiki/blob/master/Module_API_Docs.md#module-api-documentation'>on GitHub</a>.</p>
@@ -117,21 +116,25 @@ register_module([
 				$content .= "<div class='stacked-bar-part' style='flex: $wikiSize->other; background: hsla(62, 55%, 90%, 0.6)'>Other: " . human_filesize($wikiSize->other) . "</div>\n";
 				$content .= "</div>";
 			}
-			else
-			{
+			else {
 				$title = "Help - $settings->sitename";
 				
 				$content = "	<h1>$settings->sitename Help</h1>
 		<p>Welcome to $settings->sitename!</p>
-		<p>$settings->sitename is powered by Pepperminty Wiki, a complete wiki in a box you can drop into your server and expect it to just <em>work</em>.</p>";
+		<p>$settings->sitename is powered by Pepperminty Wiki, a complete wiki in a box you can drop into your server and expect it to just <em>work</em>.</p>
+		
+		<h2 id='contents' class='help-section-header'>Contents</h2>
+		<ol>";
+			foreach($help_sections as $index => $section)
+				$content .= "<li><a href='#{$index}'>{$section["title"]}</a></li>\n";
 				
+			$content .= "</ol>\n";
 				// Todo Insert a table of contents here?
 				
-				foreach($help_sections as $index => $section)
-				{
+				foreach($help_sections as $index => $section) {
 					// Todo add a button that you can click to get a permanent link
 					// to this section.
-					$content .= "<h2 id='$index' class='help-section-header'>" . $section["title"] . "</h2>\n";
+					$content .= "<h2 id='$index' class='help-section-header'>{$section["title"]}</h2>\n";
 					$content .= $section["content"] . "\n";
 				}
 			}
