add support for json formatted table of contents and specific tpl

Allows for precise control over layout of table of contents so that
theme specific changes can be implemented. Introduced a new layout file
help-index.tpl.
Table of contents is stored in json format within toc.json, support for
toc.html is retained since other languages still use it but can be
migrated to json if needed.
This commit is contained in:
SK
2025-10-19 08:18:43 +05:30
parent 6ad561dc4c
commit 4330e0bb94
5 changed files with 161 additions and 112 deletions

View File

@@ -9,7 +9,7 @@ trait HelpHelperTrait {
// PHP versions before 8.2 does not support trait constants,
// Leave this commented out until we drop support for PHP 8.1.
//
// const VALID_FILE_EXT = ['md', 'bb', 'html'];
// const VALID_FILE_EXT = ['md', 'bb', 'html', 'json'];
private string $file_name = '';
private string $file_type = '';
@@ -58,7 +58,7 @@ trait HelpHelperTrait {
private function find_help_file(string $base_path, string $lang): void {
// Use local variable until we can use trait constants.
$valid_file_ext = ['md', 'bb', 'html'];
$valid_file_ext = ['md', 'bb', 'html', 'json'];
$base_path_with_lang = "doc/{$lang}/${base_path}";

View File

@@ -20,15 +20,30 @@ class Helpindex {
$this->determine_help_language();
$this->find_help_file('toc', $this->lang['language']);
logger('Helpindex file_name=' . var_export($this->file_name,true));
if (! empty($this->file_name)) {
$this->contents = translate_projectname(
file_get_contents($this->file_name)
);
$sections = [];
$this->contents = '';
if (!empty($this->file_name) && is_readable($this->file_name)) {
$json = file_get_contents($this->file_name);
$this->contents = translate_projectname($json);
$decoded = json_decode($json, true);
if (is_array($decoded)) {
$sections = $decoded;
}
} else {
$this->contents = '<em>' . t('No documentation index found.') . '</em>';
}
logger('Helpindex file_name=' . $this->contents);
$tpl = get_markup_template('help-index.tpl');
$tpl = get_markup_template('widget.tpl');
return replace_macros($tpl, [ '$widget' => $this ]);
return replace_macros($tpl, [
'$title' => t('Documentation Index'),
'$sections' => $sections,
'$contents' => $this->contents
]);
}
public function title(): string {

View File

@@ -1,104 +1,58 @@
<div class="" id="accordion">
<div class="mb-3">
<div class="">
<h3 class="panel-title">
Members
</h3>
</div>
<div id="members" class="doco-section">
<div class="vstack">
<a href="/help/member/overview">Overview</a>
<a href="/help/member/registration">Login/Registration</a>
<a href="/help/member/accounts_profiles_channels_basics">Accounts, Profiles and Channels</a>
<a href="/help/member/posting">Posting</a>
<a href="/help/member/the_grid">The Grid</a>
<a href="/help/member/the_stream">The Stream</a>
<a href="/help/member/apps">Apps</a>
<a href="/help/member/connections">Connections</a>
<a href="/help/member/directory">The Directory</a>
<a href="/help/member/blocking_channels">Blocking Channels</a>
<a href="/help/member/permissions">Permissions</a>
<a href="/help/member/direct_messages">Direct Messages</a>
<a href="/help/member/mentions">Mentions</a>
<a href="/help/member/tags">Tags</a>
<a href="/help/member/bookmarks">Bookmarks</a>
<a href="/help/member/search">Search</a>
<a href="/help/member/article">Article</a>
<a href="/help/member/files">Files</a>
<a href="/help/member/chat_rooms">Chat Rooms</a>
<a href="/help/member/guest_access">Guest Access</a>
<a href="/help/member/privacy_groups">Privacy Groupd</a>
<a href="/help/member/calendar">Calendar</a>
<a href="/help/member/addressbook">Address Book</a>
<a href="/help/member/wikis">Wikis</a>
<a href="/help/member/NSFW">Content Warning/NSFW</a>
<a href="/help/member/clone">Clone</a>
<a href="/help/member/websites">Websites</a>
<a href="/help/member/comanche">Comanche Page Description Language</a>
<a href="/help/member/encryption">Encryption</a>
<a href="/help/member/protection_of_privacy">Tips for Protecting Your Privacy</a>
<a href="/help/member/deleting_channel">Deleting a Channel</a>
<a href="/help/member/delete_account">Deleting your account</a>
<hr>
<a href="/help/bugs">Reporting bugs</a>
<a href="/help/member/member_faq">FAQ</a>
</div>
</div>
</div>
<div class="mb-3">
<div class="">
<h3 class="panel-title">
Tutorials
</h3>
</div>
<div id="tutorials" class="doco-section">
<div class="vstack">
<a href="/help/tutorials/step_with_hubzilla">Step by step into the Fediverse with Hubzilla</a>
<a href="/help/tutorials/customise_look">Customise the look of Hubzilla</a>
</div>
</div>
</div>
<div class="mb-3">
<div class="">
<h3 class="panel-title">
Administrators
</h3>
</div>
<div id="administrators" class="doco-section">
<div class="vstack">
<a class="" href="/help/adminmanual/manual_for_administrators">Guide</a>
</div>
</div>
</div>
<div class="mb-3">
<div class="">
<h3 class="panel-title">
Developers
</h3>
</div>
<div id="developers" class="doco-section">
<div class="vstack">
<a class="" href="/help/developer/developers_guide">Guide</a>
<a href="/help/tutorials/derived_theme">Tutorial: Creating a derived theme</a>
</div>
</div>
</div>
<div class="mb-3">
<div class="">
<h3 class="panel-title">
About
</h3>
</div>
<div id="about" class="doco-section">
<div class="vstack">
<a href="/help/about">About Hubzilla</a>
<a href="/help/functions">Functions</a>
<a href="/help/glossary">Glossary</a>
<a href="/help/ui">User interface</a>
<a href="/help/the_hubzilla_project">Project</a>
<a href="/help/credits">Credits</a>
<a href="/help/placeholder">About this hub</a>
</div>
</div>
</div>
</div>
{
"Members": {
"Overview": "/help/member/overview",
"Login/Registration": "/help/member/registration",
"Accounts, Profiles and Channels": "/help/member/accounts_profiles_channels_basics",
"Posting": "/help/member/posting",
"The Grid": "/help/member/the_grid",
"The Stream": "/help/member/the_stream",
"Apps": "/help/member/apps",
"Connections": "/help/member/connections",
"The Directory": "/help/member/directory",
"Blocking Channels": "/help/member/blocking_channels",
"Permissions": "/help/member/permissions",
"Direct Messages": "/help/member/direct_messages",
"Mentions": "/help/member/mentions",
"Tags": "/help/member/tags",
"Bookmarks": "/help/member/bookmarks",
"Search": "/help/member/search",
"Article": "/help/member/article",
"Files": "/help/member/files",
"Chat Rooms": "/help/member/chat_rooms",
"Guest Access": "/help/member/guest_access",
"Privacy Groups": "/help/member/privacy_groups",
"Calendar": "/help/member/calendar",
"Address Book": "/help/member/addressbook",
"Wikis": "/help/member/wikis",
"Content Warning/NSFW": "/help/member/NSFW",
"Clone": "/help/member/clone",
"Websites": "/help/member/websites",
"Comanche Page Description Language": "/help/member/comanche",
"Encryption": "/help/member/encryption",
"Tips for Protecting Your Privacy": "/help/member/protection_of_privacy",
"Deleting a Channel": "/help/member/deleting_channel",
"Deleting your account": "/help/member/delete_account",
"Reporting bugs": "/help/bugs",
"FAQ": "/help/member/member_faq"
},
"Tutorials": {
"Step by step into the Fediverse with Hubzilla": "/help/tutorials/step_with_hubzilla",
"Customise the look of Hubzilla": "/help/tutorials/customise_look"
},
"Administrators": {
"Guide": "/help/adminmanual/manual_for_administrators"
},
"Developers": {
"Guide": "/help/developer/developers_guide",
"Tutorial: Creating a derived theme": "/help/tutorials/derived_theme"
},
"About": {
"About Hubzilla": "/help/about",
"Functions": "/help/functions",
"Glossary": "/help/glossary",
"User interface": "/help/ui",
"Project": "/help/the_hubzilla_project",
"Credits": "/help/credits",
"About this hub": "/help/placeholder"
}
}

58
doc/en/toc.json Normal file
View File

@@ -0,0 +1,58 @@
{
"Members": {
"Overview": "/help/member/overview",
"Login/Registration": "/help/member/registration",
"Accounts, Profiles and Channels": "/help/member/accounts_profiles_channels_basics",
"Posting": "/help/member/posting",
"The Grid": "/help/member/the_grid",
"The Stream": "/help/member/the_stream",
"Apps": "/help/member/apps",
"Connections": "/help/member/connections",
"The Directory": "/help/member/directory",
"Blocking Channels": "/help/member/blocking_channels",
"Permissions": "/help/member/permissions",
"Direct Messages": "/help/member/direct_messages",
"Mentions": "/help/member/mentions",
"Tags": "/help/member/tags",
"Bookmarks": "/help/member/bookmarks",
"Search": "/help/member/search",
"Article": "/help/member/article",
"Files": "/help/member/files",
"Chat Rooms": "/help/member/chat_rooms",
"Guest Access": "/help/member/guest_access",
"Privacy Groups": "/help/member/privacy_groups",
"Calendar": "/help/member/calendar",
"Address Book": "/help/member/addressbook",
"Wikis": "/help/member/wikis",
"Content Warning/NSFW": "/help/member/NSFW",
"Clone": "/help/member/clone",
"Websites": "/help/member/websites",
"Comanche Page Description Language": "/help/member/comanche",
"Encryption": "/help/member/encryption",
"Tips for Protecting Your Privacy": "/help/member/protection_of_privacy",
"Deleting a Channel": "/help/member/deleting_channel",
"Deleting your account": "/help/member/delete_account",
"Reporting bugs": "/help/bugs",
"FAQ": "/help/member/member_faq"
},
"Tutorials": {
"Step by step into the Fediverse with Hubzilla": "/help/tutorials/step_with_hubzilla",
"Customise the look of Hubzilla": "/help/tutorials/customise_look"
},
"Administrators": {
"Guide": "/help/adminmanual/manual_for_administrators"
},
"Developers": {
"Guide": "/help/developer/developers_guide",
"Tutorial: Creating a derived theme": "/help/tutorials/derived_theme"
},
"About": {
"About Hubzilla": "/help/about",
"Functions": "/help/functions",
"Glossary": "/help/glossary",
"User interface": "/help/ui",
"Project": "/help/the_hubzilla_project",
"Credits": "/help/credits",
"About this hub": "/help/placeholder"
}
}

22
view/tpl/help-index.tpl Normal file
View File

@@ -0,0 +1,22 @@
<div class="help-index">
<div id="accordion" class="vstack">
{{if $sections}}
{{foreach $sections as $section => $links}}
<div class="mb-3">
<div>
<h3 class="panel-title">{{$section}}</h3>
</div>
<div id="{{$section|replace:' ':'_'}}" class="doco-section">
<div class="vstack">
{{foreach $links as $label => $url}}
<a href="{{$url}}">{{$label}}</a>
{{/foreach}}
</div>
</div>
</div>
{{/foreach}}
{{else}}
{{$contents}}
{{/if}}
</div>
</div>