Added support for Google Custom Search Engine

This commit is contained in:
Li-Wen Yip 2017-03-25 16:17:01 +00:00
parent 43ad9b7755
commit 0465584c2b
4 changed files with 54 additions and 0 deletions

View File

@ -16,6 +16,7 @@ pygmentCodeFences = true
commit = false
rss = true
comments = true
# gcse = "012345678901234567890:abcdefghijk" # Get your code from google.com/cse. Make sure to go to "Look and Feel" and change Layout to "Full Width" and Theme to "Classic"
#[[Params.bigimg]]
# src = "img/triangle.jpg"

View File

@ -205,5 +205,17 @@
<script src="{{ .Site.BaseURL }}/js/highlight.min.js"></script>
<script> hljs.initHighlightingOnLoad(); </script>
<script> renderMathInElement(document.body); </script>
<!-- Google Custom Search Engine -->
<script>
(function() {
var cx = '{{ .Site.Params.gcse }}';
var gcse = document.createElement('script');
gcse.type = 'text/javascript';
gcse.async = true;
gcse.src = 'https://cse.google.com/cse.js?cx=' + cx;
var s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(gcse, s);
})();
</script>
{{ template "_internal/google_analytics.html" . }}

View File

@ -28,6 +28,13 @@
</li>
{{ end }}
{{ end }}
{{ if isset .Site.Params "gcse" }}
<li>
<a href="#modalSearch" data-toggle="modal" data-target="#modalSearch" style="outline: none;">
<span class="hidden-sm hidden-md hidden-lg">Search</span> <span id="searchGlyph" class="glyphicon glyphicon-search"></span>
</a>
</li>
{{ end }}
</ul>
</div>
@ -43,3 +50,23 @@
</div>
</nav>
<!-- Search Modal -->
{{ if isset .Site.Params "gcse" }}
<div id="modalSearch" class="modal fade" role="dialog">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">&times;</button>
<h4 class="modal-title">Search {{ .Site.Title }}</h4>
</div>
<div class="modal-body">
<gcse:search></gcse:search>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
{{ end }}

View File

@ -681,3 +681,17 @@ td.gutter {
#social-share-section {
margin-bottom: 30px;
}
/* --- Google Custom Search Engine Popup --- */
#modalSearch table tr, #modalSearch table tr td, #modalSearch table tr th {
border:none;
}
.reset-box-sizing, .reset-box-sizing *, .reset-box-sizing *:before, .reset-box-sizing *:after, .gsc-inline-block {
-webkit-box-sizing: content-box;
-moz-box-sizing: content-box;
box-sizing: content-box;
}
input.gsc-input, .gsc-input-box, .gsc-input-box-hover, .gsc-input-box-focus, .gsc-search-button {
box-sizing: content-box;
line-height: normal;
}