1
0
Fork 0
mirror of https://github.com/sbrl/Pepperminty-Wiki.git synced 2024-11-25 05:22:59 +00:00

Display tag names next to page names in the search results. Fixes #93.

This commit is contained in:
Starbeamrainbowlabs 2017-10-14 22:48:58 +01:00
parent b6f68150b7
commit 73637fe963
6 changed files with 118 additions and 49 deletions

View file

@ -10,6 +10,7 @@ This file holds the changelog for Pepperminty Wiki. This is the master list of t
- Statistics are automagically recalculated every day - this can be controlled with `stats_update_interval` and `stats_update_processingtime`
- Added new "« Parent Page" to subpages so that you can easily visit their parent pages
- Added new `get_page_parent($pagename)` API method.
- Added tags next to the names of pages in the search results
### Fixed
- Fixed invalid opensearch description.

View file

@ -283,6 +283,7 @@ a.redlink:visited { color: rgb(130, 15, 15); /*#8b1a1a*/ }
.search-result::before { content: attr(data-result-number); position: relative; top: 3rem; color: rgba(33, 33, 33, 0.3); font-size: 2rem; }
.search-result::after { content: "Rank: " attr(data-rank); position: absolute; top: 3.8rem; right: 0.7rem; color: rgba(50, 50, 50, 0.3); }
.search-result > h2 { margin-left: 3rem; }
.search-result-badges { font-size: 1rem; font-weight: normal; }
.search-context { max-height: 20em; overflow: hidden; }
.search-context::after { content: ""; position: absolute; bottom: 0; width: 100%; height: 3em; display: block; background: linear-gradient(to bottom, transparent, #faf8fb); pointer-events: none; }
@ -3046,7 +3047,11 @@ register_module([
add_action("history", function() {
global $settings, $env, $pageindex;
$supported_formats = [ "html", "json", "text" ];
$format = $_GET["format"] ?? "html";
switch($format) {
case "html":
$content = "<h1>History for $env->page</h1>\n";
if(!empty($pageindex->{$env->page}->history))
{
@ -3072,6 +3077,31 @@ register_module([
$content .= "<p style='text-align: center;'><em>(None yet! Try editing this page and then coming back here.)</em></p>\n";
}
exit(page_renderer::render_main("$env->page - History - $settings->sitename", $content));
case "json":
$page_history = $pageindex->{$env->page}->history ?? [];
foreach($page_history as &$history_entry) {
unset($history_entry->filename);
}
header("content-type: application/json");
exit(json_encode($page_history, JSON_PRETTY_PRINT));
case "csv":
$page_history = $pageindex->{$env->page}->history ?? [];
header("content-type: text/csv");
echo("revision_id,timestamp,type,editor,newsize,sizediff\n");
foreach($page_history as $hentry) {
echo("$hentry->rid,$hentry->timestamp,$hentry->type,$hentry->editor,$hentry->newsize,$hentry->sizediff\n");
}
exit();
default:
http_response_code(400);
exit(page_renderer::render_main("Format Error - $env->page - History - $settings->sitename", "<p>The format <code>" . htmlentities($format) . "</code> isn't currently supported. Supported formats: html, json, csv"));
}
});
@ -3630,6 +3660,10 @@ register_module([
$context .= "...";
}*/
$tag_list = "<span class='tags'>";
foreach($pageindex->{$result["pagename"]}->tags ?? [] as $tag) $tag_list .= "<a href='?action=list-tags&tag=" . rawurlencode($tag) . "' class='mini-tag'>$tag</a>";
$tag_list .= "</span>\n";
// Make redirect pages italics
if(!empty($pageindex->{$result["pagename"]}->redirect))
$result["pagename"] = "<em>{$result["pagename"]}</em>";
@ -3637,7 +3671,7 @@ register_module([
// We add 1 to $i here to convert it from an index to a result
// number as people expect it to start from 1
$content .= "<div class='search-result' data-result-number='" . ($i + 1) . "' data-rank='" . $result["rank"] . "'>\n";
$content .= " <h2><a href='$link'>" . $result["pagename"] . "</a></h2>\n";
$content .= " <h2><a href='$link'>" . $result["pagename"] . "</a> <span class='search-result-badges'>$tag_list</span></h2>\n";
$content .= " <p class='search-context'>$context</p>\n";
$content .= "</div>\n";

View file

@ -32,7 +32,7 @@
"author": "Starbeamrainbowlabs",
"description": "Adds a 'raw' action that shows you the raw source of a page.",
"id": "action-raw",
"lastupdate": 1507993680,
"lastupdate": 1507993763,
"optional": false
},
{
@ -77,7 +77,7 @@
"author": "Starbeamrainbowlabs",
"description": "Adds the ability to keep unlimited page history, limited only by your disk space. Note that this doesn't store file history (yet). Currently depends on feature-recent-changes for rendering of the history page.",
"id": "feature-history",
"lastupdate": 1497791855,
"lastupdate": 1507994538,
"optional": false
},
{
@ -104,7 +104,7 @@
"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.",
"id": "feature-search",
"lastupdate": 1505838750,
"lastupdate": 1508017313,
"optional": false
},
{

View file

@ -25,7 +25,11 @@ register_module([
add_action("history", function() {
global $settings, $env, $pageindex;
$supported_formats = [ "html", "json", "text" ];
$format = $_GET["format"] ?? "html";
switch($format) {
case "html":
$content = "<h1>History for $env->page</h1>\n";
if(!empty($pageindex->{$env->page}->history))
{
@ -51,6 +55,31 @@ register_module([
$content .= "<p style='text-align: center;'><em>(None yet! Try editing this page and then coming back here.)</em></p>\n";
}
exit(page_renderer::render_main("$env->page - History - $settings->sitename", $content));
case "json":
$page_history = $pageindex->{$env->page}->history ?? [];
foreach($page_history as &$history_entry) {
unset($history_entry->filename);
}
header("content-type: application/json");
exit(json_encode($page_history, JSON_PRETTY_PRINT));
case "csv":
$page_history = $pageindex->{$env->page}->history ?? [];
header("content-type: text/csv");
echo("revision_id,timestamp,type,editor,newsize,sizediff\n");
foreach($page_history as $hentry) {
echo("$hentry->rid,$hentry->timestamp,$hentry->type,$hentry->editor,$hentry->newsize,$hentry->sizediff\n");
}
exit();
default:
http_response_code(400);
exit(page_renderer::render_main("Format Error - $env->page - History - $settings->sitename", "<p>The format <code>" . htmlentities($format) . "</code> isn't currently supported. Supported formats: html, json, csv"));
}
});

View file

@ -205,6 +205,10 @@ register_module([
$context .= "...";
}*/
$tag_list = "<span class='tags'>";
foreach($pageindex->{$result["pagename"]}->tags ?? [] as $tag) $tag_list .= "<a href='?action=list-tags&tag=" . rawurlencode($tag) . "' class='mini-tag'>$tag</a>";
$tag_list .= "</span>\n";
// Make redirect pages italics
if(!empty($pageindex->{$result["pagename"]}->redirect))
$result["pagename"] = "<em>{$result["pagename"]}</em>";
@ -212,7 +216,7 @@ register_module([
// We add 1 to $i here to convert it from an index to a result
// number as people expect it to start from 1
$content .= "<div class='search-result' data-result-number='" . ($i + 1) . "' data-rank='" . $result["rank"] . "'>\n";
$content .= " <h2><a href='$link'>" . $result["pagename"] . "</a></h2>\n";
$content .= " <h2><a href='$link'>" . $result["pagename"] . "</a> <span class='search-result-badges'>$tag_list</span></h2>\n";
$content .= " <p class='search-context'>$context</p>\n";
$content .= "</div>\n";

View file

@ -61,6 +61,7 @@ a.redlink:visited { color: rgb(130, 15, 15); /*#8b1a1a*/ }
.search-result::before { content: attr(data-result-number); position: relative; top: 3rem; color: rgba(33, 33, 33, 0.3); font-size: 2rem; }
.search-result::after { content: "Rank: " attr(data-rank); position: absolute; top: 3.8rem; right: 0.7rem; color: rgba(50, 50, 50, 0.3); }
.search-result > h2 { margin-left: 3rem; }
.search-result-badges { font-size: 1rem; font-weight: normal; }
.search-context { max-height: 20em; overflow: hidden; }
.search-context::after { content: ""; position: absolute; bottom: 0; width: 100%; height: 3em; display: block; background: linear-gradient(to bottom, transparent, #faf8fb); pointer-events: none; }