This repository has been archived on 2023-03-26. You can view files and clone it, but cannot push or open issues or pull requests.
md-pdf/md_pdf/build/context.py

29 lines
633 B
Python
Raw Normal View History

from md_pdf.consts import TEMPLATES_DIR, STATIC_DIR
2017-05-25 17:42:36 +01:00
from word_count import word_count
from md_pdf.utils import get_plain_text
2017-05-25 20:36:23 +01:00
from datetime import datetime
EXTRA_CONTEXT = {
'templates_dir': TEMPLATES_DIR,
2017-05-25 20:36:23 +01:00
'static_dir': STATIC_DIR,
'date': datetime.now()
}
def get_context(config, content):
2017-05-25 20:39:24 +01:00
config = config.copy()
context = config['context'].copy()
2017-05-25 20:39:24 +01:00
del config['context']
context = dict(
config,
**context,
**EXTRA_CONTEXT,
**{
}
)
if config.get('show_word_count'):
context['word_count'] = word_count(get_plain_text(content))
return context