public inbox for gentoo-commits@lists.gentoo.org
 help / color / mirror / Atom feed
From: "Göktürk Yüksek" <gokturk@gentoo.org>
To: gentoo-commits@lists.gentoo.org
Subject: [gentoo-commits] proj/devmanual:master commit in: /
Date: Thu, 19 Dec 2019 21:02:44 +0000 (UTC)	[thread overview]
Message-ID: <1576788769.7f13e9b5f59ee496db5b8af7ab093a17c8f76066.gokturk@gentoo> (raw)

commit:     7f13e9b5f59ee496db5b8af7ab093a17c8f76066
Author:     Lucas Ramage <ramage.lucas <AT> protonmail <DOT> com>
AuthorDate: Thu Apr 11 19:21:27 2019 +0000
Commit:     Göktürk Yüksek <gokturk <AT> gentoo <DOT> org>
CommitDate: Thu Dec 19 20:52:49 2019 +0000
URL:        https://gitweb.gentoo.org/proj/devmanual.git/commit/?id=7f13e9b5

Implement search functionality via lunr.js

Bug: https://bugs.gentoo.org/674378
Signed-off-by: Lucas Ramage <ramage.lucas <AT> protonmail.com>
Signed-off-by: Göktürk Yüksek <gokturk <AT> gentoo.org>

 .gitignore      |  1 +
 Makefile        |  6 +++++-
 devbook.xsl     | 48 +++++++++++++++++++++++++++++++++++++++++++++
 search.js       | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 search_index.py | 26 +++++++++++++++++++++++++
 5 files changed, 140 insertions(+), 1 deletion(-)

diff --git a/.gitignore b/.gitignore
index 720d4d6..ce644c7 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,3 +1,4 @@
 *.html
 *.png
+documents.js
 eclass-reference/

diff --git a/Makefile b/Makefile
index 61daef4..4a52cc0 100644
--- a/Makefile
+++ b/Makefile
@@ -19,6 +19,10 @@ prereq:
 	{ echo "dev-libs/libxml2 is required" >&2;\
 	  exit 1; }
 
+index:
+	@echo -n "var documents = " > documents.js
+	@./search_index.py text.xml >> documents.js
+
 %.png : %.svg
 	convert $< $@
 
@@ -42,6 +46,6 @@ validate: prereq
 	  && echo "xmllint validation successful"
 
 clean:
-	rm -f $(HTMLS) $(IMAGES)
+	rm -f $(HTMLS) $(IMAGES) documents.js
 
 .PHONY: all prereq validate clean

diff --git a/devbook.xsl b/devbook.xsl
index 96a0508..71dde54 100644
--- a/devbook.xsl
+++ b/devbook.xsl
@@ -536,7 +536,45 @@
             </div>
           </div>
         </nav>
+        <nav class="navbar navbar-grey navbar-stick" id="devmanual-actions" role="navigation">
+          <div class="container">
+            <div class="row">
+              <div class="navbar-header">
+                <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#gw-toolbar">
+                  <span class="sr-only">Toggle navigation</span>
+                  <span class="icon-bar"></span>
+                  <span class="icon-bar"></span>
+                  <span class="icon-bar"></span>
+                </button>
+              </div>
+              <div class="collapse navbar-collapse" id="gw-toolbar">
+              <div class="input-group">
+                <input type="search" name="search" placeholder="Search" title="Search Gentoo Developer Manual [f]" accesskey="f" id="searchInput" class="form-control"/>
+                <div class="input-group-btn">
+                  <input type="submit" name="fulltext" value="Search" title="Search the pages for this text" id="mw-searchButton" class="searchButton btn btn-default" onclick="search()"/>
+                </div>
+              </div>
+            </div>
+          </div>
+        </div>
+      </nav>
       </header>
