Skip to content

Commit ce07d6b

Browse files
committedDec 24, 2015
system-wide shortcode support
1 parent 7a97475 commit ce07d6b

File tree

1 file changed

+18
-13
lines changed

1 file changed

+18
-13
lines changed
 

‎nikola/nikola.py

+18-13
Original file line numberDiff line numberDiff line change
@@ -1294,19 +1294,24 @@ def url_replacer(self, src, dst, lang=None, url_type=None):
12941294
return result
12951295

12961296
def _register_templated_shortcodes(self):
1297-
"""Register shortcodes provided by templates in shortcodes/ folder."""
1298-
if not os.path.isdir('shortcodes'):
1299-
return
1300-
for fname in os.listdir('shortcodes'):
1301-
name, ext = os.path.splitext(fname)
1302-
if ext == '.tmpl':
1303-
with open(os.path.join('shortcodes', fname)) as fd:
1304-
template_data = fd.read()
1305-
1306-
def render_shortcode(t_data=template_data, **kw):
1307-
return self.template_system.render_template_to_string(t_data, kw)
1308-
1309-
self.register_shortcode(name, render_shortcode)
1297+
"""Register shortcodes provided by templates in shortcodes/ folders."""
1298+
1299+
builtin_sc_dir = resource_filename('nikola', os.path.join('data', 'shortcodes', utils.get_template_engine(self.THEMES)))
1300+
sc_dirs = [builtin_sc_dir]
1301+
if os.path.isdir('shortcodes'):
1302+
sc_dirs.append('shortcodes')
1303+
1304+
for sc_dir in sc_dirs:
1305+
for fname in os.listdir(sc_dir):
1306+
name, ext = os.path.splitext(fname)
1307+
if ext == '.tmpl':
1308+
with open(os.path.join(sc_dir, fname)) as fd:
1309+
template_data = fd.read()
1310+
1311+
def render_shortcode(t_data=template_data, **kw):
1312+
return self.template_system.render_template_to_string(t_data, kw)
1313+
1314+
self.register_shortcode(name, render_shortcode)
13101315

13111316
def register_shortcode(self, name, f):
13121317
"""Register function f to handle shortcode "name"."""

0 commit comments

Comments
 (0)
Please sign in to comment.