-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlektor_google_search.py
More file actions
25 lines (19 loc) · 892 Bytes
/
lektor_google_search.py
File metadata and controls
25 lines (19 loc) · 892 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# -*- coding: utf-8 -*-
from lektor.pluginsystem import Plugin
from markupsafe import Markup
SCRIPT ='''
<script async src="https://cse.google.com/cse.js?cx=%(SEARCH_ENGINE_ID)s"></script>
<div class="gcse-search"></div>
'''
class GoogleSearchPlugin(Plugin):
name = 'Google Search'
description = u'Lektor plugin to add google seach to a website'
def on_setup_env(self, **extra):
search_engine_id = self.get_config().get('SEARCH_ENGINE_ID')
if search_engine_id is None:
raise RuntimeError('SEARCH_ENGINE_ID is not configured.'
'Please configure it in '
'`./configs/google-search.ini` file')
def render_google_search():
return Markup(SCRIPT % {'SEARCH_ENGINE_ID':search_engine_id})
self.env.jinja_env.globals['render_google_search'] = render_google_search