Documentation/replace_macros: support --site-search option
This makes the search box link to google.com/search with a "site:XYZ" restrict. I have also investigated Google Custom Search Engine, but the UI feels antiquated, and the search results overlaid properly beyond my CSS/HTML skills. Tested: A: 1. Add this option to _replace_macros_impl in tools/bzl/asciidoc.bzl 2. bazel build Documentation/cmd-index-activate.html 3. chrome $PWD/bazel-bin/Documentation/cmd-index-activate.html 4. Verify that the search box links to google.com B: 5. Revert asciidoc.bzl, bazel build release. 6. Verify that internal search works. Change-Id: Ia319803d6a9bfa20ea39c035891208bd5a55a162
This commit is contained in:
parent
168e9fe0e2
commit
0096cc3c55
@ -87,6 +87,12 @@ SEARCH_BOX = """
|
||||
id="searchBox">
|
||||
Search
|
||||
</button>
|
||||
%s
|
||||
</div>
|
||||
++++
|
||||
"""
|
||||
|
||||
BUILTIN_SEARCH = """
|
||||
<script type="text/javascript">
|
||||
var f = function() {
|
||||
window.location = '../#/Documentation/q/' +
|
||||
@ -99,11 +105,25 @@ document.getElementById("docSearch").onkeypress = function(e) {
|
||||
}
|
||||
}
|
||||
</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 @@ opts.add_option('-b', '--searchbox', action="store_true", default=True,
|
||||
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')
|
||||
|
Loading…
Reference in New Issue
Block a user