+      <div id="searchResults" class="modal fade" role="dialog">
+        <div class="modal-dialog">
+          <div class="modal-content">
+            <div class="modal-header">
+              <button type="button" class="close" data-dismiss="modal">x</button>
+              <h4 class="modal-title">Search Results</h4>
+            </div>
+            <div class="modal-body">
+              <p>No results found.</p>
+            </div>
+            <div class="modal-footer">
+              <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
+            </div>
+          </div>
+        </div>
+      </div>
       <div class="container">
         <div class="row">
           <div class="col-md010">
@@ -583,6 +621,16 @@
       </footer>
       <script src="https://assets.gentoo.org/tyrian/jquery.min.js"></script>
       <script src="https://assets.gentoo.org/tyrian/bootstrap.min.js"></script>
+      <script src="https://unpkg.com/lunr/lunr.js"></script>
+      <xsl:variable name="relative_path_depth" select="string-length(/guide/@self)-string-length(translate(/guide/@self, '/' , ''))"/>
+      <xsl:variable name="relative_path_depth_recursion">
+          <xsl:call-template name="str:repeatString">
+            <xsl:with-param name="count" select="$relative_path_depth"/>
+            <xsl:with-param name="append">../</xsl:with-param>
+          </xsl:call-template>
+      </xsl:variable>
+      <script src="{$relative_path_depth_recursion}documents.js"></script>
+      <script src="{$relative_path_depth_recursion}search.js"></script>
     </body>
     </html>
   </xsl:template>

diff --git a/search.js b/search.js
new file mode 100644
index 0000000..0b9292f
--- /dev/null
+++ b/search.js
@@ -0,0 +1,60 @@
+/*
+ * Copyright 2019 Gentoo Authors
+ * Distributed under the terms of the GNU GPL version 2 or later
+ */
+"use strict";
+
+var search_index = lunr(function () {
+  this.ref('name');
+  this.field('text');
+  this.field('url');
+
+  documents.forEach(function (doc) {
+    this.add(doc);
+  }, this);
+});
+
+var search_input = document.getElementById("searchInput");
+
+search_input.addEventListener("keyup", function(event) {
+  if(event.keyCode === 13) {
+    event.preventDefault();
+    document.getElementById("mw-searchButton").click();
+  }
+});
+
+function getContents(docs, article) {
+  var contents = { text: "", url: "" };
+
+  for (var i = 0; i< docs.length; i++) {
+    if (docs[i].name == article) {
+      contents.text = docs[i].text;
+      contents.url = docs[i].url;
+    }
+  }
+  return contents;
+}
+
+function search() {
+  var term = document.getElementById("searchInput").value;
+  if (term !== "") {
+    var results = search_index.search(term);
+    if (results.length > 0) {
+      $("#searchResults .modal-body").empty();
+      $.each(results, function(index, result) {
+        var title = result.ref;
+        var contents = getContents(documents, title);
+
+        $("#searchResults .modal-body").append(`<article><h5><a href="${contents.url}">
+                                                ${title}</a></h5><p>${contents.text}</p></article>`);
+      });
+    } else {
+      $("#searchResults .modal-body").empty();
+      $("#searchResults .modal-body").append("<p>No results found.</p>");
+    }
+  } else {
+      $("#searchResults .modal-body").empty();
+      $("#searchResults .modal-body").append("<p>No search term defined.</p>");
+  }
+  $("#searchResults").modal();
+}

diff --git a/search_index.py b/search_index.py
new file mode 100755
index 0000000..2ab79f1
--- /dev/null
+++ b/search_index.py
@@ -0,0 +1,26 @@
+#!/usr/bin/python
+# Copyright 2019 Gentoo Authors
+# Distributed under the terms of the GNU GPL version 2 or later
+import json
+import os
+import sys
+import xml.etree.ElementTree as ET
+
+xmlFile = sys.argv[1]
+documents = []
+
+for path, dirs, files in os.walk('.'):
+    if xmlFile in files:
+        tree = ET.parse(path + '/' + xmlFile)
+        root = tree.getroot()
+        for chapter in root.findall('chapter'):
+            try:
+                documents.append({"name": chapter.find('title').text,
+                    "text": chapter.find('body').find('p').text,
+                    "url": path })
+            except:
+                pass
+    if '.git' in dirs:
+        dirs.remove('.git')  # don't visit git directories
+
+print(json.dumps(documents))


             reply	other threads:[~2019-12-19 21:02 UTC|newest]

