[gi-docgen/index-content-files: 2/2] template: Search through the content files
- From: Emmanuele Bassi <ebassi src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gi-docgen/index-content-files: 2/2] template: Search through the content files
- Date: Sat, 14 Aug 2021 16:06:13 +0000 (UTC)
commit 59ecae68907f44b6de495eb0a2b1ec492ef37344
Author: Emmanuele Bassi <ebassi gnome org>
Date: Sat Aug 14 16:58:41 2021 +0100
template: Search through the content files
Now that the index has a "content" type for the documents, we need to
handle it properly.
Since we show the title of the content files in the results, we need to
move the "<code>…</code>" elements from the result generator to a
separate function, so that we don't show document titles in the same way
as identifiers and symbols.
gidocgen/templates/basic/search.js | 51 ++++++++++++++++++++++++++++++++++++--
1 file changed, 49 insertions(+), 2 deletions(-)
---
diff --git a/gidocgen/templates/basic/search.js b/gidocgen/templates/basic/search.js
index 4a0f768..b8642c9 100644
--- a/gidocgen/templates/basic/search.js
+++ b/gidocgen/templates/basic/search.js
@@ -10,6 +10,7 @@ const QUERY_TYPES = [
"callback",
"class",
"constant",
+ "content",
"ctor",
"domain",
"enum",
@@ -97,7 +98,7 @@ function searchQuery(query) {
return {
name: doc.name,
type: doc.type,
- text: getTextForDocument(doc, searchIndex.meta),
+ text: getLabelForDocument(doc, searchIndex.meta),
href: getLinkForDocument(doc),
summary: doc.summary,
};
@@ -138,7 +139,7 @@ function renderResults(query, results) {
results.forEach(function(item) {
html += "<tr>" +
"<td class=\"result " + item.type + "\">" +
- "<a href=\"" + item.href + "\"><code>" + item.text + "</code></a>" +
+ "<a href=\"" + item.href + "\">" + item.text + "</a>" +
"</td>" +
"<td>" + item.summary + "</td>" +
"</tr>";
@@ -184,6 +185,7 @@ function getLinkForDocument(doc) {
case "class": return "class." + doc.name + ".html";
case "class_method": return "class_method." + doc.struct_for + "." + doc.name + ".html";
case "constant": return "const." + doc.name + ".html";
+ case "content": return doc.href;
case "ctor": return "ctor." + doc.type_name + "." + doc.name + ".html";
case "domain": return "error." + doc.name + ".html";
case "enum": return "enum." + doc.name + ".html";
@@ -201,6 +203,48 @@ function getLinkForDocument(doc) {
return null;
}
+function getLabelForDocument(doc, meta) {
+ switch (doc.type) {
+ case "alias":
+ case "bitfield":
+ case "class":
+ case "domain":
+ case "enum":
+ case "interface":
+ case "record":
+ case "union":
+ return "<code>" + doc.ctype + "</code>";
+ case "class_method":
+ case "constant":
+ case "ctor":
+ case "function":
+ case "function_macro":
+ case "method":
+ case "type_func":
+ return "<code>" + doc.ident + "</code>";
+
+ // NOTE: meta.ns added for more consistent results, otherwise
+ // searching for "Button" would return all signals, properties
+ // and vfuncs (eg "Button.clicked") before the actual object
+ // (eg "GtkButton") because "Button" matches higher with starting
+ // sequences.
+ case "property":
+ return "<code>" + meta.ns + doc.type_name + ":" + doc.name + "</code>";
+ case "signal":
+ return "<code>" + meta.ns + doc.type_name + "::" + doc.name + "</code>";
+ case "vfunc":
+ return "<code>" + meta.ns + doc.type_name + "." + doc.name + "</code>";
+
+ case "callback":
+ return "<code>" + doc.name + "</code>";
+
+ case "content":
+ return doc.name;
+ }
+
+ return null;
+}
+
function getTextForDocument(doc, meta) {
switch (doc.type) {
case "alias":
@@ -235,6 +279,9 @@ function getTextForDocument(doc, meta) {
case "callback":
return doc.name;
+
+ case "content":
+ return doc.name;
}
return null;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]