Add primitive page that lists *all* tags at ?action=list-tags.

This commit is contained in:
Starbeamrainbowlabs 2015-11-09 07:37:38 +00:00
parent 97391466ed
commit 6217cbb6c0
3 changed files with 43 additions and 9 deletions

View File

@ -2683,12 +2683,29 @@ register_module([
add_action("list-tags", function() {
global $pageindex, $settings;
if(empty($_GET["tag"]))
if(!isset($_GET["tag"]))
{
http_response_code(301);
header("location: ?action=list");
// Render a list of all tags
$all_tags = [];
foreach($pageindex as $entry)
{
if(!isset($entry->tags)) continue;
foreach($entry->tags as $tag)
{
if(!in_array($tag, $all_tags)) $all_tags[] = $tag;
}
}
$content = "<h1>All tags</h1>
<ul>\n";
foreach($all_tags as $tag)
{
$content .= " <li><a href='?action=list_tags&tag=" . rawurlencode($tag) . "'>$tag</a></li>\n";
}
$content .= "</ul>";
exit(page_renderer::render("All tags - $settings->sitename", $content));
}
$tag = $_GET["tag"];

View File

@ -113,7 +113,7 @@
"author": "Starbeamrainbowlabs",
"description": "Adds a page that lists all the pages in the index along with their metadata.",
"id": "page-list",
"lastupdate": 1445787342,
"lastupdate": 1447054618,
"optional": false
},
{

View File

@ -22,12 +22,29 @@ register_module([
add_action("list-tags", function() {
global $pageindex, $settings;
if(empty($_GET["tag"]))
if(!isset($_GET["tag"]))
{
http_response_code(301);
header("location: ?action=list");
// Render a list of all tags
$all_tags = [];
foreach($pageindex as $entry)
{
if(!isset($entry->tags)) continue;
foreach($entry->tags as $tag)
{
if(!in_array($tag, $all_tags)) $all_tags[] = $tag;
}
}
$content = "<h1>All tags</h1>
<ul>\n";
foreach($all_tags as $tag)
{
$content .= " <li><a href='?action=list_tags&tag=" . rawurlencode($tag) . "'>$tag</a></li>\n";
}
$content .= "</ul>";
exit(page_renderer::render("All tags - $settings->sitename", $content));
}
$tag = $_GET["tag"];