Skip to content

Commit

Permalink
Convert undefined values to None (null in json).
Browse files Browse the repository at this point in the history
  • Loading branch information
rlaverde committed Mar 10, 2017
1 parent f22afc2 commit 196da72
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lektor_static_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import os
import json
from collections import defaultdict
from jinja2 import Undefined

from lektor.reporter import reporter
from lektor.pluginsystem import Plugin
Expand Down Expand Up @@ -65,7 +66,9 @@ def on_before_build(self, source, prog, **extra):
if source.datamodel.id in self.models:
model = self.models[source.datamodel.id]

item = {key: source[field] for key, field in model.items()}
item = {key: None if isinstance(source[field], Undefined) else
source[field]
for key, field in model.items()}
item['url'] = source.url_path

self.static_search[source.alt].append(item)
Expand Down

0 comments on commit 196da72

Please sign in to comment.