Skip to content

Commit

Permalink
Load configurations.
Browse files Browse the repository at this point in the history
  • Loading branch information
rlaverde committed Mar 10, 2017
1 parent 09943e5 commit f544243
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions lektor_tipue_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,11 @@ def on_server_spawn(self, **extra):
self.enabled = bool(extra_flags.get('tipue'))

def on_setup_env(self, **extra):
#TODO load configurations
pass
self.models = defaultdict(dict)

for key, item in self.get_config().items():
model, field = key.split('.')
self.models[model][field] = item

@check_enabled
def on_before_build_all(self, builder, **extra):
Expand All @@ -46,13 +49,14 @@ def on_before_build_all(self, builder, **extra):
@check_enabled
def on_before_build(self, source, prog, **extra):
if isinstance(source, Page):
#FIXME at the moment only support blog-post
if source.datamodel.id == 'blog-post':
item = {'title': source['title'],
'text': source['summary'],
'tags': source['tags'], }

self.tipue_search[source.alt].append(item)
try:
model = self.models[source.datamodel.id]
except Exception:
return
item = {key: source[field] for key, field in model.items()}

self.tipue_search[source.alt].append(item)

@check_enabled
def on_after_build_all(self, builder, **extra):
Expand Down

0 comments on commit f544243

Please sign in to comment.