OSDN Git Service

search2: Shor page summary
authorumorigu <umorigu@gmail.com>
Sun, 24 Sep 2017 13:09:30 +0000 (22:09 +0900)
committerumorigu <umorigu@gmail.com>
Sun, 24 Sep 2017 13:09:30 +0000 (22:09 +0900)
skin/pukiwiki.css
skin/search2.js
skin/tdiary.css

index 6aadc7a..7dde240 100644 (file)
@@ -642,12 +642,19 @@ tr.bugtrack_state_undef td {
 }
 
 /* search2.inc.php  */
-input#_plugin_search2_detail:checked ~ ul > pre {
+input#_plugin_search2_detail:checked ~ ul > div.search-result-detail {
        display: block;
 }
-input#_plugin_search2_detail ~ ul > pre {
+input#_plugin_search2_detail ~ ul > div.search-result-detail {
        display: none;
 }
+.search-result-page-summary {
+       font-size: 70%;
+       color: gray;
+       overflow: hidden;
+       text-overflow: ellipsis;
+       white-space: nowrap;
+}
 
 @media print {
   a:link,
index e71e397..cd0d142 100644 (file)
@@ -148,14 +148,23 @@ window.addEventListener && window.addEventListener('DOMContentLoaded', function(
         } else {
           updatedAt = val.updated_at;
         }
-        li.innerHTML = '<a href="' + href + '">' + decoratedName + '</a> ' + getPassage(now, updatedAt);
+        var liHtml = '<a href="' + href + '">' + decoratedName + '</a> ' +
+          getPassage(now, updatedAt);
+        li.innerHTML = liHtml;
         fragment.appendChild(li);
+        var div = document.createElement('div');
+        div.classList.add('search-result-detail');
+        var head = document.createElement('div');
+        head.classList.add('search-result-page-summary');
+        head.innerHTML = escapeHTML(getBodySummary(val.body));
+        div.appendChild(head);
         var summary = getSummary(val.body, searchRegex);
         for (var i = 0; i < summary.length; i++) {
           var pre = document.createElement('pre');
           pre.innerHTML = summary[i].lines.join('\n');
-          fragment.appendChild(pre);
+          div.appendChild(pre);
         }
+        fragment.appendChild(div);
         ul.appendChild(fragment);
       });
       if (!obj.search_done && obj.next_start_index) {
@@ -362,6 +371,40 @@ window.addEventListener && window.addEventListener('DOMContentLoaded', function(
         }
       }
     }
+    function getBodySummary(body) {
+      var lines = body.split('\n');
+      var isInAuthorHeader = true;
+      var summary = [];
+      var lineCount = 0;
+      for (var index = 0, length = lines.length; index < length; index++) {
+        var line = lines[index];
+        if (isInAuthorHeader) {
+          // '#author line is not search target'
+          if (line.match(/^#author\(/)) {
+            // Remove this line from search target
+            continue;
+          } else if (line.match(/^#freeze(\W|$)/)) {
+            continue;
+            // Still in header
+          } else {
+            // Already in body
+            isInAuthorHeader = false;
+          }
+        }
+        line = line.replace(/^\s+|\s+$/g, '');
+        if (line.length === 0) continue; // Empty line
+        if (line.match(/^#\w+/)) continue; // Block-type plugin
+        if (line.match(/^\/\//)) continue; // Comment
+        if (line.substr(0, 1) === '*') {
+          line = line.replace(/\s*\[\#\w+\]$/, ''); // Remove anchor
+        }
+        summary.push(line);
+        if (summary.length >= 10) {
+          continue;
+        }
+      }
+      return summary.join(' ').substring(0, 150);
+    }
     function removeEncodeHint() {
       var form = document.querySelector('form');
       if (form && form.encode_hint && (typeof form.encode_hint.removeAttribute === 'function')) {
index 06657cb..bbd2f09 100644 (file)
@@ -518,12 +518,19 @@ tr.bugtrack_state_undef td {
 }
 
 /* search2.inc.php  */
-input#_plugin_search2_detail:checked ~ ul > pre {
+input#_plugin_search2_detail:checked ~ ul > div.search-result-detail {
        display: block;
 }
-input#_plugin_search2_detail ~ ul > pre {
+input#_plugin_search2_detail ~ ul > div.search-result-detail {
        display: none;
 }
+.search-result-page-summary {
+       font-size: 70%;
+       color: gray;
+       overflow: hidden;
+       text-overflow: ellipsis;
+       white-space: nowrap;
+}
 
 @media print {
   img#logo,