[Conkeror] [PATCH] New module to define webjumps for git repository summaries.
David Kettler
kettler at internode.on.net
Fri Feb 6 20:49:37 PST 2009
There's a convenient way to choose an alternative url as either a
particular repository or as the repository list.
A completer is available which fetches the list of repositories from
gitweb. This should only be used on local sites; it's slow and not
nice to the server to use on a large external site.
Acknowledgement: The completer is glommed together from
all_word_completer and the search_engine completer.
Examples:
require("gitweb-webjump.js");
define_gitweb_summary_webjump("gitweb-ko", "http://git.kernel.org");
define_gitweb_summary_webjump("gitweb-cz", "http://repo.or.cz/w");
You can now use the following webjumps:
gitweb-cz conkeror
gitweb-ko git/git
---
The intention with the completer is that it gets the list from the
server once only. However currently, if you press more keys before it
has the list, it will redo the request. That's slower and is
unfriendly to the server. It's okay for a fast, local server.
Here's a patch that forces the get to happen only once. However in
this case when more keys are pressed the get is never completed, so
completions aren't available. I don't know how to fix this.
--8<--
| diff --git a/modules/gitweb-webjump.js b/modules/gitweb-webjump.js
| index 3067a79..37daef2 100644
| --- a/modules/gitweb-webjump.js
| +++ b/modules/gitweb-webjump.js
| @@ -16,13 +16,14 @@ require("webjump.js");
| */
| function gitweb_webjump_completer(opml_url) {
| const response_type_xml = "application/x-suggestions+xml";
| - let completions = [];
| + let completions = null;
| return function (input, pos, conservative) {
| if (pos == 0 && conservative)
| yield co_return(undefined);
| let str = input.substring(0,pos);
| try {
| - if (completions.length == 0) {
| + if (completions == null) {
| + completions = []; // only fetch once
| let lspec = load_spec(opml_url, response_type_xml);
| let doc = (yield send_http_request(lspec)).responseXML;
| if (!doc)
-->8--
Note that even with this fixed, I don't think you want the completer
for either of the example sites; it takes a long time to get the OPML
data.
---
modules/gitweb-webjump.js | 91 +++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 91 insertions(+), 0 deletions(-)
create mode 100644 modules/gitweb-webjump.js
diff --git a/modules/gitweb-webjump.js b/modules/gitweb-webjump.js
new file mode 100644
index 0000000..0b72cc5
--- /dev/null
+++ b/modules/gitweb-webjump.js
@@ -0,0 +1,91 @@
+/**
+ * (C) Copyright 2009 David Kettler
+ *
+ * Use, modification, and distribution are subject to the terms specified in the
+ * COPYING file.
+ *
+ * Construct a webjump (with optional completer) to visit repository
+ * summary pages at a gitweb server.
+**/
+
+require("webjump.js");
+
+/**
+ * A completer that gets the list of repositories from the gitweb
+ * generated OPML.
+ */
+function gitweb_webjump_completer(opml_url) {
+ const response_type_xml = "application/x-suggestions+xml";
+ let completions = [];
+ return function (input, pos, conservative) {
+ if (pos == 0 && conservative)
+ yield co_return(undefined);
+ let str = input.substring(0,pos);
+ try {
+ if (completions.length == 0) {
+ let lspec = load_spec(opml_url, response_type_xml);
+ let doc = (yield send_http_request(lspec)).responseXML;
+ if (!doc)
+ yield co_return(null);
+ let elems = doc.getElementsByTagName("outline");
+ for (let i = 0; i < elems.length; ++i) {
+ let node = elems[i];
+ let type = node.getAttribute("type");
+ let name = node.getAttribute("text");
+ if (type == "rss" && name)
+ completions.push(name.replace(/\.git$/, ""));
+ }
+ completions.sort();
+ }
+ let words = trim_whitespace(input.toLowerCase()).split(/\s+/);
+ let data = completions.filter(function (x) {
+ for (var i = 0; i < words.length; ++i)
+ if (x.toLowerCase().indexOf(words[i]) == -1)
+ return false;
+ return true;
+ });
+ let c = {count: data.length,
+ get_string: function (i) data[i],
+ get_description: function (i) data[i],
+ get_input_state: function (i) [data[i]]};
+ yield co_return(c);
+ } catch (e) {
+ yield co_return(null);
+ }
+ };
+}
+
+/**
+ * Construct a webjump to visit repository summary pages at a gitweb
+ * server.
+ *
+ * If a repository name is supplied as $default then the alternative
+ * url is set to that repository at the gitweb site. If an
+ * alternative is not specified by either $default or $alternative
+ * then it is set to the repository list page of the gitweb site.
+ *
+ * If the $completer keyword is true, a completer is provided that
+ * fetches the list of repositories from gitweb. This should only be
+ * used on local sites; it's slow and not nice to the server to use on
+ * a large external site.
+ */
+define_keywords("$default", "$alternative", "$completer");
+function define_gitweb_summary_webjump(key, base_url) {
+ keywords(arguments);
+ let completer = arguments.$completer;
+ let alternative = arguments.$alternative;
+ let gitweb_url = base_url + "/gitweb.cgi";
+ let search_url = gitweb_url + "?p=%s.git;a=summary";
+ let opml_url = gitweb_url + "?a=opml";
+
+ if (completer == true)
+ completer = gitweb_webjump_completer(opml_url);
+ if (arguments.$default)
+ alternative = search_url.replace("%s", arguments.$default);
+ if (!alternative)
+ alternative = gitweb_url;
+
+ define_webjump(key, search_url,
+ $completer = completer,
+ $alternative = alternative);
+}
--
1.5.6.5
More information about the Conkeror
mailing list