Thread overview: 213+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-12-19 21:02 Göktürk Yüksek [this message]
  -- strict thread matches above, loose matches on Subject: below --
2024-11-12 18:51 [gentoo-commits] proj/devmanual:master commit in: / Ulrich Müller
2024-11-09  6:58 Ulrich Müller
2024-11-06 20:00 Ulrich Müller
2024-11-05 22:13 Ulrich Müller
2024-11-01 20:01 Ulrich Müller
2024-11-01 17:27 Ulrich Müller
2024-11-01 11:20 Ulrich Müller
2024-11-01 11:20 Ulrich Müller
2024-10-31 18:59 Ulrich Müller
2024-10-31 11:08 Ulrich Müller
2024-10-31 11:08 Ulrich Müller
2024-10-28 16:19 Ulrich Müller
2024-10-27  7:55 Ulrich Müller
2024-07-30 14:30 Ulrich Müller
2024-06-11 16:24 Ulrich Müller
2024-06-10 15:41 Ulrich Müller
2024-05-08  6:43 Ulrich Müller
2024-04-22 18:19 Ulrich Müller
2024-03-23  7:10 Ulrich Müller
2024-01-28 17:40 Ulrich Müller
2023-11-23 17:24 Ulrich Müller
2023-11-05 16:44 Ulrich Müller
2023-11-02 17:08 Ulrich Müller
2023-11-02 17:06 Ulrich Müller
2023-11-02 17:06 Ulrich Müller
2023-10-31 20:03 Ulrich Müller
2023-10-31 20:03 Ulrich Müller
2023-10-31 20:03 Ulrich Müller
2023-10-31 20:03 Ulrich Müller
2023-10-31 20:03 Ulrich Müller
2023-10-22 11:44 Ulrich Müller
2023-10-22 11:44 Ulrich Müller
2023-10-05 20:43 Ulrich Müller
2022-06-24 10:51 Ulrich Müller
2022-06-22 14:35 Ulrich Müller
2022-06-17  8:00 Ulrich Müller
2022-06-10 17:20 Ulrich Müller
2022-01-24 18:16 Ulrich Müller
2022-01-19 11:30 Ulrich Müller
2022-01-16 21:52 Ulrich Müller
2021-10-11 10:53 Ulrich Müller
2021-10-10 10:34 Ulrich Müller
2021-10-10 10:34 Ulrich Müller
2021-09-08 17:52 Ulrich Müller
2021-09-08 17:52 Ulrich Müller
2021-07-14 12:27 Ulrich Müller
2021-03-10 19:51 Ulrich Müller
2021-03-10 19:51 Ulrich Müller
2021-03-10 19:51 Ulrich Müller
2021-03-10 19:51 Ulrich Müller
2021-03-10 19:51 Ulrich Müller
2021-03-10 18:39 Ulrich Müller
2021-03-07 17:40 Ulrich Müller
2021-03-03 19:08 Ulrich Müller
2021-02-27 15:47 Ulrich Müller
2021-02-25 23:49 Ulrich Müller
2021-02-25 19:30 Ulrich Müller
2021-02-25 19:30 Ulrich Müller
2021-02-24 19:36 Ulrich Müller
2021-02-06 10:39 Ulrich Müller
2021-01-25 10:34 Ulrich Müller
2021-01-18 12:17 Ulrich Müller
2021-01-17 22:09 Ulrich Müller
2020-08-28 17:46 Ulrich Müller
2020-03-06 16:30 Ulrich Müller
2020-03-03  8:30 Ulrich Müller
2020-03-03  8:18 Ulrich Müller
2020-03-02 10:23 Ulrich Müller
2020-03-02 10:23 Ulrich Müller
2020-02-28  7:20 Ulrich Müller
2020-02-28  7:20 Ulrich Müller
2020-02-28  7:17 Ulrich Müller
2020-02-28  7:15 Ulrich Müller
2020-02-28  7:15 Ulrich Müller
2020-02-28  7:15 Ulrich Müller
2020-02-26 20:41 Ulrich Müller
2020-02-26 20:41 Ulrich Müller
2020-02-26 18:59 Ulrich Müller
2020-02-26 18:53 Ulrich Müller
2020-02-26 18:53 Ulrich Müller
2020-02-26 18:53 Ulrich Müller
2020-02-16 13:16 Ulrich Müller
2020-02-11 11:30 Ulrich Müller
2020-02-10 17:31 Ulrich Müller
2020-02-07 14:01 Ulrich Müller
2020-02-07  5:34 Ulrich Müller
2020-02-06 20:53 Ulrich Müller
2020-02-03 10:06 Ulrich Müller
2020-02-03  0:07 Ulrich Müller
2020-02-03  0:07 Ulrich Müller
2020-02-03  0:07 Ulrich Müller
2020-01-30 13:45 Brian Evans
2020-01-27 20:44 Ulrich Müller
2020-01-27 19:58 Ulrich Müller
2020-01-27 19:58 Ulrich Müller
2020-01-22 18:24 Ulrich Müller
2020-01-21 21:53 Ulrich Müller
2020-01-16 18:53 Ulrich Müller
2020-01-15  7:06 Ulrich Müller
2020-01-14  8:15 Ulrich Müller
2020-01-12  9:23 Ulrich Müller
2020-01-09  7:34 Ulrich Müller
2020-01-09  7:34 Ulrich Müller
2020-01-02 13:38 Ulrich Müller
2020-01-02 12:54 Ulrich Müller
2020-01-02 12:54 Ulrich Müller
2020-01-02 12:54 Ulrich Müller
2019-12-26 21:36 Ulrich Müller
2019-12-26 20:33 Ulrich Müller
2019-12-26 17:06 Ulrich Müller
2019-12-26 16:47 Ulrich Müller
2019-12-21  5:19 Ulrich Müller
2019-12-19 21:02 Göktürk Yüksek
2019-12-19 21:02 Göktürk Yüksek
2019-12-19 21:02 Göktürk Yüksek
2019-12-19 21:02 Göktürk Yüksek
2019-12-19 21:02 Göktürk Yüksek
2019-12-19 21:02 Göktürk Yüksek
2019-12-19 21:02 Göktürk Yüksek
2019-12-19 21:02 Göktürk Yüksek
2019-12-19 21:02 Göktürk Yüksek
2019-12-14 10:46 Ulrich Müller
2019-12-10  8:47 Ulrich Müller
2019-12-10  8:47 Ulrich Müller
2019-12-07 22:05 Ulrich Müller
2019-11-26  3:05 Göktürk Yüksek
2019-03-22 18:51 Brian Evans
2019-03-22 18:51 Brian Evans
2019-03-19 19:02 Brian Evans
2019-03-19 17:11 Brian Evans
2018-01-03  5:57 [gentoo-commits] proj/devmanual:codesample-indent-fix " Göktürk Yüksek
2018-01-03 21:59 ` [gentoo-commits] proj/devmanual:master " Göktürk Yüksek
2017-02-05 22:41 Ulrich Müller
2016-10-31  1:21 Göktürk Yüksek
2016-10-28 17:15 Ulrich Müller
2016-10-06 22:09 Mike Gilbert
2016-06-15 18:46 Ulrich Müller
2016-05-15 11:48 Ulrich Müller
2016-05-15 11:48 Ulrich Müller
2016-04-02  8:54 Ulrich Müller
2016-02-05  8:41 Ulrich Müller
2016-01-01 21:59 NP Hardass
2015-09-05 15:48 Markos Chandras
2015-08-27  6:50 Justin Lecher
2015-08-21  6:36 Justin Lecher
2015-08-21  6:36 Justin Lecher
2015-08-20  7:06 Justin Lecher
2015-08-20  7:04 Justin Lecher
2015-08-18 11:47 Justin Lecher
2015-08-09 12:39 Justin Lecher
2015-08-09 12:39 Justin Lecher
2015-08-09  9:30 Justin Lecher
2015-08-09  9:30 Justin Lecher
2015-07-22  1:15 Jorge Manuel B. S. Vicetto
2015-06-17 12:05 Ulrich Müller
2015-06-01 18:41 Ulrich Müller
2015-06-01 15:38 Ulrich Müller
2015-05-31 10:45 Markus Meier
2015-05-31 10:45 Markus Meier
2015-03-30 18:21 Markos Chandras
2015-03-11 18:26 Markos Chandras
2015-02-15  9:54 Markos Chandras
2015-01-17  9:07 Markos Chandras
2014-11-14 18:07 Markos Chandras
2014-11-14 18:07 Markos Chandras
2014-11-14 18:07 Markos Chandras
2014-11-08 12:27 Markos Chandras
2014-11-08 12:27 Markos Chandras
2014-11-08 12:27 Markos Chandras
2014-11-08 12:27 Markos Chandras
2014-11-08 12:27 Markos Chandras
2014-11-08 12:27 Markos Chandras
2014-11-08 12:27 Markos Chandras
2014-11-08 12:27 Markos Chandras
2014-11-08 12:27 Markos Chandras
2014-11-08 12:27 Markos Chandras
2014-11-08 12:27 Markos Chandras
2014-11-08 12:27 Markos Chandras
2014-11-08 12:27 Markos Chandras
2014-11-08 12:27 Markos Chandras
2014-11-08 12:27 Markos Chandras
2014-11-08 12:27 Markos Chandras
2014-10-18 17:36 Markos Chandras
2014-10-18 17:36 Markos Chandras
2014-10-18 17:36 Markos Chandras
2014-10-18 17:35 Markos Chandras
2014-07-24 18:06 ` Markos Chandras
2014-10-18 17:35 Markos Chandras
2014-07-24 18:06 ` Markos Chandras
2014-10-18 17:35 Markos Chandras
2014-07-24 18:06 ` Markos Chandras
2014-07-24 18:06 Markos Chandras
2014-10-18 17:35 ` Markos Chandras
2014-03-16 10:24 Markos Chandras
2014-03-16 10:24 Markos Chandras
2014-03-16 10:24 Markos Chandras
2014-03-08 14:53 Markos Chandras
2014-01-05 12:35 Markos Chandras
2014-01-04 11:23 Markos Chandras
2014-01-03 18:32 Markos Chandras
2013-09-26  7:41 Markos Chandras
2013-09-21 12:23 Markos Chandras
2013-09-21 12:23 Markos Chandras
2013-07-25  8:28 Justin Lecher
2013-05-19  8:38 Markos Chandras
2013-05-15 12:57 Dirkjan Ochtman
2013-05-12 19:25 Markos Chandras
2013-05-12 15:06 Markos Chandras
2013-05-11 19:02 Markos Chandras
2012-10-12 17:44 Ulrich Mueller
2012-08-08 19:23 Markos Chandras
2012-03-18  0:16 Markos Chandras
2011-12-20 12:39 Torsten Veller

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1576788769.7f13e9b5f59ee496db5b8af7ab093a17c8f76066.gokturk@gentoo \
    --to=gokturk@gentoo.org \
    --cc=gentoo-commits@lists.gentoo.org \
    --cc=gentoo-dev@lists.gentoo.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox