Merge "Documentation/replace_macros: support --site-search option"
diff --git a/Documentation/replace_macros.py b/Documentation/replace_macros.py
index 309a135..7d8ea23 100755
--- a/Documentation/replace_macros.py
+++ b/Documentation/replace_macros.py
@@ -87,6 +87,12 @@
id="searchBox">
Search
</button>
+ %s
+</div>
+++++
+"""
+
+BUILTIN_SEARCH = """
<script type="text/javascript">
var f = function() {
window.location = '../#/Documentation/q/' +
@@ -99,11 +105,25 @@
}
}
</script>
-</div>
-++++
-
"""
+GOOGLE_SITE_SEARCH = """
+<script type="text/javascript">
+var f = function() {
+ window.location = 'https://www.google.com/search?q=' +
+ encodeURIComponent(document.getElementById("docSearch").value +
+ ' site:@SITE@');
+}
+document.getElementById("searchBox").onclick = f;
+document.getElementById("docSearch").onkeypress = function(e) {
+ if (13 == (e.keyCode ? e.keyCode : e.which)) {
+ f();
+ }
+}
+</script>
+"""
+
+
LINK_SCRIPT = """
++++
@@ -227,8 +247,19 @@
help="generate the search boxes")
opts.add_option('--no-searchbox', action="store_false", dest='searchbox',
help="don't generate the search boxes")
+opts.add_option('--site-search', action="store", metavar="SITE",
+ help=("generate the search box using google. SITE should " +
+ "point to the domain/path of the site, eg. " +
+ "gerrit-review.googlesource.com/Documentation"))
options, _ = opts.parse_args()
+if options.site_search:
+ SEARCH_BOX = (SEARCH_BOX %
+ GOOGLE_SITE_SEARCH.replace("@SITE@", options.site_search))
+else:
+ SEARCH_BOX = SEARCH_BOX % BUILTIN_SEARCH
+
+
try:
try:
out_file = open(options.out, 'w', errors='ignore')