Skip to content

Commit 8535421

Browse files
committed
ENH: Add Google Custom Search widget
Fixes #56
1 parent 155f4ac commit 8535421

File tree

3 files changed

+23
-0
lines changed

3 files changed

+23
-0
lines changed

doc/pdoc_template/config.mako

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,9 @@
22
33
git_link_template = 'https://github.com/pdoc3/pdoc/blob/{commit}/{path}#L{start_line}-L{end_line}'
44
5+
search_query = '''
6+
site:pdoc3.github.io
7+
inurl:github.com/pdoc3
8+
'''
9+
510
%>

pdoc/templates/config.mako

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,12 @@
4242
# tracking id (UA-XXXXXX-Y).
4343
google_analytics = ''
4444
45+
# If set, insert Google Custom Search search bar widget above the sidebar index.
46+
# The whitespace-separated tokens represent arbitrary extra queries (at least one
47+
# must match) passed to regular Google search. Example:
48+
#search_query = 'inurl:github.com/USER/PROJECT site:PROJECT.github.io site:PROJECT.website'
49+
search_query = ''
50+
4551
# If set, render LaTeX math syntax within \(...\) (inline equations),
4652
# or within \[...\] or $$...$$ or `.. math::` (block equations)
4753
# as nicely-formatted math formulas using MathJax.

pdoc/templates/html.mako

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,13 @@
285285
286286
<%include file="logo.mako"/>
287287
288+
% if search_query:
289+
<div class="gcse-search" style="height: 70px"
290+
data-as_oq="${' '.join(search_query.strip().split()) | h }"
291+
data-gaCategoryParameter="${module.refname | h}">
292+
</div>
293+
% endif
294+
288295
<h1>Index</h1>
289296
${extract_toc(module.docstring) if extract_module_toc_into_sidebar else ''}
290297
<ul id="index">
@@ -384,6 +391,11 @@
384391
</script><script async src='https://www.google-analytics.com/analytics.js'></script>
385392
% endif
386393

394+
% if search_query:
395+
<script async src="https://cse.google.com/cse.js?cx=017837193012385208679:pey8ky8gdqw"></script>
396+
<style>.gsc-control-cse {padding:0 !important;margin-top:1em}</style>
397+
% endif
398+
387399
% if latex_math:
388400
<script async src='https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/latest.js?config=TeX-AMS_CHTML'></script>
389401
% endif

0 commit comments

Comments
 (0)